Skip to content

Commit bfba7b1

Browse files
authored
Merge pull request #1 from peek-travel/initial-implementation
Initial implementation
2 parents b3d0adf + f7b6296 commit bfba7b1

15 files changed

+3552
-40
lines changed

Package.swift

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
7-
name: "Currency",
7+
name: "swift-currency",
88
products: [
9-
// Products define the executables and libraries produced by a package, and make them visible to other packages.
10-
.library(
11-
name: "Currency",
12-
targets: ["Currency"]),
13-
],
14-
dependencies: [
15-
// Dependencies declare other packages that this package depends on.
16-
// .package(url: /* package url */, from: "1.0.0"),
9+
.library(name: "Currency", targets: ["Currency"]),
1710
],
11+
dependencies: [],
1812
targets: [
19-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
20-
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
21-
.target(
22-
name: "Currency",
23-
dependencies: []),
24-
.testTarget(
25-
name: "CurrencyTests",
26-
dependencies: ["Currency"]),
13+
.target(name: "Currency", dependencies: []),
14+
.testTarget(name: "CurrencyTests", dependencies: ["Currency"]),
2715
]
2816
)

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
# Currency
22

33
A description of this package.
4+
5+
## ISO 4271 Currency List
6+
7+
### Updating the list
8+
9+
> You will need **gyb** installed on your machine.
10+
11+
After updating the [`Resources/ISO4217.csv`](/Resources/ISO4217.csv) with the latest from the [ISO Currency Workgroup](https://www.currency-iso.org/en/home/tables/table-a1.html),
12+
run the following command:
13+
14+
```bash
15+
find . -name '*.gyb' | \
16+
while read file; do \
17+
<path to gyb> --line-directive '' -o "${file%.gyb}" "$file"; \
18+
done
19+
```

Resources/ISO4217.csv

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
CtryNm,CcyNm,Ccy,CcyNbr,CcyMnrUnts,CcyNm/_IsFund,CcyNm/__text
2+
UNITED ARAB EMIRATES (THE),UAE Dirham,AED,784,2,,
3+
AFGHANISTAN,Afghani,AFN,971,2,,
4+
ALBANIA,Lek,ALL,8,2,,
5+
ARMENIA,Armenian Dram,AMD,51,2,,
6+
CURAÇAO,Netherlands Antillean Guilder,ANG,532,2,,
7+
ANGOLA,Kwanza,AOA,973,2,,
8+
ARGENTINA,Argentine Peso,ARS,32,2,,
9+
AUSTRALIA,Australian Dollar,AUD,36,2,,
10+
ARUBA,Aruban Florin,AWG,533,2,,
11+
AZERBAIJAN,Azerbaijan Manat,AZN,944,2,,
12+
BOSNIA AND HERZEGOVINA,Convertible Mark,BAM,977,2,,
13+
BARBADOS,Barbados Dollar,BBD,52,2,,
14+
BANGLADESH,Taka,BDT,50,2,,
15+
BULGARIA,Bulgarian Lev,BGN,975,2,,
16+
BAHRAIN,Bahraini Dinar,BHD,48,3,,
17+
BURUNDI,Burundi Franc,BIF,108,0,,
18+
BERMUDA,Bermudian Dollar,BMD,60,2,,
19+
BRUNEI DARUSSALAM,Brunei Dollar,BND,96,2,,
20+
BOLIVIA (PLURINATIONAL STATE OF),Boliviano,BOB,68,2,,
21+
BRAZIL,Brazilian Real,BRL,986,2,,
22+
BAHAMAS (THE),Bahamian Dollar,BSD,44,2,,
23+
BHUTAN,Ngultrum,BTN,64,2,,
24+
BOTSWANA,Pula,BWP,72,2,,
25+
BELARUS,Belarusian Ruble,BYN,933,2,,
26+
BELIZE,Belize Dollar,BZD,84,2,,
27+
CANADA,Canadian Dollar,CAD,124,2,,
28+
CONGO (THE DEMOCRATIC REPUBLIC OF THE),Congolese Franc,CDF,976,2,,
29+
SWITZERLAND,Swiss Franc,CHF,756,2,,
30+
CHILE,Chilean Peso,CLP,152,0,,
31+
CHINA,Yuan Renminbi,CNY,156,2,,
32+
COLOMBIA,Colombian Peso,COP,170,2,,
33+
COSTA RICA,Costa Rican Colon,CRC,188,2,,
34+
CUBA,Peso Convertible,CUC,931,2,,
35+
CUBA,Cuban Peso,CUP,192,2,,
36+
CABO VERDE,Cabo Verde Escudo,CVE,132,2,,
37+
CZECHIA,Czech Koruna,CZK,203,2,,
38+
DJIBOUTI,Djibouti Franc,DJF,262,0,,
39+
DENMARK,Danish Krone,DKK,208,2,,
40+
DOMINICAN REPUBLIC (THE),Dominican Peso,DOP,214,2,,
41+
ALGERIA,Algerian Dinar,DZD,12,2,,
42+
EGYPT,Egyptian Pound,EGP,818,2,,
43+
ERITREA,Nakfa,ERN,232,2,,
44+
ETHIOPIA,Ethiopian Birr,ETB,230,2,,
45+
ÅLAND ISLANDS,Euro,EUR,978,2,,
46+
FIJI,Fiji Dollar,FJD,242,2,,
47+
FALKLAND ISLANDS (THE) [MALVINAS],Falkland Islands Pound,FKP,238,2,,
48+
UNITED KINGDOM OF GREAT BRITAIN AND NORTHERN IRELAND (THE),Pound Sterling,GBP,826,2,,
49+
GEORGIA,Lari,GEL,981,2,,
50+
GHANA,Ghana Cedi,GHS,936,2,,
51+
GIBRALTAR,Gibraltar Pound,GIP,292,2,,
52+
GAMBIA (THE),Dalasi,GMD,270,2,,
53+
GUINEA,Guinean Franc,GNF,324,0,,
54+
GUATEMALA,Quetzal,GTQ,320,2,,
55+
GUYANA,Guyana Dollar,GYD,328,2,,
56+
HONG KONG,Hong Kong Dollar,HKD,344,2,,
57+
HONDURAS,Lempira,HNL,340,2,,
58+
CROATIA,Kuna,HRK,191,2,,
59+
HAITI,Gourde,HTG,332,2,,
60+
HUNGARY,Forint,HUF,348,2,,
61+
INDONESIA,Rupiah,IDR,360,2,,
62+
ISRAEL,New Israeli Sheqel,ILS,376,2,,
63+
INDIA,Indian Rupee,INR,356,2,,
64+
IRAQ,Iraqi Dinar,IQD,368,3,,
65+
IRAN (ISLAMIC REPUBLIC OF),Iranian Rial,IRR,364,2,,
66+
ICELAND,Iceland Krona,ISK,352,0,,
67+
JAMAICA,Jamaican Dollar,JMD,388,2,,
68+
JORDAN,Jordanian Dinar,JOD,400,3,,
69+
JAPAN,Yen,JPY,392,0,,
70+
KENYA,Kenyan Shilling,KES,404,2,,
71+
KYRGYZSTAN,Som,KGS,417,2,,
72+
CAMBODIA,Riel,KHR,116,2,,
73+
COMOROS (THE),Comorian Franc,KMF,174,0,,
74+
KOREA (THE DEMOCRATIC PEOPLE’S REPUBLIC OF),North Korean Won,KPW,408,2,,
75+
KOREA (THE REPUBLIC OF),Won,KRW,410,0,,
76+
KUWAIT,Kuwaiti Dinar,KWD,414,3,,
77+
CAYMAN ISLANDS (THE),Cayman Islands Dollar,KYD,136,2,,
78+
KAZAKHSTAN,Tenge,KZT,398,2,,
79+
LAO PEOPLE’S DEMOCRATIC REPUBLIC (THE),Lao Kip,LAK,418,2,,
80+
LEBANON,Lebanese Pound,LBP,422,2,,
81+
SRI LANKA,Sri Lanka Rupee,LKR,144,2,,
82+
LIBERIA,Liberian Dollar,LRD,430,2,,
83+
LESOTHO,Loti,LSL,426,2,,
84+
LIBYA,Libyan Dinar,LYD,434,3,,
85+
MOROCCO,Moroccan Dirham,MAD,504,2,,
86+
MOLDOVA (THE REPUBLIC OF),Moldovan Leu,MDL,498,2,,
87+
MADAGASCAR,Malagasy Ariary,MGA,969,2,,
88+
MACEDONIA (THE FORMER YUGOSLAV REPUBLIC OF),Denar,MKD,807,2,,
89+
MYANMAR,Kyat,MMK,104,2,,
90+
MONGOLIA,Tugrik,MNT,496,2,,
91+
MACAO,Pataca,MOP,446,2,,
92+
MAURITANIA,Ouguiya,MRU,929,2,,
93+
MAURITIUS,Mauritius Rupee,MUR,480,2,,
94+
MALDIVES,Rufiyaa,MVR,462,2,,
95+
MALAWI,Malawi Kwacha,MWK,454,2,,
96+
MEXICO,Mexican Peso,MXN,484,2,,
97+
MALAYSIA,Malaysian Ringgit,MYR,458,2,,
98+
MOZAMBIQUE,Mozambique Metical,MZN,943,2,,
99+
NAMIBIA,Namibia Dollar,NAD,516,2,,
100+
NIGERIA,Naira,NGN,566,2,,
101+
NICARAGUA,Cordoba Oro,NIO,558,2,,
102+
NORWAY,Norwegian Krone,NOK,578,2,,
103+
NEPAL,Nepalese Rupee,NPR,524,2,,
104+
NEW ZEALAND,New Zealand Dollar,NZD,554,2,,
105+
OMAN,Rial Omani,OMR,512,3,,
106+
PANAMA,Balboa,PAB,590,2,,
107+
PERU,Sol,PEN,604,2,,
108+
PAPUA NEW GUINEA,Kina,PGK,598,2,,
109+
PHILIPPINES (THE),Philippine Peso,PHP,608,2,,
110+
PAKISTAN,Pakistan Rupee,PKR,586,2,,
111+
POLAND,Zloty,PLN,985,2,,
112+
PARAGUAY,Guarani,PYG,600,0,,
113+
QATAR,Qatari Rial,QAR,634,2,,
114+
ROMANIA,Romanian Leu,RON,946,2,,
115+
SERBIA,Serbian Dinar,RSD,941,2,,
116+
RUSSIAN FEDERATION (THE),Russian Ruble,RUB,643,2,,
117+
RWANDA,Rwanda Franc,RWF,646,0,,
118+
SAUDI ARABIA,Saudi Riyal,SAR,682,2,,
119+
SOLOMON ISLANDS,Solomon Islands Dollar,SBD,90,2,,
120+
SEYCHELLES,Seychelles Rupee,SCR,690,2,,
121+
SUDAN (THE),Sudanese Pound,SDG,938,2,,
122+
SWEDEN,Swedish Krona,SEK,752,2,,
123+
SINGAPORE,Singapore Dollar,SGD,702,2,,
124+
"SAINT HELENA, ASCENSION AND TRISTAN DA CUNHA",Saint Helena Pound,SHP,654,2,,
125+
SIERRA LEONE,Leone,SLL,694,2,,
126+
SOMALIA,Somali Shilling,SOS,706,2,,
127+
SURINAME,Surinam Dollar,SRD,968,2,,
128+
SOUTH SUDAN,South Sudanese Pound,SSP,728,2,,
129+
SAO TOME AND PRINCIPE,Dobra,STN,930,2,,
130+
EL SALVADOR,El Salvador Colon,SVC,222,2,,
131+
SYRIAN ARAB REPUBLIC,Syrian Pound,SYP,760,2,,
132+
ESWATINI,Lilangeni,SZL,748,2,,
133+
THAILAND,Baht,THB,764,2,,
134+
TAJIKISTAN,Somoni,TJS,972,2,,
135+
TURKMENISTAN,Turkmenistan New Manat,TMT,934,2,,
136+
TUNISIA,Tunisian Dinar,TND,788,3,,
137+
TONGA,Pa’anga,TOP,776,2,,
138+
TURKEY,Turkish Lira,TRY,949,2,,
139+
TRINIDAD AND TOBAGO,Trinidad and Tobago Dollar,TTD,780,2,,
140+
TAIWAN (PROVINCE OF CHINA),New Taiwan Dollar,TWD,901,2,,
141+
"TANZANIA, UNITED REPUBLIC OF",Tanzanian Shilling,TZS,834,2,,
142+
UKRAINE,Hryvnia,UAH,980,2,,
143+
UGANDA,Uganda Shilling,UGX,800,0,,
144+
UNITED STATES OF AMERICA (THE),US Dollar,USD,840,2,,
145+
URUGUAY,Peso Uruguayo,UYU,858,2,,
146+
URUGUAY,Unidad Previsional,UYW,927,4,,
147+
UZBEKISTAN,Uzbekistan Sum,UZS,860,2,,
148+
VENEZUELA (BOLIVARIAN REPUBLIC OF),Bolívar Soberano,VES,928,2,,
149+
VIET NAM,Dong,VND,704,0,,
150+
VANUATU,Vatu,VUV,548,0,,
151+
SAMOA,Tala,WST,882,2,,
152+
CAMEROON,CFA Franc BEAC,XAF,950,0,,
153+
ANGUILLA,East Caribbean Dollar,XCD,951,2,,
154+
BENIN,CFA Franc BCEAO,XOF,952,0,,
155+
FRENCH POLYNESIA,CFP Franc,XPF,953,0,,
156+
YEMEN,Yemeni Rial,YER,886,2,,
157+
LESOTHO,Rand,ZAR,710,2,,
158+
ZAMBIA,Zambian Kwacha,ZMW,967,2,,
159+
ZIMBABWE,Zimbabwe Dollar,ZWL,932,2,,

Sources/Currency/Currency.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Currency open source project
4+
//
5+
// Copyright (c) 2020 Currency project authors
6+
// Licensed under MIT License
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Currency project authors
10+
//
11+
// SPDX-License-Identifier: MIT
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
/// A type that provides static currency information as defined by ISO 4217.
16+
public protocol CurrencyMetadata {
17+
/// The name of the currency, such as "United States Dollar".
18+
static var name: String { get }
19+
/// The ISO 4217 3-digit letter currency code.
20+
///
21+
/// For example: "USD" for "United States Dollar".
22+
static var alphabeticCode: String { get }
23+
/// The ISO 4217 3-digit numeric currency code.
24+
///
25+
/// This code is nomally the same as the ISO 3166-1 country codes, where appropriate.
26+
///
27+
/// For example, "United States of America" has the ISO 3166-1 code of 840, which is the same for the "USD" currency in ISO 4217.
28+
static var numericCode: UInt16 { get }
29+
/// The number of decimal digits used to express minor units of the currency.
30+
///
31+
/// For example, the US Dollar has the minor unit (cents) that are 1/100 of a dollar. Therefore, the the minorUnits is `2`.
32+
///
33+
/// However, the Japanese Yen has no minor unit, so it has `0` minorUnits.
34+
static var minorUnits: UInt8 { get }
35+
}

0 commit comments

Comments
 (0)