From da0ea3184484fb0818adbf70a9422c32eff4f30d Mon Sep 17 00:00:00 2001 From: Benjamin Cable Date: Mon, 16 Sep 2024 19:33:14 +0100 Subject: [PATCH] chore: v2 folder --- v2 | 1 - v2/.github/workflows/flat.yml | 30 + v2/.gitignore | 1 + v2/LICENSE | 21 + v2/Makefile | 4 + v2/README.md | 32 + v2/accounting/README.md | 50 + v2/accounting/accounting.go | 219 ++++ v2/accounting/accounting_test.go | 1591 ++++++++++++++++++++++++ v2/accounting/errors.go | 27 + v2/accounting/floats.go | 22 + v2/cmd/js.txt | 7 + v2/cmd/kotlin.txt | 10 + v2/cmd/list_one.xml | 1956 ++++++++++++++++++++++++++++++ v2/cmd/main.go | 247 ++++ v2/cmd/scaffold/list.go | 17 + v2/cmd/std.txt | 85 ++ v2/cmd/swift.txt | 37 + v2/go.mod | 8 + v2/go.sum | 4 + v2/std.go | 792 ++++++++++++ v2/std.kt | 185 +++ v2/std.swift | 389 ++++++ v2/std_currency.js | 360 ++++++ 24 files changed, 6094 insertions(+), 1 deletion(-) delete mode 160000 v2 create mode 100644 v2/.github/workflows/flat.yml create mode 100644 v2/.gitignore create mode 100644 v2/LICENSE create mode 100644 v2/Makefile create mode 100644 v2/README.md create mode 100644 v2/accounting/README.md create mode 100644 v2/accounting/accounting.go create mode 100644 v2/accounting/accounting_test.go create mode 100644 v2/accounting/errors.go create mode 100644 v2/accounting/floats.go create mode 100644 v2/cmd/js.txt create mode 100644 v2/cmd/kotlin.txt create mode 100644 v2/cmd/list_one.xml create mode 100644 v2/cmd/main.go create mode 100644 v2/cmd/scaffold/list.go create mode 100644 v2/cmd/std.txt create mode 100644 v2/cmd/swift.txt create mode 100644 v2/go.mod create mode 100644 v2/go.sum create mode 100644 v2/std.go create mode 100644 v2/std.kt create mode 100644 v2/std.swift create mode 100644 v2/std_currency.js diff --git a/v2 b/v2 deleted file mode 160000 index 74ed802..0000000 --- a/v2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 74ed80201799ffea2bbee4aa3adec90302ccb71d diff --git a/v2/.github/workflows/flat.yml b/v2/.github/workflows/flat.yml new file mode 100644 index 0000000..efdcd5b --- /dev/null +++ b/v2/.github/workflows/flat.yml @@ -0,0 +1,30 @@ +name: data +on: + schedule: + - cron: 0 0 * * * + workflow_dispatch: {} + push: + paths: + - .github/workflows/flat.yml +jobs: + scheduled: + runs-on: ubuntu-latest + steps: + - name: Setup deno + uses: denoland/setup-deno@main + with: + deno-version: v1.x + - name: Check out repo + uses: actions/checkout@v2 + - name: Fetch data + uses: githubocto/flat@v3 + with: + http_url: https://www.six-group.com/dam/download/financial-information/data-center/iso-currrency/lists/list-one.xml + downloaded_filename: cmd/list_one.xml + # Build the libraries. + - name: build application + run: make build + - name: Git Auto Commit + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: apply automatic changes diff --git a/v2/.gitignore b/v2/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/v2/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/v2/LICENSE b/v2/LICENSE new file mode 100644 index 0000000..9883ad0 --- /dev/null +++ b/v2/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Benjamin Cable + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/v2/Makefile b/v2/Makefile new file mode 100644 index 0000000..c9772ac --- /dev/null +++ b/v2/Makefile @@ -0,0 +1,4 @@ +build: + go run cmd/main.go + gofmt -w std.go + go test -v -cover ./... diff --git a/v2/README.md b/v2/README.md new file mode 100644 index 0000000..9e4096c --- /dev/null +++ b/v2/README.md @@ -0,0 +1,32 @@ +# currency + +This package generates structs containing all the up-to-date `ISO4217` currency codes and minor units, along with a very simple validator. + +Data is graciously provided by: + +- [International Organization for Standardization](https://www.iso.org/iso-4217-currency-codes.html) +- [Currency Code Services – ISO 4217 Maintenance Agency](https://www.currency-iso.org) + +## Usage: + +```go +package main + +import ( + "fmt" + "github.com/ladydascalie/currency" +) + +func main() { + // Validate currency code. + if !currency.Valid("ABC") { + // Handle invalid currency code. + fmt.Println("Invalid currency code") + } + + // Retrieve and print currency values. + fmt.Println(currency.USD.Code()) // Output: USD + fmt.Println(currency.USD.MinorUnit()) // Output: 2 +} + +``` diff --git a/v2/accounting/README.md b/v2/accounting/README.md new file mode 100644 index 0000000..293bed8 --- /dev/null +++ b/v2/accounting/README.md @@ -0,0 +1,50 @@ +# Accounting + +The accounting package is used when dealing with currency math that requires a high degree of precision. + +A few business rules and assumptions are made: + +- Banker's Rounding (or round half to even) is applied whenever rounding mode is available. + - see: [https://en.wikipedia.org/wiki/Rounding#Round_half_to_even](https://en.wikipedia.org/wiki/Rounding#Round_half_to_even) +- The maximum precision allowed after the decimal dot is **2**. + +Examples: + +```go +package main + +import ( + "fmt" + + "github.com/ladydascalie/currency/accounting" + "github.com/ladydascalie/currency" +) + +func main() { + // Create an amount from an int64 and a currency + amount := accounting.MakeAmount(currency.GBP, 1234) + + // Amounts contain the minor representation of that currency. + fmt.Println(amount.MinorValue) + // output: 1234 + + // alternatively floats are also ok! + gbp := accounting.Float64ToAmount(currency.GBP, 32.32) + fmt.Printf("minor value: %d, stringer: %s", gbp.MinorValue, gbp) + // output: minor value: 3232, stringer: 32.32 GBP + + // Currencies with no minor decimals drop the invalid precision. + jpy := accounting.Float64ToAmount(currency.JPY, 32.32) + fmt.Printf("minor value: %d, stringer: %s", jpy.MinorValue, jpy) + // output: minor value: 32, stringer: 32 JPY + + // Exchanging currencies is also supported. + usd := accounting.Float64ToAmount(currency.USD, 100.0) + eur, err := accounting.Exchange(usd, currency.EUR, 1.08968) + if err != nil { + // handle... + } + fmt.Println(eur) + // output: 91.77 EUR +} +``` diff --git a/v2/accounting/accounting.go b/v2/accounting/accounting.go new file mode 100644 index 0000000..c617448 --- /dev/null +++ b/v2/accounting/accounting.go @@ -0,0 +1,219 @@ +package accounting + +import ( + "fmt" + "math" + "math/big" + "strconv" + "strings" + + "github.com/ladydascalie/currency/v2" +) + +const ( + // QuadruplePrecision describes 128 bits of precision for IEEE 754 decimals + // see: https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format + QuadruplePrecision uint = 128 + + // OctuplePrecision describes 256 bits of precision for for IEEE 754 decimals + // see: https://en.wikipedia.org/wiki/Octuple-precision_floating-point_format + OctuplePrecision uint = 256 +) + +var ( + // Minimum rate of tax must be 0. + // As far as we know, there are as of writing, no markets with a negative sales tax. + min = itof(0) + + // Baseline for creating a rate divisor. + base = itof(1) +) + +// Amount defines an amount in a given currency, in it's minor unit form. +type Amount struct { + Currency currency.Currency + MinorValue int64 +} + +// MakeAmount returns an Amount from the provided currency and minor unit value. +func MakeAmount(c currency.Currency, minorValue int64) Amount { + return Amount{ + Currency: c, + MinorValue: minorValue, + } +} + +// String implements a default stringer for an Amount +// Note that the string will be in "human readable" format, rather than +// using the minor currency unit, this conversion is done using the +// AmountToFloat64 function, also available within this package. +// ISO_4217 does not regulate spacing or prefixing vs. suffixing. +// Strings produced using this method always follow this pattern: +// +// ┏━━ always decimal dot separated. +// ┃ +// 123.45 GBP +// ┃ ┗━━ ISO currency code. +// ┗━━ maximum 2 digits precision. +func (a Amount) String() string { + f64 := AmountToFloat64(a) + format := fmt.Sprintf("%%.%df %%s", a.Currency.MinorUnits()) + return fmt.Sprintf(format, f64, a.Currency.Code()) +} + +// ValidateManyFloatsArePrecise tests that the given float64 arguments +// have the desired precision, this is a convenience wrapper +// around ValidateFloatIsPrecise. +// NOTE: 2 digits past the dot is a business rule. +func ValidateManyFloatsArePrecise(args ...float64) error { + for _, f := range args { + if err := ValidateFloatIsPrecise(f); err != nil { + return err + } + } + return nil +} + +// ValidateFloatIsPrecise ensures that a float64 value does not exceed +// a precision of 2 digits past the decimal period. This ensures we do not +// store incorrect currency data. +// NOTE: 2 digits past the decimal period is a business rule. +func ValidateFloatIsPrecise(f float64) error { + // parse the float, with the smallest number of digits necessary + parsed := strconv.FormatFloat(f, 'f', -1, 64) + + // split the parsed number on the decimal period + parts := strings.Split(parsed, ".") + + // in case of exact number... + if len(parts) == 1 { + return nil + } + + // check the float's precision + if prec := len([]rune(parts[1])); prec > 2 { + return ErrFloatPrecision{ + Value: parsed, + Precision: prec, + } + } + return nil +} + +// Float64ToAmount returns an amount from the provided currency and value. +func Float64ToAmount(c currency.Currency, value float64) Amount { + minor := int64(math.Round(value * float64(c.Factor()))) + return Amount{ + Currency: c, + MinorValue: minor, + } +} + +// AmountToFloat64 returns the currency data as a floating point from it's +// minor currency unit format. +func AmountToFloat64(amount Amount) float64 { + // fast path for currencies like JPY with a factor of 1. + if amount.Currency.Factor() == 1 { + return float64(amount.MinorValue) + } + var ( + v = itof(amount.MinorValue) + f = ftof(amount.Currency.FactorF64()) + ) + f64, _ := newf().Quo(v, f).Float64() + return f64 +} + +// Exchange - Apply currency exchange rates to an amount. +// +// rate - should always be given from the approved finance list. +// NOTE: A rate of zero will return the amount you put in, unchanged. +// +// Rounding to the nearest even is a defined business rule. +// Tills may round up to the nearest penny, but for reporting, the rule is +// always to use banker's rounding. +// +// If unclear, see: // http://wiki.c2.com/?BankersRounding. +func Exchange(amount Amount, c currency.Currency, rate float64) (Amount, error) { + switch { + case rate < 0: + return Amount{}, ErrSubZeroRate + case rate == 0: + // Decomissioned currencies might trigger that case, + // but that should really not be the general rule. + return MakeAmount(c, 0), nil + } + + from := ftof(AmountToFloat64(amount)) + bigRate := ftof(rate) + + // Here we divide the value, by it's minor currency + // unit factor, then divide it once more by the + // exchange rate. + // -> v / e + to, _ := from.Quo(from, bigRate).Float64() + + // http://wiki.c2.com/?BankersRounding + // This part guarantees that we will not have more than 2 decimals after the dot. + to = math.RoundToEven(to*100) / 100 + + return Float64ToAmount(c, to), nil +} + +// RatNetAmount applies a VAT rate to a big.Rat value. This method returns a big.Float +// so it's accuracy can be checked, and it's value applied with .Rat(some.field) +func RatNetAmount(gross, rate *big.Rat) (*big.Float, error) { + // Here we go for octuple precision as we are dealing with rational numbers. + bf := func(rat *big.Rat) *big.Float { + return big.NewFloat(0).SetRat(rat).SetPrec(OctuplePrecision).SetMode(big.ToNearestEven) + } + + v := bf(gross) + r := bf(rate) + + // Guard against impossible (negative) tax rates. + switch r.Cmp(min) { + case -1: + return min, ErrSubZeroRate + case 0: + return v, nil + } + // Turn the rate into a divisor by making it superior to 1. + divisor := newf().Add(base, r) + + // Here we divide the gross by it's vat: + // -> val / vat + // where vat is a gross superior to 1. + return newf().Quo(v, divisor), nil +} + +// NetAmount derives the net amount before tax is applied using the given rate. +func NetAmount(gross int64, rate float64) (int64, error) { + grossRat, _ := itof(gross).Rat(nil) + rateRat, _ := ftof(rate).Rat(nil) + + bf, err := RatNetAmount(grossRat, rateRat) + if err != nil { + return 0, err + } + + netStr := bf.Text('f', 0) + net, _ := new(big.Int).SetString(netStr, 10) + return net.Int64(), nil +} + +// TaxAmount returns the difference between the gross and the net amounts. +func TaxAmount(gross, net int64) (int64, error) { + // Guard against values that are not allowed in this context. + if gross < 0 { + return 0, ErrSubZeroGross + } + if net < 0 { + return 0, ErrSubZeroNet + } + if net > gross { + return 0, ErrNetOverGrossAmount + } + // list amount - net amount = tax amount + return gross - net, nil +} diff --git a/v2/accounting/accounting_test.go b/v2/accounting/accounting_test.go new file mode 100644 index 0000000..1c6f5a6 --- /dev/null +++ b/v2/accounting/accounting_test.go @@ -0,0 +1,1591 @@ +package accounting_test + +import ( + "fmt" + "math/big" + "testing" + + "github.com/google/go-cmp/cmp" + fuzz "github.com/google/gofuzz" + "github.com/ladydascalie/currency/v2" + "github.com/ladydascalie/currency/v2/accounting" +) + +func ExampleFloat64ToAmount_gbp() { + gbp := accounting.Float64ToAmount(currency.GBP, 32.32) + fmt.Printf("minor value: %d, stringer: %s", gbp.MinorValue, gbp) + // output: minor value: 3232, stringer: 32.32 GBP +} + +func ExampleFloat64ToAmount_jpy() { + // JPY doesn't allow for values after the decimal dot, since it has a + // minor currency unit of 1. + jpy := accounting.Float64ToAmount(currency.JPY, 32.32) + fmt.Printf("minor value: %d, stringer: %s", jpy.MinorValue, jpy) + // output: minor value: 32, stringer: 32 JPY +} + +func ExampleExchange_usd_eur() { + // 4 May 2020 08:00 UTC - 5 May 2020 08:01 UTC + // EUR/USD close:1.08968 low:1.08871 high:1.09479 + usd := accounting.Float64ToAmount(currency.USD, 100.0) + eur, err := accounting.Exchange(usd, currency.EUR, 1.08968) + if err != nil { + // handle... + } + fmt.Println(eur) + // output: 91.77 EUR +} + +func ExampleExchange_usd_jpy() { + // 4 May 2020 07:40 UTC - 5 May 2020 07:40 UTC + // JPY/USD close:0.00937 low:0.00934 high:0.00939 + usd := accounting.Float64ToAmount(currency.USD, 100.0) + jpy, err := accounting.Exchange(usd, currency.JPY, 0.00937) + if err != nil { + // handle... + } + fmt.Println(jpy) + // output: 10672 JPY +} + +func TestAmount_String(t *testing.T) { + t.Run("GBP", func(t *testing.T) { + got := accounting.MakeAmount(currency.GBP, 1234).String() + want := "12.34 GBP" + if diff := cmp.Diff(got, want); diff != "" { + t.Fatalf("failed (-got +want): %s", diff) + } + }) + t.Run("JPY", func(t *testing.T) { + got := accounting.MakeAmount(currency.JPY, 1234).String() + want := "1234 JPY" + if diff := cmp.Diff(got, want); diff != "" { + t.Fatalf("failed (-got +want): %s", diff) + } + }) +} + +func TestExchange(t *testing.T) { + // factors of 1, 100, 1000 and 10000 are represented. + // + // As there is no point in duplicating tests for currencies with + // the exact same minor unit, the better approach is to instead + // bulk up the amount of unique values tested. + // + // The test is essentially: + // value / factor / rate = want + // + // Each value in the want array has been calculated manually. + tests := []struct { + expectedErr error + from currency.Currency + to currency.Currency + name string + amount float64 + expected float64 + rate float64 + }{ + { + name: "100 USD in USD", + expected: 100, + rate: 1, + from: currency.USD, + to: currency.USD, + }, + { + name: "100 USD in EUR", + expected: 91.61, + rate: 1.0916, + from: currency.USD, + to: currency.EUR, + }, + { + name: "100 USD in GBP", + expected: 80.51, + rate: 1.2421, + from: currency.USD, + to: currency.GBP, + }, + { + name: "100 USD in JPY", + expected: 10678, + rate: 0.00936545, + from: currency.USD, + to: currency.JPY, + }, + { + name: "100 USD in TND", + expected: 290.02, + rate: 0.3448, + from: currency.USD, + to: currency.TND, + }, + { + name: "100 EUR in USD", + expected: 109.16, + rate: 0.9161, + from: currency.EUR, + to: currency.USD, + }, + { + name: "100 EUR in EUR", + expected: 100, + rate: 1, + from: currency.EUR, + to: currency.EUR, + }, + { + name: "100 EUR in GBP", + expected: 87.88, + rate: 1.1379, + from: currency.EUR, + to: currency.GBP, + }, + { + name: "100 EUR in JPY", + expected: 11628, + rate: 0.0086, + from: currency.EUR, + to: currency.JPY, + }, + { + name: "100 EUR in TND", + expected: 316.66, + rate: 0.3158, + from: currency.EUR, + to: currency.TND, + }, + { + name: "100 GBP in USD", + expected: 124.21, + rate: 0.8051, + from: currency.GBP, + to: currency.USD, + }, + { + name: "100 GBP in EUR", + expected: 113.79, + rate: 0.8788, + from: currency.GBP, + to: currency.EUR, + }, + { + name: "100 GBP in GBP", + expected: 100, + rate: 1, + from: currency.GBP, + to: currency.GBP, + }, + { + name: "100 GBP in JPY", + expected: 13333, + rate: 0.0075, + from: currency.GBP, + to: currency.JPY, + }, + { + name: "100 GBP in TND", + expected: 360.23, + rate: 0.2776, + from: currency.GBP, + to: currency.TND, + }, + { + name: "100 JPY in USD", + expected: 0.94, + rate: 106.9404, + from: currency.JPY, + to: currency.USD, + }, + { + name: "100 JPY in EUR", + expected: 0.86, + rate: 116.7394, + from: currency.JPY, + to: currency.EUR, + }, + { + name: "100 JPY in GBP", + expected: 0.75, + rate: 132.8351, + from: currency.JPY, + to: currency.GBP, + }, + { + name: "100 JPY in JPY", + expected: 100, + rate: 1, + from: currency.JPY, + to: currency.JPY, + }, + { + name: "100 JPY in TND", + expected: 2.71, + rate: 36.8696, + from: currency.JPY, + to: currency.TND, + }, + { + name: "100 TND in USD", + expected: 34.48, + rate: 2.9005, + from: currency.TND, + to: currency.USD, + }, + { + name: "100 TND in EUR", + expected: 31.58, + rate: 3.1663, + from: currency.TND, + to: currency.EUR, + }, + { + name: "100 TND in GBP", + expected: 27.76, + rate: 3.6028, + from: currency.TND, + to: currency.GBP, + }, + { + name: "100 TND in JPY", + expected: 3690, + rate: 0.0271, + from: currency.TND, + to: currency.JPY, + }, + { + name: "100 TND in TND", + expected: 100, + rate: 1, + from: currency.TND, + to: currency.TND, + }, + { + name: "Subzero exchange rate must fail", + expected: 100, + rate: -1, + from: currency.TND, + to: currency.TND, + expectedErr: accounting.ErrSubZeroRate, + }, + { + name: "Zero rate should return zero amount", + expected: 0, + rate: 0, + from: currency.TND, + to: currency.TND, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + amount := accounting.Float64ToAmount(tt.from, 100) + result, err := accounting.Exchange(amount, tt.to, tt.rate) + if tt.expectedErr != err { + t.Fatal("expected an error but got none") + } + if err == nil { + if diff := cmp.Diff(tt.expected, accounting.AmountToFloat64(result)); diff != "" { + t.Errorf("Exchange() mismatch (-want +got):\n%s", diff) + } + } + }) + } +} + +func TestRatNetAmount(t *testing.T) { + br := func(f64 float64) *big.Rat { + return new(big.Rat).SetFloat64(f64) + } + + type args struct { + value *big.Rat + rate *big.Rat + } + tests := []struct { + args args + expectedErr error + name string + want string + }{ + { + name: "gross 10 vat 19", + args: args{ + value: br(10), + rate: br(.19), + }, + want: "8.403361345", + }, + { + name: "gross 19.99 vat 20", + args: args{ + value: br(19.99), + rate: br(.20), + }, + want: "16.658333333", + }, + { + name: "gross 123 vat 7", + args: args{ + value: br(123), + rate: br(.07), + }, + want: "114.953271028", + }, + { + name: "Subzero rate should fail", + args: args{ + value: br(123), + rate: br(-1), + }, + want: "", + expectedErr: accounting.ErrSubZeroRate, + }, + { + name: "Zero rate should return zero value", + args: args{ + value: br(123), + rate: br(0), + }, + want: "123.000000000", + expectedErr: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := accounting.RatNetAmount(tt.args.value, tt.args.rate) + if err != tt.expectedErr { + t.Fatal("expected an error but got none") + } + if err == nil { + if diff := cmp.Diff(tt.want, got.Text('f', 9)); diff != "" { + t.Errorf("RatNetAmount() mismatch (-want +got):\n%s", diff) + } + } + }) + } +} + +func TestToMinorUnit(t *testing.T) { + for _, tt := range minorUnitTestsCases { + t.Run(tt.name, func(t *testing.T) { + amount := accounting.Float64ToAmount(currency.GBP, tt.f64) + + if diff := cmp.Diff(tt.i64, amount.MinorValue); diff != "" { + t.Errorf("ToMinorUnit() mismatch (-want +got):\n%s", diff) + } + }) + } +} + +func TestFromMinorUnit(t *testing.T) { + for _, tt := range minorUnitTestsCases { + t.Run(tt.name, func(t *testing.T) { + amount := accounting.MakeAmount(currency.GBP, tt.i64) + + f := accounting.AmountToFloat64(amount) + if diff := cmp.Diff(tt.f64, f); diff != "" { + t.Errorf("FromMinorUnit() mismatch (-want +got):\n%s", diff) + } + }) + } +} + +func TestValidateFloatIsPrecise(t *testing.T) { + tests := []struct { + name string + amount float64 + wantError bool + }{ + { + name: "exact number", + amount: 10, + wantError: false, + }, + { + name: "too long", + amount: 12.123, + wantError: true, + }, + { + name: "valid amount", + amount: 12.12, + wantError: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := accounting.ValidateFloatIsPrecise(tt.amount) + if (err != nil) != tt.wantError { + t.Fatalf( + "ValidateFloatIsPrecise: failed on %v", + tt.amount, + ) + } + }) + } +} + +func TestValidateManyFloatsArePrecise(t *testing.T) { + tests := []struct { + name string + amounts []float64 + wantError bool + }{ + { + name: "exact numbers", + amounts: []float64{10, 11, 12}, + wantError: false, + }, + { + name: "one is too long", + amounts: []float64{11, 12.123, 13}, + wantError: true, + }, + { + name: "valid amounts", + amounts: []float64{11.11, 12.12, 13.13}, + wantError: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := accounting.ValidateManyFloatsArePrecise(tt.amounts...) + if (err != nil) != tt.wantError { + t.Fatalf("ValidateFloatIsPrecise: failed with %v", err) + } + }) + } +} + +func TestNetAmount(t *testing.T) { + type args struct { + gross int64 + rate float64 + } + tests := []struct { + args args + want int64 + wantErr bool + }{ + { + args: args{ + gross: 1999, + rate: 0.20, + }, + want: 1666, + wantErr: false, + }, + { + args: args{ + gross: 1234, + rate: 0.19, + }, + want: 1037, + wantErr: false, + }, + { + args: args{ + gross: 9999, + rate: 0.33, + }, + want: 7518, + wantErr: false, + }, + { + args: args{ + gross: 1234, + rate: 0.0, + }, + want: 1234, + wantErr: false, + }, + { + args: args{ + gross: 1234, + rate: -1.0, + }, + want: 0, + wantErr: true, + }, + } + for i, tt := range tests { + t.Run(fmt.Sprintf("NetAmount_%d", i), func(t *testing.T) { + got, err := accounting.NetAmount(tt.args.gross, tt.args.rate) + if (err != nil) != tt.wantErr { + t.Errorf("NetAmount() error = %v, wantErr %v", err, tt.wantErr) + return + } + if diff := cmp.Diff(tt.want, got); diff != "" { + t.Errorf("NetAmount() mismatch (-want +got):\n%s", diff) + } + }) + } +} + +func TestFuzzNetAmount(t *testing.T) { + type args struct { + Gross int64 + Rate float64 + } + + fz := fuzz.New() + + // 1M iterations. + for i := 0; i < 1e6; i++ { + var a args + fz.Fuzz(&a) + // we don't really care about the values here. + // we just want to prove that the function cannot panic. + netAmount, err := accounting.NetAmount(a.Gross, a.Rate) + useInt64(netAmount) + useError(err) + } +} + +func TestFuzzTaxAmount(t *testing.T) { + // One might call this test spurious. + // And you'd be right. + // But if we ever change the internals, we'll be glad to have it! + type args struct { + Gross int64 + Net int64 + } + + fz := fuzz.New() + + // 1M iterations. + for i := 0; i < 1e6; i++ { + var a args + fz.Fuzz(&a) + + // we don't really care about the values here. + // we just want to prove that the function cannot panic. + taxAmount, taxAmountError := accounting.TaxAmount(a.Gross, a.Net) + useInt64(taxAmount) + useError(taxAmountError) + } +} + +var minorUnitTestsCases = []struct { + name string + f64 float64 + i64 int64 +}{ + { + name: "known dangerous value", + f64: 9.95, + i64: 995, + }, + { + name: "known dangerous negative value", + f64: -9.95, + i64: -995, + }, + { + name: "f64:1.15", + f64: 1.15, + i64: 115, + }, + { + name: "f64:2.25", + f64: 2.25, + i64: 225, + }, + { + name: "f64:3.35", + f64: 3.35, + i64: 335, + }, + { + name: "f64:4.45", + f64: 4.45, + i64: 445, + }, + { + name: "f64:5.55", + f64: 5.55, + i64: 555, + }, + { + name: "f64:6.65", + f64: 6.65, + i64: 665, + }, + { + name: "f64:7.75", + f64: 7.75, + i64: 775, + }, + { + name: "f64:8.85", + f64: 8.85, + i64: 885, + }, + { + name: "f64:9.95", + f64: 9.95, + i64: 995, + }, + { + name: "f64:10.10", + f64: 10.10, + i64: 1010, + }, + { + name: "f64:11.11", + f64: 11.11, + i64: 1111, + }, + { + name: "f64:12.12", + f64: 12.12, + i64: 1212, + }, + { + name: "f64:13.13", + f64: 13.13, + i64: 1313, + }, + { + name: "f64:14.14", + f64: 14.14, + i64: 1414, + }, + { + name: "f64:15.15", + f64: 15.15, + i64: 1515, + }, + { + name: "f64:16.16", + f64: 16.16, + i64: 1616, + }, + { + name: "f64:17.17", + f64: 17.17, + i64: 1717, + }, + { + name: "f64:18.18", + f64: 18.18, + i64: 1818, + }, + { + name: "f64:19.19", + f64: 19.19, + i64: 1919, + }, + { + name: "f64:20.20", + f64: 20.20, + i64: 2020, + }, + { + name: "f64:21.21", + f64: 21.21, + i64: 2121, + }, + { + name: "f64:22.22", + f64: 22.22, + i64: 2222, + }, + { + name: "f64:23.23", + f64: 23.23, + i64: 2323, + }, + { + name: "f64:24.24", + f64: 24.24, + i64: 2424, + }, + { + name: "f64:25.25", + f64: 25.25, + i64: 2525, + }, + { + name: "f64:26.26", + f64: 26.26, + i64: 2626, + }, + { + name: "f64:27.27", + f64: 27.27, + i64: 2727, + }, + { + name: "f64:28.28", + f64: 28.28, + i64: 2828, + }, + { + name: "f64:29.29", + f64: 29.29, + i64: 2929, + }, + { + name: "f64:30.30", + f64: 30.30, + i64: 3030, + }, + { + name: "f64:31.31", + f64: 31.31, + i64: 3131, + }, + { + name: "f64:32.32", + f64: 32.32, + i64: 3232, + }, + { + name: "f64:33.33", + f64: 33.33, + i64: 3333, + }, + { + name: "f64:34.34", + f64: 34.34, + i64: 3434, + }, + { + name: "f64:35.35", + f64: 35.35, + i64: 3535, + }, + { + name: "f64:36.36", + f64: 36.36, + i64: 3636, + }, + { + name: "f64:37.37", + f64: 37.37, + i64: 3737, + }, + { + name: "f64:38.38", + f64: 38.38, + i64: 3838, + }, + { + name: "f64:39.39", + f64: 39.39, + i64: 3939, + }, + { + name: "f64:40.40", + f64: 40.40, + i64: 4040, + }, + { + name: "f64:41.41", + f64: 41.41, + i64: 4141, + }, + { + name: "f64:42.42", + f64: 42.42, + i64: 4242, + }, + { + name: "f64:43.43", + f64: 43.43, + i64: 4343, + }, + { + name: "f64:44.44", + f64: 44.44, + i64: 4444, + }, + { + name: "f64:45.45", + f64: 45.45, + i64: 4545, + }, + { + name: "f64:46.46", + f64: 46.46, + i64: 4646, + }, + { + name: "f64:47.47", + f64: 47.47, + i64: 4747, + }, + { + name: "f64:48.48", + f64: 48.48, + i64: 4848, + }, + { + name: "f64:49.49", + f64: 49.49, + i64: 4949, + }, + { + name: "f64:50.50", + f64: 50.50, + i64: 5050, + }, + { + name: "f64:51.51", + f64: 51.51, + i64: 5151, + }, + { + name: "f64:52.52", + f64: 52.52, + i64: 5252, + }, + { + name: "f64:53.53", + f64: 53.53, + i64: 5353, + }, + { + name: "f64:54.54", + f64: 54.54, + i64: 5454, + }, + { + name: "f64:55.55", + f64: 55.55, + i64: 5555, + }, + { + name: "f64:56.56", + f64: 56.56, + i64: 5656, + }, + { + name: "f64:57.57", + f64: 57.57, + i64: 5757, + }, + { + name: "f64:58.58", + f64: 58.58, + i64: 5858, + }, + { + name: "f64:59.59", + f64: 59.59, + i64: 5959, + }, + { + name: "f64:60.60", + f64: 60.60, + i64: 6060, + }, + { + name: "f64:61.61", + f64: 61.61, + i64: 6161, + }, + { + name: "f64:62.62", + f64: 62.62, + i64: 6262, + }, + { + name: "f64:63.63", + f64: 63.63, + i64: 6363, + }, + { + name: "f64:64.64", + f64: 64.64, + i64: 6464, + }, + { + name: "f64:65.65", + f64: 65.65, + i64: 6565, + }, + { + name: "f64:66.66", + f64: 66.66, + i64: 6666, + }, + { + name: "f64:67.67", + f64: 67.67, + i64: 6767, + }, + { + name: "f64:68.68", + f64: 68.68, + i64: 6868, + }, + { + name: "f64:69.69", + f64: 69.69, + i64: 6969, + }, + { + name: "f64:70.70", + f64: 70.70, + i64: 7070, + }, + { + name: "f64:71.71", + f64: 71.71, + i64: 7171, + }, + { + name: "f64:72.72", + f64: 72.72, + i64: 7272, + }, + { + name: "f64:73.73", + f64: 73.73, + i64: 7373, + }, + { + name: "f64:74.74", + f64: 74.74, + i64: 7474, + }, + { + name: "f64:75.75", + f64: 75.75, + i64: 7575, + }, + { + name: "f64:76.76", + f64: 76.76, + i64: 7676, + }, + { + name: "f64:77.77", + f64: 77.77, + i64: 7777, + }, + { + name: "f64:78.78", + f64: 78.78, + i64: 7878, + }, + { + name: "f64:79.79", + f64: 79.79, + i64: 7979, + }, + { + name: "f64:80.80", + f64: 80.80, + i64: 8080, + }, + { + name: "f64:81.81", + f64: 81.81, + i64: 8181, + }, + { + name: "f64:82.82", + f64: 82.82, + i64: 8282, + }, + { + name: "f64:83.83", + f64: 83.83, + i64: 8383, + }, + { + name: "f64:84.84", + f64: 84.84, + i64: 8484, + }, + { + name: "f64:85.85", + f64: 85.85, + i64: 8585, + }, + { + name: "f64:86.86", + f64: 86.86, + i64: 8686, + }, + { + name: "f64:87.87", + f64: 87.87, + i64: 8787, + }, + { + name: "f64:88.88", + f64: 88.88, + i64: 8888, + }, + { + name: "f64:89.89", + f64: 89.89, + i64: 8989, + }, + { + name: "f64:90.90", + f64: 90.90, + i64: 9090, + }, + { + name: "f64:91.91", + f64: 91.91, + i64: 9191, + }, + { + name: "f64:92.92", + f64: 92.92, + i64: 9292, + }, + { + name: "f64:93.93", + f64: 93.93, + i64: 9393, + }, + { + name: "f64:94.94", + f64: 94.94, + i64: 9494, + }, + { + name: "f64:95.95", + f64: 95.95, + i64: 9595, + }, + { + name: "f64:96.96", + f64: 96.96, + i64: 9696, + }, + { + name: "f64:97.97", + f64: 97.97, + i64: 9797, + }, + { + name: "f64:98.98", + f64: 98.98, + i64: 9898, + }, + { + name: "f64:99.99", + f64: 99.99, + i64: 9999, + }, + { + name: "f64:100.105", + f64: 100.10, + i64: 10010, + }, + { + name: "f64:1.15", + f64: -1.15, + i64: -115, + }, + { + name: "f64:2.25", + f64: -2.25, + i64: -225, + }, + { + name: "f64:3.35", + f64: -3.35, + i64: -335, + }, + { + name: "f64:4.45", + f64: -4.45, + i64: -445, + }, + { + name: "f64:5.55", + f64: -5.55, + i64: -555, + }, + { + name: "f64:6.65", + f64: -6.65, + i64: -665, + }, + { + name: "f64:7.75", + f64: -7.75, + i64: -775, + }, + { + name: "f64:8.85", + f64: -8.85, + i64: -885, + }, + { + name: "f64:9.95", + f64: -9.95, + i64: -995, + }, + { + name: "f64:10.10", + f64: -10.10, + i64: -1010, + }, + { + name: "f64:11.11", + f64: -11.11, + i64: -1111, + }, + { + name: "f64:12.12", + f64: -12.12, + i64: -1212, + }, + { + name: "f64:13.13", + f64: -13.13, + i64: -1313, + }, + { + name: "f64:14.14", + f64: -14.14, + i64: -1414, + }, + { + name: "f64:15.15", + f64: -15.15, + i64: -1515, + }, + { + name: "f64:16.16", + f64: -16.16, + i64: -1616, + }, + { + name: "f64:17.17", + f64: -17.17, + i64: -1717, + }, + { + name: "f64:18.18", + f64: -18.18, + i64: -1818, + }, + { + name: "f64:19.19", + f64: -19.19, + i64: -1919, + }, + { + name: "f64:20.20", + f64: -20.20, + i64: -2020, + }, + { + name: "f64:21.21", + f64: -21.21, + i64: -2121, + }, + { + name: "f64:22.22", + f64: -22.22, + i64: -2222, + }, + { + name: "f64:23.23", + f64: -23.23, + i64: -2323, + }, + { + name: "f64:24.24", + f64: -24.24, + i64: -2424, + }, + { + name: "f64:25.25", + f64: -25.25, + i64: -2525, + }, + { + name: "f64:26.26", + f64: -26.26, + i64: -2626, + }, + { + name: "f64:27.27", + f64: -27.27, + i64: -2727, + }, + { + name: "f64:28.28", + f64: -28.28, + i64: -2828, + }, + { + name: "f64:29.29", + f64: -29.29, + i64: -2929, + }, + { + name: "f64:30.30", + f64: -30.30, + i64: -3030, + }, + { + name: "f64:31.31", + f64: -31.31, + i64: -3131, + }, + { + name: "f64:32.32", + f64: -32.32, + i64: -3232, + }, + { + name: "f64:33.33", + f64: -33.33, + i64: -3333, + }, + { + name: "f64:34.34", + f64: -34.34, + i64: -3434, + }, + { + name: "f64:35.35", + f64: -35.35, + i64: -3535, + }, + { + name: "f64:36.36", + f64: -36.36, + i64: -3636, + }, + { + name: "f64:37.37", + f64: -37.37, + i64: -3737, + }, + { + name: "f64:38.38", + f64: -38.38, + i64: -3838, + }, + { + name: "f64:39.39", + f64: -39.39, + i64: -3939, + }, + { + name: "f64:40.40", + f64: -40.40, + i64: -4040, + }, + { + name: "f64:41.41", + f64: -41.41, + i64: -4141, + }, + { + name: "f64:42.42", + f64: -42.42, + i64: -4242, + }, + { + name: "f64:43.43", + f64: -43.43, + i64: -4343, + }, + { + name: "f64:44.44", + f64: -44.44, + i64: -4444, + }, + { + name: "f64:45.45", + f64: -45.45, + i64: -4545, + }, + { + name: "f64:46.46", + f64: -46.46, + i64: -4646, + }, + { + name: "f64:47.47", + f64: -47.47, + i64: -4747, + }, + { + name: "f64:48.48", + f64: -48.48, + i64: -4848, + }, + { + name: "f64:49.49", + f64: -49.49, + i64: -4949, + }, + { + name: "f64:50.50", + f64: -50.50, + i64: -5050, + }, + { + name: "f64:51.51", + f64: -51.51, + i64: -5151, + }, + { + name: "f64:52.52", + f64: -52.52, + i64: -5252, + }, + { + name: "f64:53.53", + f64: -53.53, + i64: -5353, + }, + { + name: "f64:54.54", + f64: -54.54, + i64: -5454, + }, + { + name: "f64:55.55", + f64: -55.55, + i64: -5555, + }, + { + name: "f64:56.56", + f64: -56.56, + i64: -5656, + }, + { + name: "f64:57.57", + f64: -57.57, + i64: -5757, + }, + { + name: "f64:58.58", + f64: -58.58, + i64: -5858, + }, + { + name: "f64:59.59", + f64: -59.59, + i64: -5959, + }, + { + name: "f64:60.60", + f64: -60.60, + i64: -6060, + }, + { + name: "f64:61.61", + f64: -61.61, + i64: -6161, + }, + { + name: "f64:62.62", + f64: -62.62, + i64: -6262, + }, + { + name: "f64:63.63", + f64: -63.63, + i64: -6363, + }, + { + name: "f64:64.64", + f64: -64.64, + i64: -6464, + }, + { + name: "f64:65.65", + f64: -65.65, + i64: -6565, + }, + { + name: "f64:66.66", + f64: -66.66, + i64: -6666, + }, + { + name: "f64:67.67", + f64: -67.67, + i64: -6767, + }, + { + name: "f64:68.68", + f64: -68.68, + i64: -6868, + }, + { + name: "f64:69.69", + f64: -69.69, + i64: -6969, + }, + { + name: "f64:70.70", + f64: -70.70, + i64: -7070, + }, + { + name: "f64:71.71", + f64: -71.71, + i64: -7171, + }, + { + name: "f64:72.72", + f64: -72.72, + i64: -7272, + }, + { + name: "f64:73.73", + f64: -73.73, + i64: -7373, + }, + { + name: "f64:74.74", + f64: -74.74, + i64: -7474, + }, + { + name: "f64:75.75", + f64: -75.75, + i64: -7575, + }, + { + name: "f64:76.76", + f64: -76.76, + i64: -7676, + }, + { + name: "f64:77.77", + f64: -77.77, + i64: -7777, + }, + { + name: "f64:78.78", + f64: -78.78, + i64: -7878, + }, + { + name: "f64:79.79", + f64: -79.79, + i64: -7979, + }, + { + name: "f64:80.80", + f64: -80.80, + i64: -8080, + }, + { + name: "f64:81.81", + f64: -81.81, + i64: -8181, + }, + { + name: "f64:82.82", + f64: -82.82, + i64: -8282, + }, + { + name: "f64:83.83", + f64: -83.83, + i64: -8383, + }, + { + name: "f64:84.84", + f64: -84.84, + i64: -8484, + }, + { + name: "f64:85.85", + f64: -85.85, + i64: -8585, + }, + { + name: "f64:86.86", + f64: -86.86, + i64: -8686, + }, + { + name: "f64:87.87", + f64: -87.87, + i64: -8787, + }, + { + name: "f64:88.88", + f64: -88.88, + i64: -8888, + }, + { + name: "f64:89.89", + f64: -89.89, + i64: -8989, + }, + { + name: "f64:90.90", + f64: -90.90, + i64: -9090, + }, + { + name: "f64:91.91", + f64: -91.91, + i64: -9191, + }, + { + name: "f64:92.92", + f64: -92.92, + i64: -9292, + }, + { + name: "f64:93.93", + f64: -93.93, + i64: -9393, + }, + { + name: "f64:94.94", + f64: -94.94, + i64: -9494, + }, + { + name: "f64:95.95", + f64: -95.95, + i64: -9595, + }, + { + name: "f64:96.96", + f64: -96.96, + i64: -9696, + }, + { + name: "f64:97.97", + f64: -97.97, + i64: -9797, + }, + { + name: "f64:98.98", + f64: -98.98, + i64: -9898, + }, + { + name: "f64:99.99", + f64: -99.99, + i64: -9999, + }, + { + name: "f64:100.105", + f64: -100.10, + i64: -10010, + }, +} + +//go:noinline +func useInt64(i int64) {} + +//go:noinline +func useError(e error) {} diff --git a/v2/accounting/errors.go b/v2/accounting/errors.go new file mode 100644 index 0000000..771bb76 --- /dev/null +++ b/v2/accounting/errors.go @@ -0,0 +1,27 @@ +package accounting + +import ( + "errors" + "fmt" +) + +var ( + // ErrSubZeroRate happens when a rate is lower than zero. + ErrSubZeroRate = errors.New("rate must not be less than zero") + // ErrSubZeroGross happens when the gross amount is less than zero. + ErrSubZeroGross = errors.New("gross amount must not be less than zero") + // ErrSubZeroNet happens when the net amount is less than zero. + ErrSubZeroNet = errors.New("net amount must not be less than zero") + // ErrNetOverGrossAmount happens when the net amount is higher than the gross amount. + ErrNetOverGrossAmount = errors.New("net amount must be equal to or lower than the gross amount") +) + +// ErrFloatPrecision happens when a floating point number is not following business precision rules. +type ErrFloatPrecision struct { + Value string + Precision int +} + +func (e ErrFloatPrecision) Error() string { + return fmt.Sprintf("incorrect value %s with precision %d", e.Value, e.Precision) +} diff --git a/v2/accounting/floats.go b/v2/accounting/floats.go new file mode 100644 index 0000000..b9a9821 --- /dev/null +++ b/v2/accounting/floats.go @@ -0,0 +1,22 @@ +package accounting + +import "math/big" + +func newf() *big.Float { + f := new(big.Float) + f.SetPrec(QuadruplePrecision) + f.SetMode(big.ToNearestEven) + return f +} + +func itof(v int64) *big.Float { + f := newf() + f.SetInt64(v) + return f +} + +func ftof(v float64) *big.Float { + f := newf() + f.SetFloat64(v) + return f +} diff --git a/v2/cmd/js.txt b/v2/cmd/js.txt new file mode 100644 index 0000000..fc2295c --- /dev/null +++ b/v2/cmd/js.txt @@ -0,0 +1,7 @@ +var stdCurrency = { + {{- $n := len . }} + {{ range $k, $v := . -}} + // {{$v.Code}} currency object + {{$v.Code}}: { code: "{{$v.Code}}", name: "{{$v.Name}}", minorUnits: {{$v.Units}}, factor: {{$v.Factor}}, name: "{{$v.Name}}"}{{if eq (inc $k) $n}}{{else}}{{if $k}},{{end}}{{if eq $k 0}},{{end}}{{end}} + {{ end -}} +}; diff --git a/v2/cmd/kotlin.txt b/v2/cmd/kotlin.txt new file mode 100644 index 0000000..b7b618a --- /dev/null +++ b/v2/cmd/kotlin.txt @@ -0,0 +1,10 @@ +data class Currency(val currencyCode: String, val minorUnits: Int, val factor: Int, val name: String) { + companion object { + val currencyMap = mapOf( + {{- $n := len . }} + {{ range $k, $v := . -}} + "{{$v.Code}}" to Currency("{{$v.Code}}", {{$v.Units}}, {{$v.Factor}}, "{{$v.Name}}"){{if eq (inc $k) $n}}{{else}}{{if $k}},{{end}}{{if eq $k 0}},{{end}}{{end}} + {{ end -}} + ) + } +} diff --git a/v2/cmd/list_one.xml b/v2/cmd/list_one.xml new file mode 100644 index 0000000..d1b87d5 --- /dev/null +++ b/v2/cmd/list_one.xml @@ -0,0 +1,1956 @@ + + + + + AFGHANISTAN + Afghani + AFN + 971 + 2 + + + ÅLAND ISLANDS + Euro + EUR + 978 + 2 + + + ALBANIA + Lek + ALL + 008 + 2 + + + ALGERIA + Algerian Dinar + DZD + 012 + 2 + + + AMERICAN SAMOA + US Dollar + USD + 840 + 2 + + + ANDORRA + Euro + EUR + 978 + 2 + + + ANGOLA + Kwanza + AOA + 973 + 2 + + + ANGUILLA + East Caribbean Dollar + XCD + 951 + 2 + + + ANTARCTICA + No universal currency + + + ANTIGUA AND BARBUDA + East Caribbean Dollar + XCD + 951 + 2 + + + ARGENTINA + Argentine Peso + ARS + 032 + 2 + + + ARMENIA + Armenian Dram + AMD + 051 + 2 + + + ARUBA + Aruban Florin + AWG + 533 + 2 + + + AUSTRALIA + Australian Dollar + AUD + 036 + 2 + + + AUSTRIA + Euro + EUR + 978 + 2 + + + AZERBAIJAN + Azerbaijan Manat + AZN + 944 + 2 + + + BAHAMAS (THE) + Bahamian Dollar + BSD + 044 + 2 + + + BAHRAIN + Bahraini Dinar + BHD + 048 + 3 + + + BANGLADESH + Taka + BDT + 050 + 2 + + + BARBADOS + Barbados Dollar + BBD + 052 + 2 + + + BELARUS + Belarusian Ruble + BYN + 933 + 2 + + + BELGIUM + Euro + EUR + 978 + 2 + + + BELIZE + Belize Dollar + BZD + 084 + 2 + + + BENIN + CFA Franc BCEAO + XOF + 952 + 0 + + + BERMUDA + Bermudian Dollar + BMD + 060 + 2 + + + BHUTAN + Indian Rupee + INR + 356 + 2 + + + BHUTAN + Ngultrum + BTN + 064 + 2 + + + BOLIVIA (PLURINATIONAL STATE OF) + Boliviano + BOB + 068 + 2 + + + BOLIVIA (PLURINATIONAL STATE OF) + Mvdol + BOV + 984 + 2 + + + BONAIRE, SINT EUSTATIUS AND SABA + US Dollar + USD + 840 + 2 + + + BOSNIA AND HERZEGOVINA + Convertible Mark + BAM + 977 + 2 + + + BOTSWANA + Pula + BWP + 072 + 2 + + + BOUVET ISLAND + Norwegian Krone + NOK + 578 + 2 + + + BRAZIL + Brazilian Real + BRL + 986 + 2 + + + BRITISH INDIAN OCEAN TERRITORY (THE) + US Dollar + USD + 840 + 2 + + + BRUNEI DARUSSALAM + Brunei Dollar + BND + 096 + 2 + + + BULGARIA + Bulgarian Lev + BGN + 975 + 2 + + + BURKINA FASO + CFA Franc BCEAO + XOF + 952 + 0 + + + BURUNDI + Burundi Franc + BIF + 108 + 0 + + + CABO VERDE + Cabo Verde Escudo + CVE + 132 + 2 + + + CAMBODIA + Riel + KHR + 116 + 2 + + + CAMEROON + CFA Franc BEAC + XAF + 950 + 0 + + + CANADA + Canadian Dollar + CAD + 124 + 2 + + + CAYMAN ISLANDS (THE) + Cayman Islands Dollar + KYD + 136 + 2 + + + CENTRAL AFRICAN REPUBLIC (THE) + CFA Franc BEAC + XAF + 950 + 0 + + + CHAD + CFA Franc BEAC + XAF + 950 + 0 + + + CHILE + Chilean Peso + CLP + 152 + 0 + + + CHILE + Unidad de Fomento + CLF + 990 + 4 + + + CHINA + Yuan Renminbi + CNY + 156 + 2 + + + CHRISTMAS ISLAND + Australian Dollar + AUD + 036 + 2 + + + COCOS (KEELING) ISLANDS (THE) + Australian Dollar + AUD + 036 + 2 + + + COLOMBIA + Colombian Peso + COP + 170 + 2 + + + COLOMBIA + Unidad de Valor Real + COU + 970 + 2 + + + COMOROS (THE) + Comorian Franc + KMF + 174 + 0 + + + CONGO (THE DEMOCRATIC REPUBLIC OF THE) + Congolese Franc + CDF + 976 + 2 + + + CONGO (THE) + CFA Franc BEAC + XAF + 950 + 0 + + + COOK ISLANDS (THE) + New Zealand Dollar + NZD + 554 + 2 + + + COSTA RICA + Costa Rican Colon + CRC + 188 + 2 + + + CÔTE D'IVOIRE + CFA Franc BCEAO + XOF + 952 + 0 + + + CROATIA + Euro + EUR + 978 + 2 + + + CUBA + Cuban Peso + CUP + 192 + 2 + + + CUBA + Peso Convertible + CUC + 931 + 2 + + + CURAÇAO + Netherlands Antillean Guilder + ANG + 532 + 2 + + + CYPRUS + Euro + EUR + 978 + 2 + + + CZECHIA + Czech Koruna + CZK + 203 + 2 + + + DENMARK + Danish Krone + DKK + 208 + 2 + + + DJIBOUTI + Djibouti Franc + DJF + 262 + 0 + + + DOMINICA + East Caribbean Dollar + XCD + 951 + 2 + + + DOMINICAN REPUBLIC (THE) + Dominican Peso + DOP + 214 + 2 + + + ECUADOR + US Dollar + USD + 840 + 2 + + + EGYPT + Egyptian Pound + EGP + 818 + 2 + + + EL SALVADOR + El Salvador Colon + SVC + 222 + 2 + + + EL SALVADOR + US Dollar + USD + 840 + 2 + + + EQUATORIAL GUINEA + CFA Franc BEAC + XAF + 950 + 0 + + + ERITREA + Nakfa + ERN + 232 + 2 + + + ESTONIA + Euro + EUR + 978 + 2 + + + ESWATINI + Lilangeni + SZL + 748 + 2 + + + ETHIOPIA + Ethiopian Birr + ETB + 230 + 2 + + + EUROPEAN UNION + Euro + EUR + 978 + 2 + + + FALKLAND ISLANDS (THE) [MALVINAS] + Falkland Islands Pound + FKP + 238 + 2 + + + FAROE ISLANDS (THE) + Danish Krone + DKK + 208 + 2 + + + FIJI + Fiji Dollar + FJD + 242 + 2 + + + FINLAND + Euro + EUR + 978 + 2 + + + FRANCE + Euro + EUR + 978 + 2 + + + FRENCH GUIANA + Euro + EUR + 978 + 2 + + + FRENCH POLYNESIA + CFP Franc + XPF + 953 + 0 + + + FRENCH SOUTHERN TERRITORIES (THE) + Euro + EUR + 978 + 2 + + + GABON + CFA Franc BEAC + XAF + 950 + 0 + + + GAMBIA (THE) + Dalasi + GMD + 270 + 2 + + + GEORGIA + Lari + GEL + 981 + 2 + + + GERMANY + Euro + EUR + 978 + 2 + + + GHANA + Ghana Cedi + GHS + 936 + 2 + + + GIBRALTAR + Gibraltar Pound + GIP + 292 + 2 + + + GREECE + Euro + EUR + 978 + 2 + + + GREENLAND + Danish Krone + DKK + 208 + 2 + + + GRENADA + East Caribbean Dollar + XCD + 951 + 2 + + + GUADELOUPE + Euro + EUR + 978 + 2 + + + GUAM + US Dollar + USD + 840 + 2 + + + GUATEMALA + Quetzal + GTQ + 320 + 2 + + + GUERNSEY + Pound Sterling + GBP + 826 + 2 + + + GUINEA + Guinean Franc + GNF + 324 + 0 + + + GUINEA-BISSAU + CFA Franc BCEAO + XOF + 952 + 0 + + + GUYANA + Guyana Dollar + GYD + 328 + 2 + + + HAITI + Gourde + HTG + 332 + 2 + + + HAITI + US Dollar + USD + 840 + 2 + + + HEARD ISLAND AND McDONALD ISLANDS + Australian Dollar + AUD + 036 + 2 + + + HOLY SEE (THE) + Euro + EUR + 978 + 2 + + + HONDURAS + Lempira + HNL + 340 + 2 + + + HONG KONG + Hong Kong Dollar + HKD + 344 + 2 + + + HUNGARY + Forint + HUF + 348 + 2 + + + ICELAND + Iceland Krona + ISK + 352 + 0 + + + INDIA + Indian Rupee + INR + 356 + 2 + + + INDONESIA + Rupiah + IDR + 360 + 2 + + + INTERNATIONAL MONETARY FUND (IMF)  + SDR (Special Drawing Right) + XDR + 960 + N.A. + + + IRAN (ISLAMIC REPUBLIC OF) + Iranian Rial + IRR + 364 + 2 + + + IRAQ + Iraqi Dinar + IQD + 368 + 3 + + + IRELAND + Euro + EUR + 978 + 2 + + + ISLE OF MAN + Pound Sterling + GBP + 826 + 2 + + + ISRAEL + New Israeli Sheqel + ILS + 376 + 2 + + + ITALY + Euro + EUR + 978 + 2 + + + JAMAICA + Jamaican Dollar + JMD + 388 + 2 + + + JAPAN + Yen + JPY + 392 + 0 + + + JERSEY + Pound Sterling + GBP + 826 + 2 + + + JORDAN + Jordanian Dinar + JOD + 400 + 3 + + + KAZAKHSTAN + Tenge + KZT + 398 + 2 + + + KENYA + Kenyan Shilling + KES + 404 + 2 + + + KIRIBATI + Australian Dollar + AUD + 036 + 2 + + + KOREA (THE DEMOCRATIC PEOPLE’S REPUBLIC OF) + North Korean Won + KPW + 408 + 2 + + + KOREA (THE REPUBLIC OF) + Won + KRW + 410 + 0 + + + KUWAIT + Kuwaiti Dinar + KWD + 414 + 3 + + + KYRGYZSTAN + Som + KGS + 417 + 2 + + + LAO PEOPLE’S DEMOCRATIC REPUBLIC (THE) + Lao Kip + LAK + 418 + 2 + + + LATVIA + Euro + EUR + 978 + 2 + + + LEBANON + Lebanese Pound + LBP + 422 + 2 + + + LESOTHO + Loti + LSL + 426 + 2 + + + LESOTHO + Rand + ZAR + 710 + 2 + + + LIBERIA + Liberian Dollar + LRD + 430 + 2 + + + LIBYA + Libyan Dinar + LYD + 434 + 3 + + + LIECHTENSTEIN + Swiss Franc + CHF + 756 + 2 + + + LITHUANIA + Euro + EUR + 978 + 2 + + + LUXEMBOURG + Euro + EUR + 978 + 2 + + + MACAO + Pataca + MOP + 446 + 2 + + + NORTH MACEDONIA + Denar + MKD + 807 + 2 + + + MADAGASCAR + Malagasy Ariary + MGA + 969 + 2 + + + MALAWI + Malawi Kwacha + MWK + 454 + 2 + + + MALAYSIA + Malaysian Ringgit + MYR + 458 + 2 + + + MALDIVES + Rufiyaa + MVR + 462 + 2 + + + MALI + CFA Franc BCEAO + XOF + 952 + 0 + + + MALTA + Euro + EUR + 978 + 2 + + + MARSHALL ISLANDS (THE) + US Dollar + USD + 840 + 2 + + + MARTINIQUE + Euro + EUR + 978 + 2 + + + MAURITANIA + Ouguiya + MRU + 929 + 2 + + + MAURITIUS + Mauritius Rupee + MUR + 480 + 2 + + + MAYOTTE + Euro + EUR + 978 + 2 + + + MEMBER COUNTRIES OF THE AFRICAN DEVELOPMENT BANK GROUP + ADB Unit of Account + XUA + 965 + N.A. + + + MEXICO + Mexican Peso + MXN + 484 + 2 + + + MEXICO + Mexican Unidad de Inversion (UDI) + MXV + 979 + 2 + + + MICRONESIA (FEDERATED STATES OF) + US Dollar + USD + 840 + 2 + + + MOLDOVA (THE REPUBLIC OF) + Moldovan Leu + MDL + 498 + 2 + + + MONACO + Euro + EUR + 978 + 2 + + + MONGOLIA + Tugrik + MNT + 496 + 2 + + + MONTENEGRO + Euro + EUR + 978 + 2 + + + MONTSERRAT + East Caribbean Dollar + XCD + 951 + 2 + + + MOROCCO + Moroccan Dirham + MAD + 504 + 2 + + + MOZAMBIQUE + Mozambique Metical + MZN + 943 + 2 + + + MYANMAR + Kyat + MMK + 104 + 2 + + + NAMIBIA + Namibia Dollar + NAD + 516 + 2 + + + NAMIBIA + Rand + ZAR + 710 + 2 + + + NAURU + Australian Dollar + AUD + 036 + 2 + + + NEPAL + Nepalese Rupee + NPR + 524 + 2 + + + NETHERLANDS (THE) + Euro + EUR + 978 + 2 + + + NEW CALEDONIA + CFP Franc + XPF + 953 + 0 + + + NEW ZEALAND + New Zealand Dollar + NZD + 554 + 2 + + + NICARAGUA + Cordoba Oro + NIO + 558 + 2 + + + NIGER (THE) + CFA Franc BCEAO + XOF + 952 + 0 + + + NIGERIA + Naira + NGN + 566 + 2 + + + NIUE + New Zealand Dollar + NZD + 554 + 2 + + + NORFOLK ISLAND + Australian Dollar + AUD + 036 + 2 + + + NORTHERN MARIANA ISLANDS (THE) + US Dollar + USD + 840 + 2 + + + NORWAY + Norwegian Krone + NOK + 578 + 2 + + + OMAN + Rial Omani + OMR + 512 + 3 + + + PAKISTAN + Pakistan Rupee + PKR + 586 + 2 + + + PALAU + US Dollar + USD + 840 + 2 + + + PALESTINE, STATE OF + No universal currency + + + PANAMA + Balboa + PAB + 590 + 2 + + + PANAMA + US Dollar + USD + 840 + 2 + + + PAPUA NEW GUINEA + Kina + PGK + 598 + 2 + + + PARAGUAY + Guarani + PYG + 600 + 0 + + + PERU + Sol + PEN + 604 + 2 + + + PHILIPPINES (THE) + Philippine Peso + PHP + 608 + 2 + + + PITCAIRN + New Zealand Dollar + NZD + 554 + 2 + + + POLAND + Zloty + PLN + 985 + 2 + + + PORTUGAL + Euro + EUR + 978 + 2 + + + PUERTO RICO + US Dollar + USD + 840 + 2 + + + QATAR + Qatari Rial + QAR + 634 + 2 + + + RÉUNION + Euro + EUR + 978 + 2 + + + ROMANIA + Romanian Leu + RON + 946 + 2 + + + RUSSIAN FEDERATION (THE) + Russian Ruble + RUB + 643 + 2 + + + RWANDA + Rwanda Franc + RWF + 646 + 0 + + + SAINT BARTHÉLEMY + Euro + EUR + 978 + 2 + + + SAINT HELENA, ASCENSION AND TRISTAN DA CUNHA + Saint Helena Pound + SHP + 654 + 2 + + + SAINT KITTS AND NEVIS + East Caribbean Dollar + XCD + 951 + 2 + + + SAINT LUCIA + East Caribbean Dollar + XCD + 951 + 2 + + + SAINT MARTIN (FRENCH PART) + Euro + EUR + 978 + 2 + + + SAINT PIERRE AND MIQUELON + Euro + EUR + 978 + 2 + + + SAINT VINCENT AND THE GRENADINES + East Caribbean Dollar + XCD + 951 + 2 + + + SAMOA + Tala + WST + 882 + 2 + + + SAN MARINO + Euro + EUR + 978 + 2 + + + SAO TOME AND PRINCIPE + Dobra + STN + 930 + 2 + + + SAUDI ARABIA + Saudi Riyal + SAR + 682 + 2 + + + SENEGAL + CFA Franc BCEAO + XOF + 952 + 0 + + + SERBIA + Serbian Dinar + RSD + 941 + 2 + + + SEYCHELLES + Seychelles Rupee + SCR + 690 + 2 + + + SIERRA LEONE + Leone + SLE + 925 + 2 + + + SINGAPORE + Singapore Dollar + SGD + 702 + 2 + + + SINT MAARTEN (DUTCH PART) + Netherlands Antillean Guilder + ANG + 532 + 2 + + + SISTEMA UNITARIO DE COMPENSACION REGIONAL DE PAGOS "SUCRE" + Sucre + XSU + 994 + N.A. + + + SLOVAKIA + Euro + EUR + 978 + 2 + + + SLOVENIA + Euro + EUR + 978 + 2 + + + SOLOMON ISLANDS + Solomon Islands Dollar + SBD + 090 + 2 + + + SOMALIA + Somali Shilling + SOS + 706 + 2 + + + SOUTH AFRICA + Rand + ZAR + 710 + 2 + + + SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS + No universal currency + + + SOUTH SUDAN + South Sudanese Pound + SSP + 728 + 2 + + + SPAIN + Euro + EUR + 978 + 2 + + + SRI LANKA + Sri Lanka Rupee + LKR + 144 + 2 + + + SUDAN (THE) + Sudanese Pound + SDG + 938 + 2 + + + SURINAME + Surinam Dollar + SRD + 968 + 2 + + + SVALBARD AND JAN MAYEN + Norwegian Krone + NOK + 578 + 2 + + + SWEDEN + Swedish Krona + SEK + 752 + 2 + + + SWITZERLAND + Swiss Franc + CHF + 756 + 2 + + + SWITZERLAND + WIR Euro + CHE + 947 + 2 + + + SWITZERLAND + WIR Franc + CHW + 948 + 2 + + + SYRIAN ARAB REPUBLIC + Syrian Pound + SYP + 760 + 2 + + + TAIWAN (PROVINCE OF CHINA) + New Taiwan Dollar + TWD + 901 + 2 + + + TAJIKISTAN + Somoni + TJS + 972 + 2 + + + TANZANIA, UNITED REPUBLIC OF + Tanzanian Shilling + TZS + 834 + 2 + + + THAILAND + Baht + THB + 764 + 2 + + + TIMOR-LESTE + US Dollar + USD + 840 + 2 + + + TOGO + CFA Franc BCEAO + XOF + 952 + 0 + + + TOKELAU + New Zealand Dollar + NZD + 554 + 2 + + + TONGA + Pa’anga + TOP + 776 + 2 + + + TRINIDAD AND TOBAGO + Trinidad and Tobago Dollar + TTD + 780 + 2 + + + TUNISIA + Tunisian Dinar + TND + 788 + 3 + + + TÜRKİYE + Turkish Lira + TRY + 949 + 2 + + + TURKMENISTAN + Turkmenistan New Manat + TMT + 934 + 2 + + + TURKS AND CAICOS ISLANDS (THE) + US Dollar + USD + 840 + 2 + + + TUVALU + Australian Dollar + AUD + 036 + 2 + + + UGANDA + Uganda Shilling + UGX + 800 + 0 + + + UKRAINE + Hryvnia + UAH + 980 + 2 + + + UNITED ARAB EMIRATES (THE) + UAE Dirham + AED + 784 + 2 + + + UNITED KINGDOM OF GREAT BRITAIN AND NORTHERN IRELAND (THE) + Pound Sterling + GBP + 826 + 2 + + + UNITED STATES MINOR OUTLYING ISLANDS (THE) + US Dollar + USD + 840 + 2 + + + UNITED STATES OF AMERICA (THE) + US Dollar + USD + 840 + 2 + + + UNITED STATES OF AMERICA (THE) + US Dollar (Next day) + USN + 997 + 2 + + + URUGUAY + Peso Uruguayo + UYU + 858 + 2 + + + URUGUAY + Uruguay Peso en Unidades Indexadas (UI) + UYI + 940 + 0 + + + URUGUAY + Unidad Previsional + UYW + 927 + 4 + + + UZBEKISTAN + Uzbekistan Sum + UZS + 860 + 2 + + + VANUATU + Vatu + VUV + 548 + 0 + + + VENEZUELA (BOLIVARIAN REPUBLIC OF) + Bolívar Soberano + VES + 928 + 2 + + + VENEZUELA (BOLIVARIAN REPUBLIC OF) + Bolívar Soberano + VED + 926 + 2 + + + VIET NAM + Dong + VND + 704 + 0 + + + VIRGIN ISLANDS (BRITISH) + US Dollar + USD + 840 + 2 + + + VIRGIN ISLANDS (U.S.) + US Dollar + USD + 840 + 2 + + + WALLIS AND FUTUNA + CFP Franc + XPF + 953 + 0 + + + WESTERN SAHARA + Moroccan Dirham + MAD + 504 + 2 + + + YEMEN + Yemeni Rial + YER + 886 + 2 + + + ZAMBIA + Zambian Kwacha + ZMW + 967 + 2 + + + ZIMBABWE + Zimbabwe Gold + ZWG + 924 + 2 + + + ZZ01_Bond Markets Unit European_EURCO + Bond Markets Unit European Composite Unit (EURCO) + XBA + 955 + N.A. + + + ZZ02_Bond Markets Unit European_EMU-6 + Bond Markets Unit European Monetary Unit (E.M.U.-6) + XBB + 956 + N.A. + + + ZZ03_Bond Markets Unit European_EUA-9 + Bond Markets Unit European Unit of Account 9 (E.U.A.-9) + XBC + 957 + N.A. + + + ZZ04_Bond Markets Unit European_EUA-17 + Bond Markets Unit European Unit of Account 17 (E.U.A.-17) + XBD + 958 + N.A. + + + ZZ06_Testing_Code + Codes specifically reserved for testing purposes + XTS + 963 + N.A. + + + ZZ07_No_Currency + The codes assigned for transactions where no currency is involved + XXX + 999 + N.A. + + + ZZ08_Gold + Gold + XAU + 959 + N.A. + + + ZZ09_Palladium + Palladium + XPD + 964 + N.A. + + + ZZ10_Platinum + Platinum + XPT + 962 + N.A. + + + ZZ11_Silver + Silver + XAG + 961 + N.A. + + + \ No newline at end of file diff --git a/v2/cmd/main.go b/v2/cmd/main.go new file mode 100644 index 0000000..d3f06f9 --- /dev/null +++ b/v2/cmd/main.go @@ -0,0 +1,247 @@ +package main + +import ( + "bytes" + "encoding/xml" + "fmt" + "go/format" + "io" + "io/ioutil" + "log" + "net/http" + "os" + "sort" + "strconv" + "strings" + "text/template" + + "github.com/ladydascalie/currency/v2/cmd/scaffold" +) + +const ( + templateFile = "cmd/std.txt" // must include the cmd prefix because this code is called from the Makefile + outputFile = "std.go" // we want this to output in the top directory + + // For the source on this, please check: + // - International Organization for Standardization: https://www.iso.org/iso-4217-currency-codes.html + // - Currency Code Services – ISO 4217 Maintenance Agency: https://www.currency-iso.org + isoStdDownload = "https://www.six-group.com/dam/download/financial-information/data-center/iso-currrency/lists/list-one.xml" +) + +func main() { + log.SetFlags(log.Lshortfile | log.LstdFlags) + + err, iso := getLatestISO4217() + if err != nil { + log.Fatalf("could not get latest iso: %v", err) + } + + currencies := buildCurrencyList(iso) + if len(currencies) == 0 { + log.Fatalf("could not build currency list") + } + + for _, gen := range generators { + gen(currencies) + } +} + +func getLatestISO4217() (err error, iso scaffold.ISO4217) { + res, err := http.Get(isoStdDownload) + if err != nil { + log.Fatal(err) + } + b, err := ioutil.ReadAll(res.Body) + if err != nil { + log.Fatal(err) + } + defer res.Body.Close() + + if err = xml.Unmarshal(b, &iso); err != nil { + log.Fatal(err) + } + return err, iso +} + +type currency struct { + Code string + Units int + Factor string + Name string +} + +func buildCurrencyList(iso scaffold.ISO4217) []currency { + var currencies []currency + for _, entry := range iso.Table.Entries { + if entry.Code == "" { + continue + } + + var ( + unit int + err error + ) + unit, err = strconv.Atoi(entry.MinorUnits) + if err != nil { + // nothing really + // it's always because of "N.A." + // But just in case... + if entry.MinorUnits != "N.A." { + log.Fatalln(err) + } + } + if func() bool { + for _, cur := range currencies { + if cur.Code == entry.Code { + return true + } + } + return false + }() { + continue + } + + currencies = append(currencies, currency{ + Code: entry.Code, + Units: unit, + Factor: fmt.Sprintf("1%s", strings.Repeat("0", unit)), + Name: entry.Description, + }) + } + sort.Slice(currencies, func(i, j int) bool { + return currencies[i].Code < currencies[j].Code + }) + return currencies +} + +type generatorFunc func(currencies []currency) + +var generators = []generatorFunc{ + generateGoPackage, + generateSwiftPackage, + generateJavascriptPackage, + generateKotlinPackage, +} + +var fns = template.FuncMap{ + "inc": func(x int) int { + return x + 1 + }, +} + +func generateJavascriptPackage(currencies []currency) { + const ( + infile = "cmd/js.txt" + outfile = "std_currency.js" + ) + tpl, err := ioutil.ReadFile(infile) + if err != nil { + log.Fatalf("cannot open template file: %v", err) + } + + t := template.Must(template.New("js").Funcs(fns).Parse(string(tpl))) + buf := new(bytes.Buffer) + err = t.Execute(buf, currencies) + if err != nil { + log.Fatal(err) + } + + to, err := os.Create(outfile) + if err != nil { + log.Fatal(err) + } + defer to.Close() + + _, err = io.Copy(to, buf) + if err != nil { + log.Fatal(err) + } +} + +func generateKotlinPackage(currencies []currency) { + const ( + infile = "cmd/kotlin.txt" + outfile = "std.kt" + ) + tpl, err := ioutil.ReadFile(infile) + if err != nil { + log.Fatalf("cannot open template file: %v", err) + } + + t := template.Must(template.New("kotlin").Funcs(fns).Parse(string(tpl))) + buf := new(bytes.Buffer) + err = t.Execute(buf, currencies) + if err != nil { + log.Fatal(err) + } + + to, err := os.Create(outfile) + if err != nil { + log.Fatal(err) + } + defer to.Close() + + _, err = io.Copy(to, buf) + if err != nil { + log.Fatal(err) + } +} + +func generateSwiftPackage(currencies []currency) { + const ( + infile = "cmd/swift.txt" + outfile = "std.swift" + ) + tpl, err := ioutil.ReadFile(infile) + if err != nil { + log.Fatalf("cannot open template file: %v", err) + } + + t := template.Must(template.New("swift").Funcs(fns).Parse(string(tpl))) + buf := new(bytes.Buffer) + err = t.Execute(buf, currencies) + if err != nil { + log.Fatal(err) + } + + to, err := os.Create(outfile) + if err != nil { + log.Fatal(err) + } + defer to.Close() + + _, err = io.Copy(to, buf) + if err != nil { + log.Fatal(err) + } +} + +func generateGoPackage(currencies []currency) { + tpl, err := ioutil.ReadFile(templateFile) + if err != nil { + log.Fatalf("cannot open template file: %v", err) + } + + t := template.Must(template.New("go").Parse(string(tpl))) + buf := new(bytes.Buffer) + err = t.Execute(buf, currencies) + if err != nil { + log.Fatal(err) + } + + formatted, err := format.Source(buf.Bytes()) + if err != nil { + log.Fatal(err) + } + buf = bytes.NewBuffer(formatted) + to, err := os.Create(outputFile) + if err != nil { + log.Fatal(err) + } + defer to.Close() + + _, err = io.Copy(to, buf) + if err != nil { + log.Fatal(err) + } +} diff --git a/v2/cmd/scaffold/list.go b/v2/cmd/scaffold/list.go new file mode 100644 index 0000000..7dd1d5f --- /dev/null +++ b/v2/cmd/scaffold/list.go @@ -0,0 +1,17 @@ +package scaffold + +type Entry struct { + Code string `xml:"Ccy,omitempty" json:"AlphanumericCode,omitempty"` + MinorUnits string `xml:"CcyMnrUnts,omitempty" json:"MinorUnits,omitempty"` + Country string `xml:"CtryNm,omitempty" json:"CountryName,omitempty"` + Description string `xml:"CcyNm,omitempty" json:"CurrencyName,omitempty"` +} + +type Table struct { + Entries []*Entry `xml:"CcyNtry,omitempty" json:"Entries,omitempty"` +} + +type ISO4217 struct { + AttrPublished string `xml:"Pblshd,attr" json:",omitempty"` // maxLength=10 + Table *Table `xml:"CcyTbl,omitempty" json:"Table,omitempty"` +} diff --git a/v2/cmd/std.txt b/v2/cmd/std.txt new file mode 100644 index 0000000..6760546 --- /dev/null +++ b/v2/cmd/std.txt @@ -0,0 +1,85 @@ +package currency + +/*-------------------------------+ +| Code generated by std_currency | +| DO NOT EDIT | ++-------------------------------*/ + +import "fmt" + +// Currency defines a currency containing +// It's code, taken from the constants above +// as well as it's minor units, as an integer. +type Currency struct { + code string + minorUnits int + factor int + name string +} + +// Code returns the currency code to the user +func (c *Currency) Code() string { return c.code } + +// MinorUnits returns the minor unit to the user +func (c *Currency) MinorUnits() int { return c.minorUnits } + +// Name returns the currency name as defined in the ISO. +func (c *Currency) Name() string { return c.name } + +// Factor returns the factor by which a float should be multiplied +// to get back to it's smallest denomination +// +// Example: +// pence := 100.00 * currency.GBP.Factor() +func (c *Currency) Factor() int { return c.factor } + +// FactorI64 returns the factor, converted to a int64 +func (c *Currency) FactorI64() int64 { return int64(c.factor) } + +// FactorF64 returns the factor, converted to a float64 +func (c *Currency) FactorF64() float64 { return float64(c.factor) } + +// Get returns a currency struct if the provided +// code is contained within the valid codes. Otherwise +// an error will be returned +func Get(code string) (*Currency, error) { + if Valid(code) { + val, ok := currencies[code] + if ok { + return &val, nil + } + } + return nil, fmt.Errorf("currency: could not find currency with code: %q", code) +} + +// Valid checks if a provided code is contained +// inside the provided ValidCodes slice +func Valid(code string) bool { + for _, c := range ValidCodes { + if c == code { + return true + } + } + return false +} + +// Following are all the structs containing currency data +var ( + {{ range $k, $v := . -}} + // {{$v.Code}} currency struct + {{$v.Code}} = Currency{ code: "{{$v.Code}}", minorUnits: {{$v.Units}}, factor: {{$v.Factor}}, name: "{{$v.Name}}"} + {{ end }} +) + +var currencies = map[string]Currency{ + {{ range $k, $v := . -}} + "{{$v.Code}}": {{$v.Code}}, + {{ end }} +} + +// ValidCodes is provided so that you may build your own validation against it +var ValidCodes = []string{ + {{ range $k, $v := . -}} + "{{$v.Code}}", + {{ end }} +} diff --git a/v2/cmd/swift.txt b/v2/cmd/swift.txt new file mode 100644 index 0000000..4281a81 --- /dev/null +++ b/v2/cmd/swift.txt @@ -0,0 +1,37 @@ +import UIKit + +struct Currency { + /// The `ISO 4217` currency code + var code: String + + /// The number of digits to display after the decimal point when displaying the currency + var minorUnits: Int + + /// The factor to divide the currency figure by before handing to a currency formatter + var factor: Int + + /// The `ISO 4217` currency name + var name: String +} + +class Currencies { + {{ range $k, $v := . -}} + static let {{$v.Code}}: Currency = Currency(code: "{{$v.Code}}", minorUnits: {{$v.Units}}, factor: {{$v.Factor}}, name: "{{$v.Name}}") + {{ end }} + + static let allCurrencies: [String: Currency] = + [ + {{- $n := len . }} + {{ range $k, $v := . -}} + "{{$v.Code}}": {{$v.Code}}{{if eq (inc $k) $n}}{{else}}{{if $k}},{{end}}{{if eq $k 0}},{{end}}{{end}} + {{ end -}} + ] + + /// Look up a currency struct containing currency and formatting information + /// + /// - Parameter code: The `ISO 4217` currency code to search for + /// - Returns: A `Currency` object, if supported. Otherwise nil. + class func currency(for code: String) -> Currency? { + return allCurrencies[code] + } +} diff --git a/v2/go.mod b/v2/go.mod new file mode 100644 index 0000000..e484a1e --- /dev/null +++ b/v2/go.mod @@ -0,0 +1,8 @@ +module github.com/ladydascalie/currency/v2 + +go 1.23 + +require ( + github.com/google/go-cmp v0.6.0 + github.com/google/gofuzz v1.2.0 +) diff --git a/v2/go.sum b/v2/go.sum new file mode 100644 index 0000000..a3f8861 --- /dev/null +++ b/v2/go.sum @@ -0,0 +1,4 @@ +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= +github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= diff --git a/v2/std.go b/v2/std.go new file mode 100644 index 0000000..327b9c6 --- /dev/null +++ b/v2/std.go @@ -0,0 +1,792 @@ +package currency + +/*-------------------------------+ +| Code generated by std_currency | +| DO NOT EDIT | ++-------------------------------*/ + +import "fmt" + +// Currency defines a currency containing +// It's code, taken from the constants above +// as well as it's minor units, as an integer. +type Currency struct { + code string + minorUnits int + factor int + name string +} + +// Code returns the currency code to the user +func (c *Currency) Code() string { return c.code } + +// MinorUnits returns the minor unit to the user +func (c *Currency) MinorUnits() int { return c.minorUnits } + +// Name returns the currency name as defined in the ISO. +func (c *Currency) Name() string { return c.name } + +// Factor returns the factor by which a float should be multiplied +// to get back to it's smallest denomination +// +// Example: +// +// pence := 100.00 * currency.GBP.Factor() +func (c *Currency) Factor() int { return c.factor } + +// FactorI64 returns the factor, converted to a int64 +func (c *Currency) FactorI64() int64 { return int64(c.factor) } + +// FactorF64 returns the factor, converted to a float64 +func (c *Currency) FactorF64() float64 { return float64(c.factor) } + +// Get returns a currency struct if the provided +// code is contained within the valid codes. Otherwise +// an error will be returned +func Get(code string) (*Currency, error) { + if Valid(code) { + val, ok := currencies[code] + if ok { + return &val, nil + } + } + return nil, fmt.Errorf("currency: could not find currency with code: %q", code) +} + +// Valid checks if a provided code is contained +// inside the provided ValidCodes slice +func Valid(code string) bool { + for _, c := range ValidCodes { + if c == code { + return true + } + } + return false +} + +// Following are all the structs containing currency data +var ( + // AED currency struct + AED = Currency{code: "AED", minorUnits: 2, factor: 100, name: "UAE Dirham"} + // AFN currency struct + AFN = Currency{code: "AFN", minorUnits: 2, factor: 100, name: "Afghani"} + // ALL currency struct + ALL = Currency{code: "ALL", minorUnits: 2, factor: 100, name: "Lek"} + // AMD currency struct + AMD = Currency{code: "AMD", minorUnits: 2, factor: 100, name: "Armenian Dram"} + // ANG currency struct + ANG = Currency{code: "ANG", minorUnits: 2, factor: 100, name: "Netherlands Antillean Guilder"} + // AOA currency struct + AOA = Currency{code: "AOA", minorUnits: 2, factor: 100, name: "Kwanza"} + // ARS currency struct + ARS = Currency{code: "ARS", minorUnits: 2, factor: 100, name: "Argentine Peso"} + // AUD currency struct + AUD = Currency{code: "AUD", minorUnits: 2, factor: 100, name: "Australian Dollar"} + // AWG currency struct + AWG = Currency{code: "AWG", minorUnits: 2, factor: 100, name: "Aruban Florin"} + // AZN currency struct + AZN = Currency{code: "AZN", minorUnits: 2, factor: 100, name: "Azerbaijan Manat"} + // BAM currency struct + BAM = Currency{code: "BAM", minorUnits: 2, factor: 100, name: "Convertible Mark"} + // BBD currency struct + BBD = Currency{code: "BBD", minorUnits: 2, factor: 100, name: "Barbados Dollar"} + // BDT currency struct + BDT = Currency{code: "BDT", minorUnits: 2, factor: 100, name: "Taka"} + // BGN currency struct + BGN = Currency{code: "BGN", minorUnits: 2, factor: 100, name: "Bulgarian Lev"} + // BHD currency struct + BHD = Currency{code: "BHD", minorUnits: 3, factor: 1000, name: "Bahraini Dinar"} + // BIF currency struct + BIF = Currency{code: "BIF", minorUnits: 0, factor: 1, name: "Burundi Franc"} + // BMD currency struct + BMD = Currency{code: "BMD", minorUnits: 2, factor: 100, name: "Bermudian Dollar"} + // BND currency struct + BND = Currency{code: "BND", minorUnits: 2, factor: 100, name: "Brunei Dollar"} + // BOB currency struct + BOB = Currency{code: "BOB", minorUnits: 2, factor: 100, name: "Boliviano"} + // BOV currency struct + BOV = Currency{code: "BOV", minorUnits: 2, factor: 100, name: "Mvdol"} + // BRL currency struct + BRL = Currency{code: "BRL", minorUnits: 2, factor: 100, name: "Brazilian Real"} + // BSD currency struct + BSD = Currency{code: "BSD", minorUnits: 2, factor: 100, name: "Bahamian Dollar"} + // BTN currency struct + BTN = Currency{code: "BTN", minorUnits: 2, factor: 100, name: "Ngultrum"} + // BWP currency struct + BWP = Currency{code: "BWP", minorUnits: 2, factor: 100, name: "Pula"} + // BYN currency struct + BYN = Currency{code: "BYN", minorUnits: 2, factor: 100, name: "Belarusian Ruble"} + // BZD currency struct + BZD = Currency{code: "BZD", minorUnits: 2, factor: 100, name: "Belize Dollar"} + // CAD currency struct + CAD = Currency{code: "CAD", minorUnits: 2, factor: 100, name: "Canadian Dollar"} + // CDF currency struct + CDF = Currency{code: "CDF", minorUnits: 2, factor: 100, name: "Congolese Franc"} + // CHE currency struct + CHE = Currency{code: "CHE", minorUnits: 2, factor: 100, name: "WIR Euro"} + // CHF currency struct + CHF = Currency{code: "CHF", minorUnits: 2, factor: 100, name: "Swiss Franc"} + // CHW currency struct + CHW = Currency{code: "CHW", minorUnits: 2, factor: 100, name: "WIR Franc"} + // CLF currency struct + CLF = Currency{code: "CLF", minorUnits: 4, factor: 10000, name: "Unidad de Fomento"} + // CLP currency struct + CLP = Currency{code: "CLP", minorUnits: 0, factor: 1, name: "Chilean Peso"} + // CNY currency struct + CNY = Currency{code: "CNY", minorUnits: 2, factor: 100, name: "Yuan Renminbi"} + // COP currency struct + COP = Currency{code: "COP", minorUnits: 2, factor: 100, name: "Colombian Peso"} + // COU currency struct + COU = Currency{code: "COU", minorUnits: 2, factor: 100, name: "Unidad de Valor Real"} + // CRC currency struct + CRC = Currency{code: "CRC", minorUnits: 2, factor: 100, name: "Costa Rican Colon"} + // CUC currency struct + CUC = Currency{code: "CUC", minorUnits: 2, factor: 100, name: "Peso Convertible"} + // CUP currency struct + CUP = Currency{code: "CUP", minorUnits: 2, factor: 100, name: "Cuban Peso"} + // CVE currency struct + CVE = Currency{code: "CVE", minorUnits: 2, factor: 100, name: "Cabo Verde Escudo"} + // CZK currency struct + CZK = Currency{code: "CZK", minorUnits: 2, factor: 100, name: "Czech Koruna"} + // DJF currency struct + DJF = Currency{code: "DJF", minorUnits: 0, factor: 1, name: "Djibouti Franc"} + // DKK currency struct + DKK = Currency{code: "DKK", minorUnits: 2, factor: 100, name: "Danish Krone"} + // DOP currency struct + DOP = Currency{code: "DOP", minorUnits: 2, factor: 100, name: "Dominican Peso"} + // DZD currency struct + DZD = Currency{code: "DZD", minorUnits: 2, factor: 100, name: "Algerian Dinar"} + // EGP currency struct + EGP = Currency{code: "EGP", minorUnits: 2, factor: 100, name: "Egyptian Pound"} + // ERN currency struct + ERN = Currency{code: "ERN", minorUnits: 2, factor: 100, name: "Nakfa"} + // ETB currency struct + ETB = Currency{code: "ETB", minorUnits: 2, factor: 100, name: "Ethiopian Birr"} + // EUR currency struct + EUR = Currency{code: "EUR", minorUnits: 2, factor: 100, name: "Euro"} + // FJD currency struct + FJD = Currency{code: "FJD", minorUnits: 2, factor: 100, name: "Fiji Dollar"} + // FKP currency struct + FKP = Currency{code: "FKP", minorUnits: 2, factor: 100, name: "Falkland Islands Pound"} + // GBP currency struct + GBP = Currency{code: "GBP", minorUnits: 2, factor: 100, name: "Pound Sterling"} + // GEL currency struct + GEL = Currency{code: "GEL", minorUnits: 2, factor: 100, name: "Lari"} + // GHS currency struct + GHS = Currency{code: "GHS", minorUnits: 2, factor: 100, name: "Ghana Cedi"} + // GIP currency struct + GIP = Currency{code: "GIP", minorUnits: 2, factor: 100, name: "Gibraltar Pound"} + // GMD currency struct + GMD = Currency{code: "GMD", minorUnits: 2, factor: 100, name: "Dalasi"} + // GNF currency struct + GNF = Currency{code: "GNF", minorUnits: 0, factor: 1, name: "Guinean Franc"} + // GTQ currency struct + GTQ = Currency{code: "GTQ", minorUnits: 2, factor: 100, name: "Quetzal"} + // GYD currency struct + GYD = Currency{code: "GYD", minorUnits: 2, factor: 100, name: "Guyana Dollar"} + // HKD currency struct + HKD = Currency{code: "HKD", minorUnits: 2, factor: 100, name: "Hong Kong Dollar"} + // HNL currency struct + HNL = Currency{code: "HNL", minorUnits: 2, factor: 100, name: "Lempira"} + // HTG currency struct + HTG = Currency{code: "HTG", minorUnits: 2, factor: 100, name: "Gourde"} + // HUF currency struct + HUF = Currency{code: "HUF", minorUnits: 2, factor: 100, name: "Forint"} + // IDR currency struct + IDR = Currency{code: "IDR", minorUnits: 2, factor: 100, name: "Rupiah"} + // ILS currency struct + ILS = Currency{code: "ILS", minorUnits: 2, factor: 100, name: "New Israeli Sheqel"} + // INR currency struct + INR = Currency{code: "INR", minorUnits: 2, factor: 100, name: "Indian Rupee"} + // IQD currency struct + IQD = Currency{code: "IQD", minorUnits: 3, factor: 1000, name: "Iraqi Dinar"} + // IRR currency struct + IRR = Currency{code: "IRR", minorUnits: 2, factor: 100, name: "Iranian Rial"} + // ISK currency struct + ISK = Currency{code: "ISK", minorUnits: 0, factor: 1, name: "Iceland Krona"} + // JMD currency struct + JMD = Currency{code: "JMD", minorUnits: 2, factor: 100, name: "Jamaican Dollar"} + // JOD currency struct + JOD = Currency{code: "JOD", minorUnits: 3, factor: 1000, name: "Jordanian Dinar"} + // JPY currency struct + JPY = Currency{code: "JPY", minorUnits: 0, factor: 1, name: "Yen"} + // KES currency struct + KES = Currency{code: "KES", minorUnits: 2, factor: 100, name: "Kenyan Shilling"} + // KGS currency struct + KGS = Currency{code: "KGS", minorUnits: 2, factor: 100, name: "Som"} + // KHR currency struct + KHR = Currency{code: "KHR", minorUnits: 2, factor: 100, name: "Riel"} + // KMF currency struct + KMF = Currency{code: "KMF", minorUnits: 0, factor: 1, name: "Comorian Franc "} + // KPW currency struct + KPW = Currency{code: "KPW", minorUnits: 2, factor: 100, name: "North Korean Won"} + // KRW currency struct + KRW = Currency{code: "KRW", minorUnits: 0, factor: 1, name: "Won"} + // KWD currency struct + KWD = Currency{code: "KWD", minorUnits: 3, factor: 1000, name: "Kuwaiti Dinar"} + // KYD currency struct + KYD = Currency{code: "KYD", minorUnits: 2, factor: 100, name: "Cayman Islands Dollar"} + // KZT currency struct + KZT = Currency{code: "KZT", minorUnits: 2, factor: 100, name: "Tenge"} + // LAK currency struct + LAK = Currency{code: "LAK", minorUnits: 2, factor: 100, name: "Lao Kip"} + // LBP currency struct + LBP = Currency{code: "LBP", minorUnits: 2, factor: 100, name: "Lebanese Pound"} + // LKR currency struct + LKR = Currency{code: "LKR", minorUnits: 2, factor: 100, name: "Sri Lanka Rupee"} + // LRD currency struct + LRD = Currency{code: "LRD", minorUnits: 2, factor: 100, name: "Liberian Dollar"} + // LSL currency struct + LSL = Currency{code: "LSL", minorUnits: 2, factor: 100, name: "Loti"} + // LYD currency struct + LYD = Currency{code: "LYD", minorUnits: 3, factor: 1000, name: "Libyan Dinar"} + // MAD currency struct + MAD = Currency{code: "MAD", minorUnits: 2, factor: 100, name: "Moroccan Dirham"} + // MDL currency struct + MDL = Currency{code: "MDL", minorUnits: 2, factor: 100, name: "Moldovan Leu"} + // MGA currency struct + MGA = Currency{code: "MGA", minorUnits: 2, factor: 100, name: "Malagasy Ariary"} + // MKD currency struct + MKD = Currency{code: "MKD", minorUnits: 2, factor: 100, name: "Denar"} + // MMK currency struct + MMK = Currency{code: "MMK", minorUnits: 2, factor: 100, name: "Kyat"} + // MNT currency struct + MNT = Currency{code: "MNT", minorUnits: 2, factor: 100, name: "Tugrik"} + // MOP currency struct + MOP = Currency{code: "MOP", minorUnits: 2, factor: 100, name: "Pataca"} + // MRU currency struct + MRU = Currency{code: "MRU", minorUnits: 2, factor: 100, name: "Ouguiya"} + // MUR currency struct + MUR = Currency{code: "MUR", minorUnits: 2, factor: 100, name: "Mauritius Rupee"} + // MVR currency struct + MVR = Currency{code: "MVR", minorUnits: 2, factor: 100, name: "Rufiyaa"} + // MWK currency struct + MWK = Currency{code: "MWK", minorUnits: 2, factor: 100, name: "Malawi Kwacha"} + // MXN currency struct + MXN = Currency{code: "MXN", minorUnits: 2, factor: 100, name: "Mexican Peso"} + // MXV currency struct + MXV = Currency{code: "MXV", minorUnits: 2, factor: 100, name: "Mexican Unidad de Inversion (UDI)"} + // MYR currency struct + MYR = Currency{code: "MYR", minorUnits: 2, factor: 100, name: "Malaysian Ringgit"} + // MZN currency struct + MZN = Currency{code: "MZN", minorUnits: 2, factor: 100, name: "Mozambique Metical"} + // NAD currency struct + NAD = Currency{code: "NAD", minorUnits: 2, factor: 100, name: "Namibia Dollar"} + // NGN currency struct + NGN = Currency{code: "NGN", minorUnits: 2, factor: 100, name: "Naira"} + // NIO currency struct + NIO = Currency{code: "NIO", minorUnits: 2, factor: 100, name: "Cordoba Oro"} + // NOK currency struct + NOK = Currency{code: "NOK", minorUnits: 2, factor: 100, name: "Norwegian Krone"} + // NPR currency struct + NPR = Currency{code: "NPR", minorUnits: 2, factor: 100, name: "Nepalese Rupee"} + // NZD currency struct + NZD = Currency{code: "NZD", minorUnits: 2, factor: 100, name: "New Zealand Dollar"} + // OMR currency struct + OMR = Currency{code: "OMR", minorUnits: 3, factor: 1000, name: "Rial Omani"} + // PAB currency struct + PAB = Currency{code: "PAB", minorUnits: 2, factor: 100, name: "Balboa"} + // PEN currency struct + PEN = Currency{code: "PEN", minorUnits: 2, factor: 100, name: "Sol"} + // PGK currency struct + PGK = Currency{code: "PGK", minorUnits: 2, factor: 100, name: "Kina"} + // PHP currency struct + PHP = Currency{code: "PHP", minorUnits: 2, factor: 100, name: "Philippine Peso"} + // PKR currency struct + PKR = Currency{code: "PKR", minorUnits: 2, factor: 100, name: "Pakistan Rupee"} + // PLN currency struct + PLN = Currency{code: "PLN", minorUnits: 2, factor: 100, name: "Zloty"} + // PYG currency struct + PYG = Currency{code: "PYG", minorUnits: 0, factor: 1, name: "Guarani"} + // QAR currency struct + QAR = Currency{code: "QAR", minorUnits: 2, factor: 100, name: "Qatari Rial"} + // RON currency struct + RON = Currency{code: "RON", minorUnits: 2, factor: 100, name: "Romanian Leu"} + // RSD currency struct + RSD = Currency{code: "RSD", minorUnits: 2, factor: 100, name: "Serbian Dinar"} + // RUB currency struct + RUB = Currency{code: "RUB", minorUnits: 2, factor: 100, name: "Russian Ruble"} + // RWF currency struct + RWF = Currency{code: "RWF", minorUnits: 0, factor: 1, name: "Rwanda Franc"} + // SAR currency struct + SAR = Currency{code: "SAR", minorUnits: 2, factor: 100, name: "Saudi Riyal"} + // SBD currency struct + SBD = Currency{code: "SBD", minorUnits: 2, factor: 100, name: "Solomon Islands Dollar"} + // SCR currency struct + SCR = Currency{code: "SCR", minorUnits: 2, factor: 100, name: "Seychelles Rupee"} + // SDG currency struct + SDG = Currency{code: "SDG", minorUnits: 2, factor: 100, name: "Sudanese Pound"} + // SEK currency struct + SEK = Currency{code: "SEK", minorUnits: 2, factor: 100, name: "Swedish Krona"} + // SGD currency struct + SGD = Currency{code: "SGD", minorUnits: 2, factor: 100, name: "Singapore Dollar"} + // SHP currency struct + SHP = Currency{code: "SHP", minorUnits: 2, factor: 100, name: "Saint Helena Pound"} + // SLE currency struct + SLE = Currency{code: "SLE", minorUnits: 2, factor: 100, name: "Leone"} + // SOS currency struct + SOS = Currency{code: "SOS", minorUnits: 2, factor: 100, name: "Somali Shilling"} + // SRD currency struct + SRD = Currency{code: "SRD", minorUnits: 2, factor: 100, name: "Surinam Dollar"} + // SSP currency struct + SSP = Currency{code: "SSP", minorUnits: 2, factor: 100, name: "South Sudanese Pound"} + // STN currency struct + STN = Currency{code: "STN", minorUnits: 2, factor: 100, name: "Dobra"} + // SVC currency struct + SVC = Currency{code: "SVC", minorUnits: 2, factor: 100, name: "El Salvador Colon"} + // SYP currency struct + SYP = Currency{code: "SYP", minorUnits: 2, factor: 100, name: "Syrian Pound"} + // SZL currency struct + SZL = Currency{code: "SZL", minorUnits: 2, factor: 100, name: "Lilangeni"} + // THB currency struct + THB = Currency{code: "THB", minorUnits: 2, factor: 100, name: "Baht"} + // TJS currency struct + TJS = Currency{code: "TJS", minorUnits: 2, factor: 100, name: "Somoni"} + // TMT currency struct + TMT = Currency{code: "TMT", minorUnits: 2, factor: 100, name: "Turkmenistan New Manat"} + // TND currency struct + TND = Currency{code: "TND", minorUnits: 3, factor: 1000, name: "Tunisian Dinar"} + // TOP currency struct + TOP = Currency{code: "TOP", minorUnits: 2, factor: 100, name: "Pa’anga"} + // TRY currency struct + TRY = Currency{code: "TRY", minorUnits: 2, factor: 100, name: "Turkish Lira"} + // TTD currency struct + TTD = Currency{code: "TTD", minorUnits: 2, factor: 100, name: "Trinidad and Tobago Dollar"} + // TWD currency struct + TWD = Currency{code: "TWD", minorUnits: 2, factor: 100, name: "New Taiwan Dollar"} + // TZS currency struct + TZS = Currency{code: "TZS", minorUnits: 2, factor: 100, name: "Tanzanian Shilling"} + // UAH currency struct + UAH = Currency{code: "UAH", minorUnits: 2, factor: 100, name: "Hryvnia"} + // UGX currency struct + UGX = Currency{code: "UGX", minorUnits: 0, factor: 1, name: "Uganda Shilling"} + // USD currency struct + USD = Currency{code: "USD", minorUnits: 2, factor: 100, name: "US Dollar"} + // USN currency struct + USN = Currency{code: "USN", minorUnits: 2, factor: 100, name: "US Dollar (Next day)"} + // UYI currency struct + UYI = Currency{code: "UYI", minorUnits: 0, factor: 1, name: "Uruguay Peso en Unidades Indexadas (UI)"} + // UYU currency struct + UYU = Currency{code: "UYU", minorUnits: 2, factor: 100, name: "Peso Uruguayo"} + // UYW currency struct + UYW = Currency{code: "UYW", minorUnits: 4, factor: 10000, name: "Unidad Previsional"} + // UZS currency struct + UZS = Currency{code: "UZS", minorUnits: 2, factor: 100, name: "Uzbekistan Sum"} + // VED currency struct + VED = Currency{code: "VED", minorUnits: 2, factor: 100, name: "Bolívar Soberano"} + // VES currency struct + VES = Currency{code: "VES", minorUnits: 2, factor: 100, name: "Bolívar Soberano"} + // VND currency struct + VND = Currency{code: "VND", minorUnits: 0, factor: 1, name: "Dong"} + // VUV currency struct + VUV = Currency{code: "VUV", minorUnits: 0, factor: 1, name: "Vatu"} + // WST currency struct + WST = Currency{code: "WST", minorUnits: 2, factor: 100, name: "Tala"} + // XAF currency struct + XAF = Currency{code: "XAF", minorUnits: 0, factor: 1, name: "CFA Franc BEAC"} + // XAG currency struct + XAG = Currency{code: "XAG", minorUnits: 0, factor: 1, name: "Silver"} + // XAU currency struct + XAU = Currency{code: "XAU", minorUnits: 0, factor: 1, name: "Gold"} + // XBA currency struct + XBA = Currency{code: "XBA", minorUnits: 0, factor: 1, name: "Bond Markets Unit European Composite Unit (EURCO)"} + // XBB currency struct + XBB = Currency{code: "XBB", minorUnits: 0, factor: 1, name: "Bond Markets Unit European Monetary Unit (E.M.U.-6)"} + // XBC currency struct + XBC = Currency{code: "XBC", minorUnits: 0, factor: 1, name: "Bond Markets Unit European Unit of Account 9 (E.U.A.-9)"} + // XBD currency struct + XBD = Currency{code: "XBD", minorUnits: 0, factor: 1, name: "Bond Markets Unit European Unit of Account 17 (E.U.A.-17)"} + // XCD currency struct + XCD = Currency{code: "XCD", minorUnits: 2, factor: 100, name: "East Caribbean Dollar"} + // XDR currency struct + XDR = Currency{code: "XDR", minorUnits: 0, factor: 1, name: "SDR (Special Drawing Right)"} + // XOF currency struct + XOF = Currency{code: "XOF", minorUnits: 0, factor: 1, name: "CFA Franc BCEAO"} + // XPD currency struct + XPD = Currency{code: "XPD", minorUnits: 0, factor: 1, name: "Palladium"} + // XPF currency struct + XPF = Currency{code: "XPF", minorUnits: 0, factor: 1, name: "CFP Franc"} + // XPT currency struct + XPT = Currency{code: "XPT", minorUnits: 0, factor: 1, name: "Platinum"} + // XSU currency struct + XSU = Currency{code: "XSU", minorUnits: 0, factor: 1, name: "Sucre"} + // XTS currency struct + XTS = Currency{code: "XTS", minorUnits: 0, factor: 1, name: "Codes specifically reserved for testing purposes"} + // XUA currency struct + XUA = Currency{code: "XUA", minorUnits: 0, factor: 1, name: "ADB Unit of Account"} + // XXX currency struct + XXX = Currency{code: "XXX", minorUnits: 0, factor: 1, name: "The codes assigned for transactions where no currency is involved"} + // YER currency struct + YER = Currency{code: "YER", minorUnits: 2, factor: 100, name: "Yemeni Rial"} + // ZAR currency struct + ZAR = Currency{code: "ZAR", minorUnits: 2, factor: 100, name: "Rand"} + // ZMW currency struct + ZMW = Currency{code: "ZMW", minorUnits: 2, factor: 100, name: "Zambian Kwacha"} + // ZWG currency struct + ZWG = Currency{code: "ZWG", minorUnits: 2, factor: 100, name: "Zimbabwe Gold"} +) + +var currencies = map[string]Currency{ + "AED": AED, + "AFN": AFN, + "ALL": ALL, + "AMD": AMD, + "ANG": ANG, + "AOA": AOA, + "ARS": ARS, + "AUD": AUD, + "AWG": AWG, + "AZN": AZN, + "BAM": BAM, + "BBD": BBD, + "BDT": BDT, + "BGN": BGN, + "BHD": BHD, + "BIF": BIF, + "BMD": BMD, + "BND": BND, + "BOB": BOB, + "BOV": BOV, + "BRL": BRL, + "BSD": BSD, + "BTN": BTN, + "BWP": BWP, + "BYN": BYN, + "BZD": BZD, + "CAD": CAD, + "CDF": CDF, + "CHE": CHE, + "CHF": CHF, + "CHW": CHW, + "CLF": CLF, + "CLP": CLP, + "CNY": CNY, + "COP": COP, + "COU": COU, + "CRC": CRC, + "CUC": CUC, + "CUP": CUP, + "CVE": CVE, + "CZK": CZK, + "DJF": DJF, + "DKK": DKK, + "DOP": DOP, + "DZD": DZD, + "EGP": EGP, + "ERN": ERN, + "ETB": ETB, + "EUR": EUR, + "FJD": FJD, + "FKP": FKP, + "GBP": GBP, + "GEL": GEL, + "GHS": GHS, + "GIP": GIP, + "GMD": GMD, + "GNF": GNF, + "GTQ": GTQ, + "GYD": GYD, + "HKD": HKD, + "HNL": HNL, + "HTG": HTG, + "HUF": HUF, + "IDR": IDR, + "ILS": ILS, + "INR": INR, + "IQD": IQD, + "IRR": IRR, + "ISK": ISK, + "JMD": JMD, + "JOD": JOD, + "JPY": JPY, + "KES": KES, + "KGS": KGS, + "KHR": KHR, + "KMF": KMF, + "KPW": KPW, + "KRW": KRW, + "KWD": KWD, + "KYD": KYD, + "KZT": KZT, + "LAK": LAK, + "LBP": LBP, + "LKR": LKR, + "LRD": LRD, + "LSL": LSL, + "LYD": LYD, + "MAD": MAD, + "MDL": MDL, + "MGA": MGA, + "MKD": MKD, + "MMK": MMK, + "MNT": MNT, + "MOP": MOP, + "MRU": MRU, + "MUR": MUR, + "MVR": MVR, + "MWK": MWK, + "MXN": MXN, + "MXV": MXV, + "MYR": MYR, + "MZN": MZN, + "NAD": NAD, + "NGN": NGN, + "NIO": NIO, + "NOK": NOK, + "NPR": NPR, + "NZD": NZD, + "OMR": OMR, + "PAB": PAB, + "PEN": PEN, + "PGK": PGK, + "PHP": PHP, + "PKR": PKR, + "PLN": PLN, + "PYG": PYG, + "QAR": QAR, + "RON": RON, + "RSD": RSD, + "RUB": RUB, + "RWF": RWF, + "SAR": SAR, + "SBD": SBD, + "SCR": SCR, + "SDG": SDG, + "SEK": SEK, + "SGD": SGD, + "SHP": SHP, + "SLE": SLE, + "SOS": SOS, + "SRD": SRD, + "SSP": SSP, + "STN": STN, + "SVC": SVC, + "SYP": SYP, + "SZL": SZL, + "THB": THB, + "TJS": TJS, + "TMT": TMT, + "TND": TND, + "TOP": TOP, + "TRY": TRY, + "TTD": TTD, + "TWD": TWD, + "TZS": TZS, + "UAH": UAH, + "UGX": UGX, + "USD": USD, + "USN": USN, + "UYI": UYI, + "UYU": UYU, + "UYW": UYW, + "UZS": UZS, + "VED": VED, + "VES": VES, + "VND": VND, + "VUV": VUV, + "WST": WST, + "XAF": XAF, + "XAG": XAG, + "XAU": XAU, + "XBA": XBA, + "XBB": XBB, + "XBC": XBC, + "XBD": XBD, + "XCD": XCD, + "XDR": XDR, + "XOF": XOF, + "XPD": XPD, + "XPF": XPF, + "XPT": XPT, + "XSU": XSU, + "XTS": XTS, + "XUA": XUA, + "XXX": XXX, + "YER": YER, + "ZAR": ZAR, + "ZMW": ZMW, + "ZWG": ZWG, +} + +// ValidCodes is provided so that you may build your own validation against it +var ValidCodes = []string{ + "AED", + "AFN", + "ALL", + "AMD", + "ANG", + "AOA", + "ARS", + "AUD", + "AWG", + "AZN", + "BAM", + "BBD", + "BDT", + "BGN", + "BHD", + "BIF", + "BMD", + "BND", + "BOB", + "BOV", + "BRL", + "BSD", + "BTN", + "BWP", + "BYN", + "BZD", + "CAD", + "CDF", + "CHE", + "CHF", + "CHW", + "CLF", + "CLP", + "CNY", + "COP", + "COU", + "CRC", + "CUC", + "CUP", + "CVE", + "CZK", + "DJF", + "DKK", + "DOP", + "DZD", + "EGP", + "ERN", + "ETB", + "EUR", + "FJD", + "FKP", + "GBP", + "GEL", + "GHS", + "GIP", + "GMD", + "GNF", + "GTQ", + "GYD", + "HKD", + "HNL", + "HTG", + "HUF", + "IDR", + "ILS", + "INR", + "IQD", + "IRR", + "ISK", + "JMD", + "JOD", + "JPY", + "KES", + "KGS", + "KHR", + "KMF", + "KPW", + "KRW", + "KWD", + "KYD", + "KZT", + "LAK", + "LBP", + "LKR", + "LRD", + "LSL", + "LYD", + "MAD", + "MDL", + "MGA", + "MKD", + "MMK", + "MNT", + "MOP", + "MRU", + "MUR", + "MVR", + "MWK", + "MXN", + "MXV", + "MYR", + "MZN", + "NAD", + "NGN", + "NIO", + "NOK", + "NPR", + "NZD", + "OMR", + "PAB", + "PEN", + "PGK", + "PHP", + "PKR", + "PLN", + "PYG", + "QAR", + "RON", + "RSD", + "RUB", + "RWF", + "SAR", + "SBD", + "SCR", + "SDG", + "SEK", + "SGD", + "SHP", + "SLE", + "SOS", + "SRD", + "SSP", + "STN", + "SVC", + "SYP", + "SZL", + "THB", + "TJS", + "TMT", + "TND", + "TOP", + "TRY", + "TTD", + "TWD", + "TZS", + "UAH", + "UGX", + "USD", + "USN", + "UYI", + "UYU", + "UYW", + "UZS", + "VED", + "VES", + "VND", + "VUV", + "WST", + "XAF", + "XAG", + "XAU", + "XBA", + "XBB", + "XBC", + "XBD", + "XCD", + "XDR", + "XOF", + "XPD", + "XPF", + "XPT", + "XSU", + "XTS", + "XUA", + "XXX", + "YER", + "ZAR", + "ZMW", + "ZWG", +} diff --git a/v2/std.kt b/v2/std.kt new file mode 100644 index 0000000..8ca0731 --- /dev/null +++ b/v2/std.kt @@ -0,0 +1,185 @@ +data class Currency(val currencyCode: String, val minorUnits: Int, val factor: Int, val name: String) { + companion object { + val currencyMap = mapOf( + "AED" to Currency("AED", 2, 100, "UAE Dirham"), + "AFN" to Currency("AFN", 2, 100, "Afghani"), + "ALL" to Currency("ALL", 2, 100, "Lek"), + "AMD" to Currency("AMD", 2, 100, "Armenian Dram"), + "ANG" to Currency("ANG", 2, 100, "Netherlands Antillean Guilder"), + "AOA" to Currency("AOA", 2, 100, "Kwanza"), + "ARS" to Currency("ARS", 2, 100, "Argentine Peso"), + "AUD" to Currency("AUD", 2, 100, "Australian Dollar"), + "AWG" to Currency("AWG", 2, 100, "Aruban Florin"), + "AZN" to Currency("AZN", 2, 100, "Azerbaijan Manat"), + "BAM" to Currency("BAM", 2, 100, "Convertible Mark"), + "BBD" to Currency("BBD", 2, 100, "Barbados Dollar"), + "BDT" to Currency("BDT", 2, 100, "Taka"), + "BGN" to Currency("BGN", 2, 100, "Bulgarian Lev"), + "BHD" to Currency("BHD", 3, 1000, "Bahraini Dinar"), + "BIF" to Currency("BIF", 0, 1, "Burundi Franc"), + "BMD" to Currency("BMD", 2, 100, "Bermudian Dollar"), + "BND" to Currency("BND", 2, 100, "Brunei Dollar"), + "BOB" to Currency("BOB", 2, 100, "Boliviano"), + "BOV" to Currency("BOV", 2, 100, "Mvdol"), + "BRL" to Currency("BRL", 2, 100, "Brazilian Real"), + "BSD" to Currency("BSD", 2, 100, "Bahamian Dollar"), + "BTN" to Currency("BTN", 2, 100, "Ngultrum"), + "BWP" to Currency("BWP", 2, 100, "Pula"), + "BYN" to Currency("BYN", 2, 100, "Belarusian Ruble"), + "BZD" to Currency("BZD", 2, 100, "Belize Dollar"), + "CAD" to Currency("CAD", 2, 100, "Canadian Dollar"), + "CDF" to Currency("CDF", 2, 100, "Congolese Franc"), + "CHE" to Currency("CHE", 2, 100, "WIR Euro"), + "CHF" to Currency("CHF", 2, 100, "Swiss Franc"), + "CHW" to Currency("CHW", 2, 100, "WIR Franc"), + "CLF" to Currency("CLF", 4, 10000, "Unidad de Fomento"), + "CLP" to Currency("CLP", 0, 1, "Chilean Peso"), + "CNY" to Currency("CNY", 2, 100, "Yuan Renminbi"), + "COP" to Currency("COP", 2, 100, "Colombian Peso"), + "COU" to Currency("COU", 2, 100, "Unidad de Valor Real"), + "CRC" to Currency("CRC", 2, 100, "Costa Rican Colon"), + "CUC" to Currency("CUC", 2, 100, "Peso Convertible"), + "CUP" to Currency("CUP", 2, 100, "Cuban Peso"), + "CVE" to Currency("CVE", 2, 100, "Cabo Verde Escudo"), + "CZK" to Currency("CZK", 2, 100, "Czech Koruna"), + "DJF" to Currency("DJF", 0, 1, "Djibouti Franc"), + "DKK" to Currency("DKK", 2, 100, "Danish Krone"), + "DOP" to Currency("DOP", 2, 100, "Dominican Peso"), + "DZD" to Currency("DZD", 2, 100, "Algerian Dinar"), + "EGP" to Currency("EGP", 2, 100, "Egyptian Pound"), + "ERN" to Currency("ERN", 2, 100, "Nakfa"), + "ETB" to Currency("ETB", 2, 100, "Ethiopian Birr"), + "EUR" to Currency("EUR", 2, 100, "Euro"), + "FJD" to Currency("FJD", 2, 100, "Fiji Dollar"), + "FKP" to Currency("FKP", 2, 100, "Falkland Islands Pound"), + "GBP" to Currency("GBP", 2, 100, "Pound Sterling"), + "GEL" to Currency("GEL", 2, 100, "Lari"), + "GHS" to Currency("GHS", 2, 100, "Ghana Cedi"), + "GIP" to Currency("GIP", 2, 100, "Gibraltar Pound"), + "GMD" to Currency("GMD", 2, 100, "Dalasi"), + "GNF" to Currency("GNF", 0, 1, "Guinean Franc"), + "GTQ" to Currency("GTQ", 2, 100, "Quetzal"), + "GYD" to Currency("GYD", 2, 100, "Guyana Dollar"), + "HKD" to Currency("HKD", 2, 100, "Hong Kong Dollar"), + "HNL" to Currency("HNL", 2, 100, "Lempira"), + "HTG" to Currency("HTG", 2, 100, "Gourde"), + "HUF" to Currency("HUF", 2, 100, "Forint"), + "IDR" to Currency("IDR", 2, 100, "Rupiah"), + "ILS" to Currency("ILS", 2, 100, "New Israeli Sheqel"), + "INR" to Currency("INR", 2, 100, "Indian Rupee"), + "IQD" to Currency("IQD", 3, 1000, "Iraqi Dinar"), + "IRR" to Currency("IRR", 2, 100, "Iranian Rial"), + "ISK" to Currency("ISK", 0, 1, "Iceland Krona"), + "JMD" to Currency("JMD", 2, 100, "Jamaican Dollar"), + "JOD" to Currency("JOD", 3, 1000, "Jordanian Dinar"), + "JPY" to Currency("JPY", 0, 1, "Yen"), + "KES" to Currency("KES", 2, 100, "Kenyan Shilling"), + "KGS" to Currency("KGS", 2, 100, "Som"), + "KHR" to Currency("KHR", 2, 100, "Riel"), + "KMF" to Currency("KMF", 0, 1, "Comorian Franc "), + "KPW" to Currency("KPW", 2, 100, "North Korean Won"), + "KRW" to Currency("KRW", 0, 1, "Won"), + "KWD" to Currency("KWD", 3, 1000, "Kuwaiti Dinar"), + "KYD" to Currency("KYD", 2, 100, "Cayman Islands Dollar"), + "KZT" to Currency("KZT", 2, 100, "Tenge"), + "LAK" to Currency("LAK", 2, 100, "Lao Kip"), + "LBP" to Currency("LBP", 2, 100, "Lebanese Pound"), + "LKR" to Currency("LKR", 2, 100, "Sri Lanka Rupee"), + "LRD" to Currency("LRD", 2, 100, "Liberian Dollar"), + "LSL" to Currency("LSL", 2, 100, "Loti"), + "LYD" to Currency("LYD", 3, 1000, "Libyan Dinar"), + "MAD" to Currency("MAD", 2, 100, "Moroccan Dirham"), + "MDL" to Currency("MDL", 2, 100, "Moldovan Leu"), + "MGA" to Currency("MGA", 2, 100, "Malagasy Ariary"), + "MKD" to Currency("MKD", 2, 100, "Denar"), + "MMK" to Currency("MMK", 2, 100, "Kyat"), + "MNT" to Currency("MNT", 2, 100, "Tugrik"), + "MOP" to Currency("MOP", 2, 100, "Pataca"), + "MRU" to Currency("MRU", 2, 100, "Ouguiya"), + "MUR" to Currency("MUR", 2, 100, "Mauritius Rupee"), + "MVR" to Currency("MVR", 2, 100, "Rufiyaa"), + "MWK" to Currency("MWK", 2, 100, "Malawi Kwacha"), + "MXN" to Currency("MXN", 2, 100, "Mexican Peso"), + "MXV" to Currency("MXV", 2, 100, "Mexican Unidad de Inversion (UDI)"), + "MYR" to Currency("MYR", 2, 100, "Malaysian Ringgit"), + "MZN" to Currency("MZN", 2, 100, "Mozambique Metical"), + "NAD" to Currency("NAD", 2, 100, "Namibia Dollar"), + "NGN" to Currency("NGN", 2, 100, "Naira"), + "NIO" to Currency("NIO", 2, 100, "Cordoba Oro"), + "NOK" to Currency("NOK", 2, 100, "Norwegian Krone"), + "NPR" to Currency("NPR", 2, 100, "Nepalese Rupee"), + "NZD" to Currency("NZD", 2, 100, "New Zealand Dollar"), + "OMR" to Currency("OMR", 3, 1000, "Rial Omani"), + "PAB" to Currency("PAB", 2, 100, "Balboa"), + "PEN" to Currency("PEN", 2, 100, "Sol"), + "PGK" to Currency("PGK", 2, 100, "Kina"), + "PHP" to Currency("PHP", 2, 100, "Philippine Peso"), + "PKR" to Currency("PKR", 2, 100, "Pakistan Rupee"), + "PLN" to Currency("PLN", 2, 100, "Zloty"), + "PYG" to Currency("PYG", 0, 1, "Guarani"), + "QAR" to Currency("QAR", 2, 100, "Qatari Rial"), + "RON" to Currency("RON", 2, 100, "Romanian Leu"), + "RSD" to Currency("RSD", 2, 100, "Serbian Dinar"), + "RUB" to Currency("RUB", 2, 100, "Russian Ruble"), + "RWF" to Currency("RWF", 0, 1, "Rwanda Franc"), + "SAR" to Currency("SAR", 2, 100, "Saudi Riyal"), + "SBD" to Currency("SBD", 2, 100, "Solomon Islands Dollar"), + "SCR" to Currency("SCR", 2, 100, "Seychelles Rupee"), + "SDG" to Currency("SDG", 2, 100, "Sudanese Pound"), + "SEK" to Currency("SEK", 2, 100, "Swedish Krona"), + "SGD" to Currency("SGD", 2, 100, "Singapore Dollar"), + "SHP" to Currency("SHP", 2, 100, "Saint Helena Pound"), + "SLE" to Currency("SLE", 2, 100, "Leone"), + "SOS" to Currency("SOS", 2, 100, "Somali Shilling"), + "SRD" to Currency("SRD", 2, 100, "Surinam Dollar"), + "SSP" to Currency("SSP", 2, 100, "South Sudanese Pound"), + "STN" to Currency("STN", 2, 100, "Dobra"), + "SVC" to Currency("SVC", 2, 100, "El Salvador Colon"), + "SYP" to Currency("SYP", 2, 100, "Syrian Pound"), + "SZL" to Currency("SZL", 2, 100, "Lilangeni"), + "THB" to Currency("THB", 2, 100, "Baht"), + "TJS" to Currency("TJS", 2, 100, "Somoni"), + "TMT" to Currency("TMT", 2, 100, "Turkmenistan New Manat"), + "TND" to Currency("TND", 3, 1000, "Tunisian Dinar"), + "TOP" to Currency("TOP", 2, 100, "Pa’anga"), + "TRY" to Currency("TRY", 2, 100, "Turkish Lira"), + "TTD" to Currency("TTD", 2, 100, "Trinidad and Tobago Dollar"), + "TWD" to Currency("TWD", 2, 100, "New Taiwan Dollar"), + "TZS" to Currency("TZS", 2, 100, "Tanzanian Shilling"), + "UAH" to Currency("UAH", 2, 100, "Hryvnia"), + "UGX" to Currency("UGX", 0, 1, "Uganda Shilling"), + "USD" to Currency("USD", 2, 100, "US Dollar"), + "USN" to Currency("USN", 2, 100, "US Dollar (Next day)"), + "UYI" to Currency("UYI", 0, 1, "Uruguay Peso en Unidades Indexadas (UI)"), + "UYU" to Currency("UYU", 2, 100, "Peso Uruguayo"), + "UYW" to Currency("UYW", 4, 10000, "Unidad Previsional"), + "UZS" to Currency("UZS", 2, 100, "Uzbekistan Sum"), + "VED" to Currency("VED", 2, 100, "Bolívar Soberano"), + "VES" to Currency("VES", 2, 100, "Bolívar Soberano"), + "VND" to Currency("VND", 0, 1, "Dong"), + "VUV" to Currency("VUV", 0, 1, "Vatu"), + "WST" to Currency("WST", 2, 100, "Tala"), + "XAF" to Currency("XAF", 0, 1, "CFA Franc BEAC"), + "XAG" to Currency("XAG", 0, 1, "Silver"), + "XAU" to Currency("XAU", 0, 1, "Gold"), + "XBA" to Currency("XBA", 0, 1, "Bond Markets Unit European Composite Unit (EURCO)"), + "XBB" to Currency("XBB", 0, 1, "Bond Markets Unit European Monetary Unit (E.M.U.-6)"), + "XBC" to Currency("XBC", 0, 1, "Bond Markets Unit European Unit of Account 9 (E.U.A.-9)"), + "XBD" to Currency("XBD", 0, 1, "Bond Markets Unit European Unit of Account 17 (E.U.A.-17)"), + "XCD" to Currency("XCD", 2, 100, "East Caribbean Dollar"), + "XDR" to Currency("XDR", 0, 1, "SDR (Special Drawing Right)"), + "XOF" to Currency("XOF", 0, 1, "CFA Franc BCEAO"), + "XPD" to Currency("XPD", 0, 1, "Palladium"), + "XPF" to Currency("XPF", 0, 1, "CFP Franc"), + "XPT" to Currency("XPT", 0, 1, "Platinum"), + "XSU" to Currency("XSU", 0, 1, "Sucre"), + "XTS" to Currency("XTS", 0, 1, "Codes specifically reserved for testing purposes"), + "XUA" to Currency("XUA", 0, 1, "ADB Unit of Account"), + "XXX" to Currency("XXX", 0, 1, "The codes assigned for transactions where no currency is involved"), + "YER" to Currency("YER", 2, 100, "Yemeni Rial"), + "ZAR" to Currency("ZAR", 2, 100, "Rand"), + "ZMW" to Currency("ZMW", 2, 100, "Zambian Kwacha"), + "ZWG" to Currency("ZWG", 2, 100, "Zimbabwe Gold") + ) + } +} diff --git a/v2/std.swift b/v2/std.swift new file mode 100644 index 0000000..a9ebce4 --- /dev/null +++ b/v2/std.swift @@ -0,0 +1,389 @@ +import UIKit + +struct Currency { + /// The `ISO 4217` currency code + var code: String + + /// The number of digits to display after the decimal point when displaying the currency + var minorUnits: Int + + /// The factor to divide the currency figure by before handing to a currency formatter + var factor: Int + + /// The `ISO 4217` currency name + var name: String +} + +class Currencies { + static let AED: Currency = Currency(code: "AED", minorUnits: 2, factor: 100, name: "UAE Dirham") + static let AFN: Currency = Currency(code: "AFN", minorUnits: 2, factor: 100, name: "Afghani") + static let ALL: Currency = Currency(code: "ALL", minorUnits: 2, factor: 100, name: "Lek") + static let AMD: Currency = Currency(code: "AMD", minorUnits: 2, factor: 100, name: "Armenian Dram") + static let ANG: Currency = Currency(code: "ANG", minorUnits: 2, factor: 100, name: "Netherlands Antillean Guilder") + static let AOA: Currency = Currency(code: "AOA", minorUnits: 2, factor: 100, name: "Kwanza") + static let ARS: Currency = Currency(code: "ARS", minorUnits: 2, factor: 100, name: "Argentine Peso") + static let AUD: Currency = Currency(code: "AUD", minorUnits: 2, factor: 100, name: "Australian Dollar") + static let AWG: Currency = Currency(code: "AWG", minorUnits: 2, factor: 100, name: "Aruban Florin") + static let AZN: Currency = Currency(code: "AZN", minorUnits: 2, factor: 100, name: "Azerbaijan Manat") + static let BAM: Currency = Currency(code: "BAM", minorUnits: 2, factor: 100, name: "Convertible Mark") + static let BBD: Currency = Currency(code: "BBD", minorUnits: 2, factor: 100, name: "Barbados Dollar") + static let BDT: Currency = Currency(code: "BDT", minorUnits: 2, factor: 100, name: "Taka") + static let BGN: Currency = Currency(code: "BGN", minorUnits: 2, factor: 100, name: "Bulgarian Lev") + static let BHD: Currency = Currency(code: "BHD", minorUnits: 3, factor: 1000, name: "Bahraini Dinar") + static let BIF: Currency = Currency(code: "BIF", minorUnits: 0, factor: 1, name: "Burundi Franc") + static let BMD: Currency = Currency(code: "BMD", minorUnits: 2, factor: 100, name: "Bermudian Dollar") + static let BND: Currency = Currency(code: "BND", minorUnits: 2, factor: 100, name: "Brunei Dollar") + static let BOB: Currency = Currency(code: "BOB", minorUnits: 2, factor: 100, name: "Boliviano") + static let BOV: Currency = Currency(code: "BOV", minorUnits: 2, factor: 100, name: "Mvdol") + static let BRL: Currency = Currency(code: "BRL", minorUnits: 2, factor: 100, name: "Brazilian Real") + static let BSD: Currency = Currency(code: "BSD", minorUnits: 2, factor: 100, name: "Bahamian Dollar") + static let BTN: Currency = Currency(code: "BTN", minorUnits: 2, factor: 100, name: "Ngultrum") + static let BWP: Currency = Currency(code: "BWP", minorUnits: 2, factor: 100, name: "Pula") + static let BYN: Currency = Currency(code: "BYN", minorUnits: 2, factor: 100, name: "Belarusian Ruble") + static let BZD: Currency = Currency(code: "BZD", minorUnits: 2, factor: 100, name: "Belize Dollar") + static let CAD: Currency = Currency(code: "CAD", minorUnits: 2, factor: 100, name: "Canadian Dollar") + static let CDF: Currency = Currency(code: "CDF", minorUnits: 2, factor: 100, name: "Congolese Franc") + static let CHE: Currency = Currency(code: "CHE", minorUnits: 2, factor: 100, name: "WIR Euro") + static let CHF: Currency = Currency(code: "CHF", minorUnits: 2, factor: 100, name: "Swiss Franc") + static let CHW: Currency = Currency(code: "CHW", minorUnits: 2, factor: 100, name: "WIR Franc") + static let CLF: Currency = Currency(code: "CLF", minorUnits: 4, factor: 10000, name: "Unidad de Fomento") + static let CLP: Currency = Currency(code: "CLP", minorUnits: 0, factor: 1, name: "Chilean Peso") + static let CNY: Currency = Currency(code: "CNY", minorUnits: 2, factor: 100, name: "Yuan Renminbi") + static let COP: Currency = Currency(code: "COP", minorUnits: 2, factor: 100, name: "Colombian Peso") + static let COU: Currency = Currency(code: "COU", minorUnits: 2, factor: 100, name: "Unidad de Valor Real") + static let CRC: Currency = Currency(code: "CRC", minorUnits: 2, factor: 100, name: "Costa Rican Colon") + static let CUC: Currency = Currency(code: "CUC", minorUnits: 2, factor: 100, name: "Peso Convertible") + static let CUP: Currency = Currency(code: "CUP", minorUnits: 2, factor: 100, name: "Cuban Peso") + static let CVE: Currency = Currency(code: "CVE", minorUnits: 2, factor: 100, name: "Cabo Verde Escudo") + static let CZK: Currency = Currency(code: "CZK", minorUnits: 2, factor: 100, name: "Czech Koruna") + static let DJF: Currency = Currency(code: "DJF", minorUnits: 0, factor: 1, name: "Djibouti Franc") + static let DKK: Currency = Currency(code: "DKK", minorUnits: 2, factor: 100, name: "Danish Krone") + static let DOP: Currency = Currency(code: "DOP", minorUnits: 2, factor: 100, name: "Dominican Peso") + static let DZD: Currency = Currency(code: "DZD", minorUnits: 2, factor: 100, name: "Algerian Dinar") + static let EGP: Currency = Currency(code: "EGP", minorUnits: 2, factor: 100, name: "Egyptian Pound") + static let ERN: Currency = Currency(code: "ERN", minorUnits: 2, factor: 100, name: "Nakfa") + static let ETB: Currency = Currency(code: "ETB", minorUnits: 2, factor: 100, name: "Ethiopian Birr") + static let EUR: Currency = Currency(code: "EUR", minorUnits: 2, factor: 100, name: "Euro") + static let FJD: Currency = Currency(code: "FJD", minorUnits: 2, factor: 100, name: "Fiji Dollar") + static let FKP: Currency = Currency(code: "FKP", minorUnits: 2, factor: 100, name: "Falkland Islands Pound") + static let GBP: Currency = Currency(code: "GBP", minorUnits: 2, factor: 100, name: "Pound Sterling") + static let GEL: Currency = Currency(code: "GEL", minorUnits: 2, factor: 100, name: "Lari") + static let GHS: Currency = Currency(code: "GHS", minorUnits: 2, factor: 100, name: "Ghana Cedi") + static let GIP: Currency = Currency(code: "GIP", minorUnits: 2, factor: 100, name: "Gibraltar Pound") + static let GMD: Currency = Currency(code: "GMD", minorUnits: 2, factor: 100, name: "Dalasi") + static let GNF: Currency = Currency(code: "GNF", minorUnits: 0, factor: 1, name: "Guinean Franc") + static let GTQ: Currency = Currency(code: "GTQ", minorUnits: 2, factor: 100, name: "Quetzal") + static let GYD: Currency = Currency(code: "GYD", minorUnits: 2, factor: 100, name: "Guyana Dollar") + static let HKD: Currency = Currency(code: "HKD", minorUnits: 2, factor: 100, name: "Hong Kong Dollar") + static let HNL: Currency = Currency(code: "HNL", minorUnits: 2, factor: 100, name: "Lempira") + static let HTG: Currency = Currency(code: "HTG", minorUnits: 2, factor: 100, name: "Gourde") + static let HUF: Currency = Currency(code: "HUF", minorUnits: 2, factor: 100, name: "Forint") + static let IDR: Currency = Currency(code: "IDR", minorUnits: 2, factor: 100, name: "Rupiah") + static let ILS: Currency = Currency(code: "ILS", minorUnits: 2, factor: 100, name: "New Israeli Sheqel") + static let INR: Currency = Currency(code: "INR", minorUnits: 2, factor: 100, name: "Indian Rupee") + static let IQD: Currency = Currency(code: "IQD", minorUnits: 3, factor: 1000, name: "Iraqi Dinar") + static let IRR: Currency = Currency(code: "IRR", minorUnits: 2, factor: 100, name: "Iranian Rial") + static let ISK: Currency = Currency(code: "ISK", minorUnits: 0, factor: 1, name: "Iceland Krona") + static let JMD: Currency = Currency(code: "JMD", minorUnits: 2, factor: 100, name: "Jamaican Dollar") + static let JOD: Currency = Currency(code: "JOD", minorUnits: 3, factor: 1000, name: "Jordanian Dinar") + static let JPY: Currency = Currency(code: "JPY", minorUnits: 0, factor: 1, name: "Yen") + static let KES: Currency = Currency(code: "KES", minorUnits: 2, factor: 100, name: "Kenyan Shilling") + static let KGS: Currency = Currency(code: "KGS", minorUnits: 2, factor: 100, name: "Som") + static let KHR: Currency = Currency(code: "KHR", minorUnits: 2, factor: 100, name: "Riel") + static let KMF: Currency = Currency(code: "KMF", minorUnits: 0, factor: 1, name: "Comorian Franc ") + static let KPW: Currency = Currency(code: "KPW", minorUnits: 2, factor: 100, name: "North Korean Won") + static let KRW: Currency = Currency(code: "KRW", minorUnits: 0, factor: 1, name: "Won") + static let KWD: Currency = Currency(code: "KWD", minorUnits: 3, factor: 1000, name: "Kuwaiti Dinar") + static let KYD: Currency = Currency(code: "KYD", minorUnits: 2, factor: 100, name: "Cayman Islands Dollar") + static let KZT: Currency = Currency(code: "KZT", minorUnits: 2, factor: 100, name: "Tenge") + static let LAK: Currency = Currency(code: "LAK", minorUnits: 2, factor: 100, name: "Lao Kip") + static let LBP: Currency = Currency(code: "LBP", minorUnits: 2, factor: 100, name: "Lebanese Pound") + static let LKR: Currency = Currency(code: "LKR", minorUnits: 2, factor: 100, name: "Sri Lanka Rupee") + static let LRD: Currency = Currency(code: "LRD", minorUnits: 2, factor: 100, name: "Liberian Dollar") + static let LSL: Currency = Currency(code: "LSL", minorUnits: 2, factor: 100, name: "Loti") + static let LYD: Currency = Currency(code: "LYD", minorUnits: 3, factor: 1000, name: "Libyan Dinar") + static let MAD: Currency = Currency(code: "MAD", minorUnits: 2, factor: 100, name: "Moroccan Dirham") + static let MDL: Currency = Currency(code: "MDL", minorUnits: 2, factor: 100, name: "Moldovan Leu") + static let MGA: Currency = Currency(code: "MGA", minorUnits: 2, factor: 100, name: "Malagasy Ariary") + static let MKD: Currency = Currency(code: "MKD", minorUnits: 2, factor: 100, name: "Denar") + static let MMK: Currency = Currency(code: "MMK", minorUnits: 2, factor: 100, name: "Kyat") + static let MNT: Currency = Currency(code: "MNT", minorUnits: 2, factor: 100, name: "Tugrik") + static let MOP: Currency = Currency(code: "MOP", minorUnits: 2, factor: 100, name: "Pataca") + static let MRU: Currency = Currency(code: "MRU", minorUnits: 2, factor: 100, name: "Ouguiya") + static let MUR: Currency = Currency(code: "MUR", minorUnits: 2, factor: 100, name: "Mauritius Rupee") + static let MVR: Currency = Currency(code: "MVR", minorUnits: 2, factor: 100, name: "Rufiyaa") + static let MWK: Currency = Currency(code: "MWK", minorUnits: 2, factor: 100, name: "Malawi Kwacha") + static let MXN: Currency = Currency(code: "MXN", minorUnits: 2, factor: 100, name: "Mexican Peso") + static let MXV: Currency = Currency(code: "MXV", minorUnits: 2, factor: 100, name: "Mexican Unidad de Inversion (UDI)") + static let MYR: Currency = Currency(code: "MYR", minorUnits: 2, factor: 100, name: "Malaysian Ringgit") + static let MZN: Currency = Currency(code: "MZN", minorUnits: 2, factor: 100, name: "Mozambique Metical") + static let NAD: Currency = Currency(code: "NAD", minorUnits: 2, factor: 100, name: "Namibia Dollar") + static let NGN: Currency = Currency(code: "NGN", minorUnits: 2, factor: 100, name: "Naira") + static let NIO: Currency = Currency(code: "NIO", minorUnits: 2, factor: 100, name: "Cordoba Oro") + static let NOK: Currency = Currency(code: "NOK", minorUnits: 2, factor: 100, name: "Norwegian Krone") + static let NPR: Currency = Currency(code: "NPR", minorUnits: 2, factor: 100, name: "Nepalese Rupee") + static let NZD: Currency = Currency(code: "NZD", minorUnits: 2, factor: 100, name: "New Zealand Dollar") + static let OMR: Currency = Currency(code: "OMR", minorUnits: 3, factor: 1000, name: "Rial Omani") + static let PAB: Currency = Currency(code: "PAB", minorUnits: 2, factor: 100, name: "Balboa") + static let PEN: Currency = Currency(code: "PEN", minorUnits: 2, factor: 100, name: "Sol") + static let PGK: Currency = Currency(code: "PGK", minorUnits: 2, factor: 100, name: "Kina") + static let PHP: Currency = Currency(code: "PHP", minorUnits: 2, factor: 100, name: "Philippine Peso") + static let PKR: Currency = Currency(code: "PKR", minorUnits: 2, factor: 100, name: "Pakistan Rupee") + static let PLN: Currency = Currency(code: "PLN", minorUnits: 2, factor: 100, name: "Zloty") + static let PYG: Currency = Currency(code: "PYG", minorUnits: 0, factor: 1, name: "Guarani") + static let QAR: Currency = Currency(code: "QAR", minorUnits: 2, factor: 100, name: "Qatari Rial") + static let RON: Currency = Currency(code: "RON", minorUnits: 2, factor: 100, name: "Romanian Leu") + static let RSD: Currency = Currency(code: "RSD", minorUnits: 2, factor: 100, name: "Serbian Dinar") + static let RUB: Currency = Currency(code: "RUB", minorUnits: 2, factor: 100, name: "Russian Ruble") + static let RWF: Currency = Currency(code: "RWF", minorUnits: 0, factor: 1, name: "Rwanda Franc") + static let SAR: Currency = Currency(code: "SAR", minorUnits: 2, factor: 100, name: "Saudi Riyal") + static let SBD: Currency = Currency(code: "SBD", minorUnits: 2, factor: 100, name: "Solomon Islands Dollar") + static let SCR: Currency = Currency(code: "SCR", minorUnits: 2, factor: 100, name: "Seychelles Rupee") + static let SDG: Currency = Currency(code: "SDG", minorUnits: 2, factor: 100, name: "Sudanese Pound") + static let SEK: Currency = Currency(code: "SEK", minorUnits: 2, factor: 100, name: "Swedish Krona") + static let SGD: Currency = Currency(code: "SGD", minorUnits: 2, factor: 100, name: "Singapore Dollar") + static let SHP: Currency = Currency(code: "SHP", minorUnits: 2, factor: 100, name: "Saint Helena Pound") + static let SLE: Currency = Currency(code: "SLE", minorUnits: 2, factor: 100, name: "Leone") + static let SOS: Currency = Currency(code: "SOS", minorUnits: 2, factor: 100, name: "Somali Shilling") + static let SRD: Currency = Currency(code: "SRD", minorUnits: 2, factor: 100, name: "Surinam Dollar") + static let SSP: Currency = Currency(code: "SSP", minorUnits: 2, factor: 100, name: "South Sudanese Pound") + static let STN: Currency = Currency(code: "STN", minorUnits: 2, factor: 100, name: "Dobra") + static let SVC: Currency = Currency(code: "SVC", minorUnits: 2, factor: 100, name: "El Salvador Colon") + static let SYP: Currency = Currency(code: "SYP", minorUnits: 2, factor: 100, name: "Syrian Pound") + static let SZL: Currency = Currency(code: "SZL", minorUnits: 2, factor: 100, name: "Lilangeni") + static let THB: Currency = Currency(code: "THB", minorUnits: 2, factor: 100, name: "Baht") + static let TJS: Currency = Currency(code: "TJS", minorUnits: 2, factor: 100, name: "Somoni") + static let TMT: Currency = Currency(code: "TMT", minorUnits: 2, factor: 100, name: "Turkmenistan New Manat") + static let TND: Currency = Currency(code: "TND", minorUnits: 3, factor: 1000, name: "Tunisian Dinar") + static let TOP: Currency = Currency(code: "TOP", minorUnits: 2, factor: 100, name: "Pa’anga") + static let TRY: Currency = Currency(code: "TRY", minorUnits: 2, factor: 100, name: "Turkish Lira") + static let TTD: Currency = Currency(code: "TTD", minorUnits: 2, factor: 100, name: "Trinidad and Tobago Dollar") + static let TWD: Currency = Currency(code: "TWD", minorUnits: 2, factor: 100, name: "New Taiwan Dollar") + static let TZS: Currency = Currency(code: "TZS", minorUnits: 2, factor: 100, name: "Tanzanian Shilling") + static let UAH: Currency = Currency(code: "UAH", minorUnits: 2, factor: 100, name: "Hryvnia") + static let UGX: Currency = Currency(code: "UGX", minorUnits: 0, factor: 1, name: "Uganda Shilling") + static let USD: Currency = Currency(code: "USD", minorUnits: 2, factor: 100, name: "US Dollar") + static let USN: Currency = Currency(code: "USN", minorUnits: 2, factor: 100, name: "US Dollar (Next day)") + static let UYI: Currency = Currency(code: "UYI", minorUnits: 0, factor: 1, name: "Uruguay Peso en Unidades Indexadas (UI)") + static let UYU: Currency = Currency(code: "UYU", minorUnits: 2, factor: 100, name: "Peso Uruguayo") + static let UYW: Currency = Currency(code: "UYW", minorUnits: 4, factor: 10000, name: "Unidad Previsional") + static let UZS: Currency = Currency(code: "UZS", minorUnits: 2, factor: 100, name: "Uzbekistan Sum") + static let VED: Currency = Currency(code: "VED", minorUnits: 2, factor: 100, name: "Bolívar Soberano") + static let VES: Currency = Currency(code: "VES", minorUnits: 2, factor: 100, name: "Bolívar Soberano") + static let VND: Currency = Currency(code: "VND", minorUnits: 0, factor: 1, name: "Dong") + static let VUV: Currency = Currency(code: "VUV", minorUnits: 0, factor: 1, name: "Vatu") + static let WST: Currency = Currency(code: "WST", minorUnits: 2, factor: 100, name: "Tala") + static let XAF: Currency = Currency(code: "XAF", minorUnits: 0, factor: 1, name: "CFA Franc BEAC") + static let XAG: Currency = Currency(code: "XAG", minorUnits: 0, factor: 1, name: "Silver") + static let XAU: Currency = Currency(code: "XAU", minorUnits: 0, factor: 1, name: "Gold") + static let XBA: Currency = Currency(code: "XBA", minorUnits: 0, factor: 1, name: "Bond Markets Unit European Composite Unit (EURCO)") + static let XBB: Currency = Currency(code: "XBB", minorUnits: 0, factor: 1, name: "Bond Markets Unit European Monetary Unit (E.M.U.-6)") + static let XBC: Currency = Currency(code: "XBC", minorUnits: 0, factor: 1, name: "Bond Markets Unit European Unit of Account 9 (E.U.A.-9)") + static let XBD: Currency = Currency(code: "XBD", minorUnits: 0, factor: 1, name: "Bond Markets Unit European Unit of Account 17 (E.U.A.-17)") + static let XCD: Currency = Currency(code: "XCD", minorUnits: 2, factor: 100, name: "East Caribbean Dollar") + static let XDR: Currency = Currency(code: "XDR", minorUnits: 0, factor: 1, name: "SDR (Special Drawing Right)") + static let XOF: Currency = Currency(code: "XOF", minorUnits: 0, factor: 1, name: "CFA Franc BCEAO") + static let XPD: Currency = Currency(code: "XPD", minorUnits: 0, factor: 1, name: "Palladium") + static let XPF: Currency = Currency(code: "XPF", minorUnits: 0, factor: 1, name: "CFP Franc") + static let XPT: Currency = Currency(code: "XPT", minorUnits: 0, factor: 1, name: "Platinum") + static let XSU: Currency = Currency(code: "XSU", minorUnits: 0, factor: 1, name: "Sucre") + static let XTS: Currency = Currency(code: "XTS", minorUnits: 0, factor: 1, name: "Codes specifically reserved for testing purposes") + static let XUA: Currency = Currency(code: "XUA", minorUnits: 0, factor: 1, name: "ADB Unit of Account") + static let XXX: Currency = Currency(code: "XXX", minorUnits: 0, factor: 1, name: "The codes assigned for transactions where no currency is involved") + static let YER: Currency = Currency(code: "YER", minorUnits: 2, factor: 100, name: "Yemeni Rial") + static let ZAR: Currency = Currency(code: "ZAR", minorUnits: 2, factor: 100, name: "Rand") + static let ZMW: Currency = Currency(code: "ZMW", minorUnits: 2, factor: 100, name: "Zambian Kwacha") + static let ZWG: Currency = Currency(code: "ZWG", minorUnits: 2, factor: 100, name: "Zimbabwe Gold") + + + static let allCurrencies: [String: Currency] = + [ + "AED": AED, + "AFN": AFN, + "ALL": ALL, + "AMD": AMD, + "ANG": ANG, + "AOA": AOA, + "ARS": ARS, + "AUD": AUD, + "AWG": AWG, + "AZN": AZN, + "BAM": BAM, + "BBD": BBD, + "BDT": BDT, + "BGN": BGN, + "BHD": BHD, + "BIF": BIF, + "BMD": BMD, + "BND": BND, + "BOB": BOB, + "BOV": BOV, + "BRL": BRL, + "BSD": BSD, + "BTN": BTN, + "BWP": BWP, + "BYN": BYN, + "BZD": BZD, + "CAD": CAD, + "CDF": CDF, + "CHE": CHE, + "CHF": CHF, + "CHW": CHW, + "CLF": CLF, + "CLP": CLP, + "CNY": CNY, + "COP": COP, + "COU": COU, + "CRC": CRC, + "CUC": CUC, + "CUP": CUP, + "CVE": CVE, + "CZK": CZK, + "DJF": DJF, + "DKK": DKK, + "DOP": DOP, + "DZD": DZD, + "EGP": EGP, + "ERN": ERN, + "ETB": ETB, + "EUR": EUR, + "FJD": FJD, + "FKP": FKP, + "GBP": GBP, + "GEL": GEL, + "GHS": GHS, + "GIP": GIP, + "GMD": GMD, + "GNF": GNF, + "GTQ": GTQ, + "GYD": GYD, + "HKD": HKD, + "HNL": HNL, + "HTG": HTG, + "HUF": HUF, + "IDR": IDR, + "ILS": ILS, + "INR": INR, + "IQD": IQD, + "IRR": IRR, + "ISK": ISK, + "JMD": JMD, + "JOD": JOD, + "JPY": JPY, + "KES": KES, + "KGS": KGS, + "KHR": KHR, + "KMF": KMF, + "KPW": KPW, + "KRW": KRW, + "KWD": KWD, + "KYD": KYD, + "KZT": KZT, + "LAK": LAK, + "LBP": LBP, + "LKR": LKR, + "LRD": LRD, + "LSL": LSL, + "LYD": LYD, + "MAD": MAD, + "MDL": MDL, + "MGA": MGA, + "MKD": MKD, + "MMK": MMK, + "MNT": MNT, + "MOP": MOP, + "MRU": MRU, + "MUR": MUR, + "MVR": MVR, + "MWK": MWK, + "MXN": MXN, + "MXV": MXV, + "MYR": MYR, + "MZN": MZN, + "NAD": NAD, + "NGN": NGN, + "NIO": NIO, + "NOK": NOK, + "NPR": NPR, + "NZD": NZD, + "OMR": OMR, + "PAB": PAB, + "PEN": PEN, + "PGK": PGK, + "PHP": PHP, + "PKR": PKR, + "PLN": PLN, + "PYG": PYG, + "QAR": QAR, + "RON": RON, + "RSD": RSD, + "RUB": RUB, + "RWF": RWF, + "SAR": SAR, + "SBD": SBD, + "SCR": SCR, + "SDG": SDG, + "SEK": SEK, + "SGD": SGD, + "SHP": SHP, + "SLE": SLE, + "SOS": SOS, + "SRD": SRD, + "SSP": SSP, + "STN": STN, + "SVC": SVC, + "SYP": SYP, + "SZL": SZL, + "THB": THB, + "TJS": TJS, + "TMT": TMT, + "TND": TND, + "TOP": TOP, + "TRY": TRY, + "TTD": TTD, + "TWD": TWD, + "TZS": TZS, + "UAH": UAH, + "UGX": UGX, + "USD": USD, + "USN": USN, + "UYI": UYI, + "UYU": UYU, + "UYW": UYW, + "UZS": UZS, + "VED": VED, + "VES": VES, + "VND": VND, + "VUV": VUV, + "WST": WST, + "XAF": XAF, + "XAG": XAG, + "XAU": XAU, + "XBA": XBA, + "XBB": XBB, + "XBC": XBC, + "XBD": XBD, + "XCD": XCD, + "XDR": XDR, + "XOF": XOF, + "XPD": XPD, + "XPF": XPF, + "XPT": XPT, + "XSU": XSU, + "XTS": XTS, + "XUA": XUA, + "XXX": XXX, + "YER": YER, + "ZAR": ZAR, + "ZMW": ZMW, + "ZWG": ZWG + ] + + /// Look up a currency struct containing currency and formatting information + /// + /// - Parameter code: The `ISO 4217` currency code to search for + /// - Returns: A `Currency` object, if supported. Otherwise nil. + class func currency(for code: String) -> Currency? { + return allCurrencies[code] + } +} diff --git a/v2/std_currency.js b/v2/std_currency.js new file mode 100644 index 0000000..0ac5916 --- /dev/null +++ b/v2/std_currency.js @@ -0,0 +1,360 @@ +var stdCurrency = { + // AED currency object + AED: { code: "AED", name: "UAE Dirham", minorUnits: 2, factor: 100, name: "UAE Dirham"}, + // AFN currency object + AFN: { code: "AFN", name: "Afghani", minorUnits: 2, factor: 100, name: "Afghani"}, + // ALL currency object + ALL: { code: "ALL", name: "Lek", minorUnits: 2, factor: 100, name: "Lek"}, + // AMD currency object + AMD: { code: "AMD", name: "Armenian Dram", minorUnits: 2, factor: 100, name: "Armenian Dram"}, + // ANG currency object + ANG: { code: "ANG", name: "Netherlands Antillean Guilder", minorUnits: 2, factor: 100, name: "Netherlands Antillean Guilder"}, + // AOA currency object + AOA: { code: "AOA", name: "Kwanza", minorUnits: 2, factor: 100, name: "Kwanza"}, + // ARS currency object + ARS: { code: "ARS", name: "Argentine Peso", minorUnits: 2, factor: 100, name: "Argentine Peso"}, + // AUD currency object + AUD: { code: "AUD", name: "Australian Dollar", minorUnits: 2, factor: 100, name: "Australian Dollar"}, + // AWG currency object + AWG: { code: "AWG", name: "Aruban Florin", minorUnits: 2, factor: 100, name: "Aruban Florin"}, + // AZN currency object + AZN: { code: "AZN", name: "Azerbaijan Manat", minorUnits: 2, factor: 100, name: "Azerbaijan Manat"}, + // BAM currency object + BAM: { code: "BAM", name: "Convertible Mark", minorUnits: 2, factor: 100, name: "Convertible Mark"}, + // BBD currency object + BBD: { code: "BBD", name: "Barbados Dollar", minorUnits: 2, factor: 100, name: "Barbados Dollar"}, + // BDT currency object + BDT: { code: "BDT", name: "Taka", minorUnits: 2, factor: 100, name: "Taka"}, + // BGN currency object + BGN: { code: "BGN", name: "Bulgarian Lev", minorUnits: 2, factor: 100, name: "Bulgarian Lev"}, + // BHD currency object + BHD: { code: "BHD", name: "Bahraini Dinar", minorUnits: 3, factor: 1000, name: "Bahraini Dinar"}, + // BIF currency object + BIF: { code: "BIF", name: "Burundi Franc", minorUnits: 0, factor: 1, name: "Burundi Franc"}, + // BMD currency object + BMD: { code: "BMD", name: "Bermudian Dollar", minorUnits: 2, factor: 100, name: "Bermudian Dollar"}, + // BND currency object + BND: { code: "BND", name: "Brunei Dollar", minorUnits: 2, factor: 100, name: "Brunei Dollar"}, + // BOB currency object + BOB: { code: "BOB", name: "Boliviano", minorUnits: 2, factor: 100, name: "Boliviano"}, + // BOV currency object + BOV: { code: "BOV", name: "Mvdol", minorUnits: 2, factor: 100, name: "Mvdol"}, + // BRL currency object + BRL: { code: "BRL", name: "Brazilian Real", minorUnits: 2, factor: 100, name: "Brazilian Real"}, + // BSD currency object + BSD: { code: "BSD", name: "Bahamian Dollar", minorUnits: 2, factor: 100, name: "Bahamian Dollar"}, + // BTN currency object + BTN: { code: "BTN", name: "Ngultrum", minorUnits: 2, factor: 100, name: "Ngultrum"}, + // BWP currency object + BWP: { code: "BWP", name: "Pula", minorUnits: 2, factor: 100, name: "Pula"}, + // BYN currency object + BYN: { code: "BYN", name: "Belarusian Ruble", minorUnits: 2, factor: 100, name: "Belarusian Ruble"}, + // BZD currency object + BZD: { code: "BZD", name: "Belize Dollar", minorUnits: 2, factor: 100, name: "Belize Dollar"}, + // CAD currency object + CAD: { code: "CAD", name: "Canadian Dollar", minorUnits: 2, factor: 100, name: "Canadian Dollar"}, + // CDF currency object + CDF: { code: "CDF", name: "Congolese Franc", minorUnits: 2, factor: 100, name: "Congolese Franc"}, + // CHE currency object + CHE: { code: "CHE", name: "WIR Euro", minorUnits: 2, factor: 100, name: "WIR Euro"}, + // CHF currency object + CHF: { code: "CHF", name: "Swiss Franc", minorUnits: 2, factor: 100, name: "Swiss Franc"}, + // CHW currency object + CHW: { code: "CHW", name: "WIR Franc", minorUnits: 2, factor: 100, name: "WIR Franc"}, + // CLF currency object + CLF: { code: "CLF", name: "Unidad de Fomento", minorUnits: 4, factor: 10000, name: "Unidad de Fomento"}, + // CLP currency object + CLP: { code: "CLP", name: "Chilean Peso", minorUnits: 0, factor: 1, name: "Chilean Peso"}, + // CNY currency object + CNY: { code: "CNY", name: "Yuan Renminbi", minorUnits: 2, factor: 100, name: "Yuan Renminbi"}, + // COP currency object + COP: { code: "COP", name: "Colombian Peso", minorUnits: 2, factor: 100, name: "Colombian Peso"}, + // COU currency object + COU: { code: "COU", name: "Unidad de Valor Real", minorUnits: 2, factor: 100, name: "Unidad de Valor Real"}, + // CRC currency object + CRC: { code: "CRC", name: "Costa Rican Colon", minorUnits: 2, factor: 100, name: "Costa Rican Colon"}, + // CUC currency object + CUC: { code: "CUC", name: "Peso Convertible", minorUnits: 2, factor: 100, name: "Peso Convertible"}, + // CUP currency object + CUP: { code: "CUP", name: "Cuban Peso", minorUnits: 2, factor: 100, name: "Cuban Peso"}, + // CVE currency object + CVE: { code: "CVE", name: "Cabo Verde Escudo", minorUnits: 2, factor: 100, name: "Cabo Verde Escudo"}, + // CZK currency object + CZK: { code: "CZK", name: "Czech Koruna", minorUnits: 2, factor: 100, name: "Czech Koruna"}, + // DJF currency object + DJF: { code: "DJF", name: "Djibouti Franc", minorUnits: 0, factor: 1, name: "Djibouti Franc"}, + // DKK currency object + DKK: { code: "DKK", name: "Danish Krone", minorUnits: 2, factor: 100, name: "Danish Krone"}, + // DOP currency object + DOP: { code: "DOP", name: "Dominican Peso", minorUnits: 2, factor: 100, name: "Dominican Peso"}, + // DZD currency object + DZD: { code: "DZD", name: "Algerian Dinar", minorUnits: 2, factor: 100, name: "Algerian Dinar"}, + // EGP currency object + EGP: { code: "EGP", name: "Egyptian Pound", minorUnits: 2, factor: 100, name: "Egyptian Pound"}, + // ERN currency object + ERN: { code: "ERN", name: "Nakfa", minorUnits: 2, factor: 100, name: "Nakfa"}, + // ETB currency object + ETB: { code: "ETB", name: "Ethiopian Birr", minorUnits: 2, factor: 100, name: "Ethiopian Birr"}, + // EUR currency object + EUR: { code: "EUR", name: "Euro", minorUnits: 2, factor: 100, name: "Euro"}, + // FJD currency object + FJD: { code: "FJD", name: "Fiji Dollar", minorUnits: 2, factor: 100, name: "Fiji Dollar"}, + // FKP currency object + FKP: { code: "FKP", name: "Falkland Islands Pound", minorUnits: 2, factor: 100, name: "Falkland Islands Pound"}, + // GBP currency object + GBP: { code: "GBP", name: "Pound Sterling", minorUnits: 2, factor: 100, name: "Pound Sterling"}, + // GEL currency object + GEL: { code: "GEL", name: "Lari", minorUnits: 2, factor: 100, name: "Lari"}, + // GHS currency object + GHS: { code: "GHS", name: "Ghana Cedi", minorUnits: 2, factor: 100, name: "Ghana Cedi"}, + // GIP currency object + GIP: { code: "GIP", name: "Gibraltar Pound", minorUnits: 2, factor: 100, name: "Gibraltar Pound"}, + // GMD currency object + GMD: { code: "GMD", name: "Dalasi", minorUnits: 2, factor: 100, name: "Dalasi"}, + // GNF currency object + GNF: { code: "GNF", name: "Guinean Franc", minorUnits: 0, factor: 1, name: "Guinean Franc"}, + // GTQ currency object + GTQ: { code: "GTQ", name: "Quetzal", minorUnits: 2, factor: 100, name: "Quetzal"}, + // GYD currency object + GYD: { code: "GYD", name: "Guyana Dollar", minorUnits: 2, factor: 100, name: "Guyana Dollar"}, + // HKD currency object + HKD: { code: "HKD", name: "Hong Kong Dollar", minorUnits: 2, factor: 100, name: "Hong Kong Dollar"}, + // HNL currency object + HNL: { code: "HNL", name: "Lempira", minorUnits: 2, factor: 100, name: "Lempira"}, + // HTG currency object + HTG: { code: "HTG", name: "Gourde", minorUnits: 2, factor: 100, name: "Gourde"}, + // HUF currency object + HUF: { code: "HUF", name: "Forint", minorUnits: 2, factor: 100, name: "Forint"}, + // IDR currency object + IDR: { code: "IDR", name: "Rupiah", minorUnits: 2, factor: 100, name: "Rupiah"}, + // ILS currency object + ILS: { code: "ILS", name: "New Israeli Sheqel", minorUnits: 2, factor: 100, name: "New Israeli Sheqel"}, + // INR currency object + INR: { code: "INR", name: "Indian Rupee", minorUnits: 2, factor: 100, name: "Indian Rupee"}, + // IQD currency object + IQD: { code: "IQD", name: "Iraqi Dinar", minorUnits: 3, factor: 1000, name: "Iraqi Dinar"}, + // IRR currency object + IRR: { code: "IRR", name: "Iranian Rial", minorUnits: 2, factor: 100, name: "Iranian Rial"}, + // ISK currency object + ISK: { code: "ISK", name: "Iceland Krona", minorUnits: 0, factor: 1, name: "Iceland Krona"}, + // JMD currency object + JMD: { code: "JMD", name: "Jamaican Dollar", minorUnits: 2, factor: 100, name: "Jamaican Dollar"}, + // JOD currency object + JOD: { code: "JOD", name: "Jordanian Dinar", minorUnits: 3, factor: 1000, name: "Jordanian Dinar"}, + // JPY currency object + JPY: { code: "JPY", name: "Yen", minorUnits: 0, factor: 1, name: "Yen"}, + // KES currency object + KES: { code: "KES", name: "Kenyan Shilling", minorUnits: 2, factor: 100, name: "Kenyan Shilling"}, + // KGS currency object + KGS: { code: "KGS", name: "Som", minorUnits: 2, factor: 100, name: "Som"}, + // KHR currency object + KHR: { code: "KHR", name: "Riel", minorUnits: 2, factor: 100, name: "Riel"}, + // KMF currency object + KMF: { code: "KMF", name: "Comorian Franc ", minorUnits: 0, factor: 1, name: "Comorian Franc "}, + // KPW currency object + KPW: { code: "KPW", name: "North Korean Won", minorUnits: 2, factor: 100, name: "North Korean Won"}, + // KRW currency object + KRW: { code: "KRW", name: "Won", minorUnits: 0, factor: 1, name: "Won"}, + // KWD currency object + KWD: { code: "KWD", name: "Kuwaiti Dinar", minorUnits: 3, factor: 1000, name: "Kuwaiti Dinar"}, + // KYD currency object + KYD: { code: "KYD", name: "Cayman Islands Dollar", minorUnits: 2, factor: 100, name: "Cayman Islands Dollar"}, + // KZT currency object + KZT: { code: "KZT", name: "Tenge", minorUnits: 2, factor: 100, name: "Tenge"}, + // LAK currency object + LAK: { code: "LAK", name: "Lao Kip", minorUnits: 2, factor: 100, name: "Lao Kip"}, + // LBP currency object + LBP: { code: "LBP", name: "Lebanese Pound", minorUnits: 2, factor: 100, name: "Lebanese Pound"}, + // LKR currency object + LKR: { code: "LKR", name: "Sri Lanka Rupee", minorUnits: 2, factor: 100, name: "Sri Lanka Rupee"}, + // LRD currency object + LRD: { code: "LRD", name: "Liberian Dollar", minorUnits: 2, factor: 100, name: "Liberian Dollar"}, + // LSL currency object + LSL: { code: "LSL", name: "Loti", minorUnits: 2, factor: 100, name: "Loti"}, + // LYD currency object + LYD: { code: "LYD", name: "Libyan Dinar", minorUnits: 3, factor: 1000, name: "Libyan Dinar"}, + // MAD currency object + MAD: { code: "MAD", name: "Moroccan Dirham", minorUnits: 2, factor: 100, name: "Moroccan Dirham"}, + // MDL currency object + MDL: { code: "MDL", name: "Moldovan Leu", minorUnits: 2, factor: 100, name: "Moldovan Leu"}, + // MGA currency object + MGA: { code: "MGA", name: "Malagasy Ariary", minorUnits: 2, factor: 100, name: "Malagasy Ariary"}, + // MKD currency object + MKD: { code: "MKD", name: "Denar", minorUnits: 2, factor: 100, name: "Denar"}, + // MMK currency object + MMK: { code: "MMK", name: "Kyat", minorUnits: 2, factor: 100, name: "Kyat"}, + // MNT currency object + MNT: { code: "MNT", name: "Tugrik", minorUnits: 2, factor: 100, name: "Tugrik"}, + // MOP currency object + MOP: { code: "MOP", name: "Pataca", minorUnits: 2, factor: 100, name: "Pataca"}, + // MRU currency object + MRU: { code: "MRU", name: "Ouguiya", minorUnits: 2, factor: 100, name: "Ouguiya"}, + // MUR currency object + MUR: { code: "MUR", name: "Mauritius Rupee", minorUnits: 2, factor: 100, name: "Mauritius Rupee"}, + // MVR currency object + MVR: { code: "MVR", name: "Rufiyaa", minorUnits: 2, factor: 100, name: "Rufiyaa"}, + // MWK currency object + MWK: { code: "MWK", name: "Malawi Kwacha", minorUnits: 2, factor: 100, name: "Malawi Kwacha"}, + // MXN currency object + MXN: { code: "MXN", name: "Mexican Peso", minorUnits: 2, factor: 100, name: "Mexican Peso"}, + // MXV currency object + MXV: { code: "MXV", name: "Mexican Unidad de Inversion (UDI)", minorUnits: 2, factor: 100, name: "Mexican Unidad de Inversion (UDI)"}, + // MYR currency object + MYR: { code: "MYR", name: "Malaysian Ringgit", minorUnits: 2, factor: 100, name: "Malaysian Ringgit"}, + // MZN currency object + MZN: { code: "MZN", name: "Mozambique Metical", minorUnits: 2, factor: 100, name: "Mozambique Metical"}, + // NAD currency object + NAD: { code: "NAD", name: "Namibia Dollar", minorUnits: 2, factor: 100, name: "Namibia Dollar"}, + // NGN currency object + NGN: { code: "NGN", name: "Naira", minorUnits: 2, factor: 100, name: "Naira"}, + // NIO currency object + NIO: { code: "NIO", name: "Cordoba Oro", minorUnits: 2, factor: 100, name: "Cordoba Oro"}, + // NOK currency object + NOK: { code: "NOK", name: "Norwegian Krone", minorUnits: 2, factor: 100, name: "Norwegian Krone"}, + // NPR currency object + NPR: { code: "NPR", name: "Nepalese Rupee", minorUnits: 2, factor: 100, name: "Nepalese Rupee"}, + // NZD currency object + NZD: { code: "NZD", name: "New Zealand Dollar", minorUnits: 2, factor: 100, name: "New Zealand Dollar"}, + // OMR currency object + OMR: { code: "OMR", name: "Rial Omani", minorUnits: 3, factor: 1000, name: "Rial Omani"}, + // PAB currency object + PAB: { code: "PAB", name: "Balboa", minorUnits: 2, factor: 100, name: "Balboa"}, + // PEN currency object + PEN: { code: "PEN", name: "Sol", minorUnits: 2, factor: 100, name: "Sol"}, + // PGK currency object + PGK: { code: "PGK", name: "Kina", minorUnits: 2, factor: 100, name: "Kina"}, + // PHP currency object + PHP: { code: "PHP", name: "Philippine Peso", minorUnits: 2, factor: 100, name: "Philippine Peso"}, + // PKR currency object + PKR: { code: "PKR", name: "Pakistan Rupee", minorUnits: 2, factor: 100, name: "Pakistan Rupee"}, + // PLN currency object + PLN: { code: "PLN", name: "Zloty", minorUnits: 2, factor: 100, name: "Zloty"}, + // PYG currency object + PYG: { code: "PYG", name: "Guarani", minorUnits: 0, factor: 1, name: "Guarani"}, + // QAR currency object + QAR: { code: "QAR", name: "Qatari Rial", minorUnits: 2, factor: 100, name: "Qatari Rial"}, + // RON currency object + RON: { code: "RON", name: "Romanian Leu", minorUnits: 2, factor: 100, name: "Romanian Leu"}, + // RSD currency object + RSD: { code: "RSD", name: "Serbian Dinar", minorUnits: 2, factor: 100, name: "Serbian Dinar"}, + // RUB currency object + RUB: { code: "RUB", name: "Russian Ruble", minorUnits: 2, factor: 100, name: "Russian Ruble"}, + // RWF currency object + RWF: { code: "RWF", name: "Rwanda Franc", minorUnits: 0, factor: 1, name: "Rwanda Franc"}, + // SAR currency object + SAR: { code: "SAR", name: "Saudi Riyal", minorUnits: 2, factor: 100, name: "Saudi Riyal"}, + // SBD currency object + SBD: { code: "SBD", name: "Solomon Islands Dollar", minorUnits: 2, factor: 100, name: "Solomon Islands Dollar"}, + // SCR currency object + SCR: { code: "SCR", name: "Seychelles Rupee", minorUnits: 2, factor: 100, name: "Seychelles Rupee"}, + // SDG currency object + SDG: { code: "SDG", name: "Sudanese Pound", minorUnits: 2, factor: 100, name: "Sudanese Pound"}, + // SEK currency object + SEK: { code: "SEK", name: "Swedish Krona", minorUnits: 2, factor: 100, name: "Swedish Krona"}, + // SGD currency object + SGD: { code: "SGD", name: "Singapore Dollar", minorUnits: 2, factor: 100, name: "Singapore Dollar"}, + // SHP currency object + SHP: { code: "SHP", name: "Saint Helena Pound", minorUnits: 2, factor: 100, name: "Saint Helena Pound"}, + // SLE currency object + SLE: { code: "SLE", name: "Leone", minorUnits: 2, factor: 100, name: "Leone"}, + // SOS currency object + SOS: { code: "SOS", name: "Somali Shilling", minorUnits: 2, factor: 100, name: "Somali Shilling"}, + // SRD currency object + SRD: { code: "SRD", name: "Surinam Dollar", minorUnits: 2, factor: 100, name: "Surinam Dollar"}, + // SSP currency object + SSP: { code: "SSP", name: "South Sudanese Pound", minorUnits: 2, factor: 100, name: "South Sudanese Pound"}, + // STN currency object + STN: { code: "STN", name: "Dobra", minorUnits: 2, factor: 100, name: "Dobra"}, + // SVC currency object + SVC: { code: "SVC", name: "El Salvador Colon", minorUnits: 2, factor: 100, name: "El Salvador Colon"}, + // SYP currency object + SYP: { code: "SYP", name: "Syrian Pound", minorUnits: 2, factor: 100, name: "Syrian Pound"}, + // SZL currency object + SZL: { code: "SZL", name: "Lilangeni", minorUnits: 2, factor: 100, name: "Lilangeni"}, + // THB currency object + THB: { code: "THB", name: "Baht", minorUnits: 2, factor: 100, name: "Baht"}, + // TJS currency object + TJS: { code: "TJS", name: "Somoni", minorUnits: 2, factor: 100, name: "Somoni"}, + // TMT currency object + TMT: { code: "TMT", name: "Turkmenistan New Manat", minorUnits: 2, factor: 100, name: "Turkmenistan New Manat"}, + // TND currency object + TND: { code: "TND", name: "Tunisian Dinar", minorUnits: 3, factor: 1000, name: "Tunisian Dinar"}, + // TOP currency object + TOP: { code: "TOP", name: "Pa’anga", minorUnits: 2, factor: 100, name: "Pa’anga"}, + // TRY currency object + TRY: { code: "TRY", name: "Turkish Lira", minorUnits: 2, factor: 100, name: "Turkish Lira"}, + // TTD currency object + TTD: { code: "TTD", name: "Trinidad and Tobago Dollar", minorUnits: 2, factor: 100, name: "Trinidad and Tobago Dollar"}, + // TWD currency object + TWD: { code: "TWD", name: "New Taiwan Dollar", minorUnits: 2, factor: 100, name: "New Taiwan Dollar"}, + // TZS currency object + TZS: { code: "TZS", name: "Tanzanian Shilling", minorUnits: 2, factor: 100, name: "Tanzanian Shilling"}, + // UAH currency object + UAH: { code: "UAH", name: "Hryvnia", minorUnits: 2, factor: 100, name: "Hryvnia"}, + // UGX currency object + UGX: { code: "UGX", name: "Uganda Shilling", minorUnits: 0, factor: 1, name: "Uganda Shilling"}, + // USD currency object + USD: { code: "USD", name: "US Dollar", minorUnits: 2, factor: 100, name: "US Dollar"}, + // USN currency object + USN: { code: "USN", name: "US Dollar (Next day)", minorUnits: 2, factor: 100, name: "US Dollar (Next day)"}, + // UYI currency object + UYI: { code: "UYI", name: "Uruguay Peso en Unidades Indexadas (UI)", minorUnits: 0, factor: 1, name: "Uruguay Peso en Unidades Indexadas (UI)"}, + // UYU currency object + UYU: { code: "UYU", name: "Peso Uruguayo", minorUnits: 2, factor: 100, name: "Peso Uruguayo"}, + // UYW currency object + UYW: { code: "UYW", name: "Unidad Previsional", minorUnits: 4, factor: 10000, name: "Unidad Previsional"}, + // UZS currency object + UZS: { code: "UZS", name: "Uzbekistan Sum", minorUnits: 2, factor: 100, name: "Uzbekistan Sum"}, + // VED currency object + VED: { code: "VED", name: "Bolívar Soberano", minorUnits: 2, factor: 100, name: "Bolívar Soberano"}, + // VES currency object + VES: { code: "VES", name: "Bolívar Soberano", minorUnits: 2, factor: 100, name: "Bolívar Soberano"}, + // VND currency object + VND: { code: "VND", name: "Dong", minorUnits: 0, factor: 1, name: "Dong"}, + // VUV currency object + VUV: { code: "VUV", name: "Vatu", minorUnits: 0, factor: 1, name: "Vatu"}, + // WST currency object + WST: { code: "WST", name: "Tala", minorUnits: 2, factor: 100, name: "Tala"}, + // XAF currency object + XAF: { code: "XAF", name: "CFA Franc BEAC", minorUnits: 0, factor: 1, name: "CFA Franc BEAC"}, + // XAG currency object + XAG: { code: "XAG", name: "Silver", minorUnits: 0, factor: 1, name: "Silver"}, + // XAU currency object + XAU: { code: "XAU", name: "Gold", minorUnits: 0, factor: 1, name: "Gold"}, + // XBA currency object + XBA: { code: "XBA", name: "Bond Markets Unit European Composite Unit (EURCO)", minorUnits: 0, factor: 1, name: "Bond Markets Unit European Composite Unit (EURCO)"}, + // XBB currency object + XBB: { code: "XBB", name: "Bond Markets Unit European Monetary Unit (E.M.U.-6)", minorUnits: 0, factor: 1, name: "Bond Markets Unit European Monetary Unit (E.M.U.-6)"}, + // XBC currency object + XBC: { code: "XBC", name: "Bond Markets Unit European Unit of Account 9 (E.U.A.-9)", minorUnits: 0, factor: 1, name: "Bond Markets Unit European Unit of Account 9 (E.U.A.-9)"}, + // XBD currency object + XBD: { code: "XBD", name: "Bond Markets Unit European Unit of Account 17 (E.U.A.-17)", minorUnits: 0, factor: 1, name: "Bond Markets Unit European Unit of Account 17 (E.U.A.-17)"}, + // XCD currency object + XCD: { code: "XCD", name: "East Caribbean Dollar", minorUnits: 2, factor: 100, name: "East Caribbean Dollar"}, + // XDR currency object + XDR: { code: "XDR", name: "SDR (Special Drawing Right)", minorUnits: 0, factor: 1, name: "SDR (Special Drawing Right)"}, + // XOF currency object + XOF: { code: "XOF", name: "CFA Franc BCEAO", minorUnits: 0, factor: 1, name: "CFA Franc BCEAO"}, + // XPD currency object + XPD: { code: "XPD", name: "Palladium", minorUnits: 0, factor: 1, name: "Palladium"}, + // XPF currency object + XPF: { code: "XPF", name: "CFP Franc", minorUnits: 0, factor: 1, name: "CFP Franc"}, + // XPT currency object + XPT: { code: "XPT", name: "Platinum", minorUnits: 0, factor: 1, name: "Platinum"}, + // XSU currency object + XSU: { code: "XSU", name: "Sucre", minorUnits: 0, factor: 1, name: "Sucre"}, + // XTS currency object + XTS: { code: "XTS", name: "Codes specifically reserved for testing purposes", minorUnits: 0, factor: 1, name: "Codes specifically reserved for testing purposes"}, + // XUA currency object + XUA: { code: "XUA", name: "ADB Unit of Account", minorUnits: 0, factor: 1, name: "ADB Unit of Account"}, + // XXX currency object + XXX: { code: "XXX", name: "The codes assigned for transactions where no currency is involved", minorUnits: 0, factor: 1, name: "The codes assigned for transactions where no currency is involved"}, + // YER currency object + YER: { code: "YER", name: "Yemeni Rial", minorUnits: 2, factor: 100, name: "Yemeni Rial"}, + // ZAR currency object + ZAR: { code: "ZAR", name: "Rand", minorUnits: 2, factor: 100, name: "Rand"}, + // ZMW currency object + ZMW: { code: "ZMW", name: "Zambian Kwacha", minorUnits: 2, factor: 100, name: "Zambian Kwacha"}, + // ZWG currency object + ZWG: { code: "ZWG", name: "Zimbabwe Gold", minorUnits: 2, factor: 100, name: "Zimbabwe Gold"} + };