Skip to content

Commit

Permalink
feat: provide currency names
Browse files Browse the repository at this point in the history
  • Loading branch information
ladydascalie committed Jun 29, 2024
1 parent a6eb201 commit 1f727cc
Show file tree
Hide file tree
Showing 8 changed files with 742 additions and 728 deletions.
2 changes: 1 addition & 1 deletion cmd/js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ 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}}}{{if eq (inc $k) $n}}{{else}}{{if $k}},{{end}}{{if eq $k 0}},{{end}}{{end}}
{{$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 -}}
};
6 changes: 3 additions & 3 deletions cmd/kotlin.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
data class Currency(val currencyCode: String, val minorUnits: Int, val factor: Int) {
data class Currency(val currencyCode: String, val minorUnits: Int, val factor: Int, val name: String) {
companion object {
val currencyMap = mapOf<String, Currency>(
{{- $n := len . }}
{{ range $k, $v := . -}}
"{{$v.Code}}" to Currency("{{$v.Code}}", {{$v.Units}}, {{$v.Factor}}){{if eq (inc $k) $n}}{{else}}{{if $k}},{{end}}{{if eq $k 0}},{{end}}{{end}}
"{{$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 -}}
)
}
}
}
6 changes: 5 additions & 1 deletion cmd/std.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Currency struct {
code string
minorUnits int
factor int
name string
}

// Code returns the currency code to the user
Expand All @@ -22,6 +23,9 @@ 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
//
Expand Down Expand Up @@ -63,7 +67,7 @@ func Valid(code string) bool {
var (
{{ range $k, $v := . -}}
// {{$v.Code}} currency struct
{{$v.Code}} = Currency{ code: "{{$v.Code}}", minorUnits: {{$v.Units}}, factor: {{$v.Factor}}}
{{$v.Code}} = Currency{ code: "{{$v.Code}}", minorUnits: {{$v.Units}}, factor: {{$v.Factor}}, name: "{{$v.Name}}"}
{{ end }}
)

Expand Down
5 changes: 4 additions & 1 deletion cmd/swift.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ struct Currency {

/// 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}})
static let {{$v.Code}}: Currency = Currency(code: "{{$v.Code}}", minorUnits: {{$v.Units}}, factor: {{$v.Factor}}, name: "{{$v.Name}}")
{{ end }}

static let allCurrencies: [String: Currency] =
Expand Down
364 changes: 184 additions & 180 deletions std.go

Large diffs are not rendered by default.

364 changes: 182 additions & 182 deletions std.kt

Large diffs are not rendered by default.

363 changes: 183 additions & 180 deletions std.swift

Large diffs are not rendered by default.

360 changes: 180 additions & 180 deletions std_currency.js

Large diffs are not rendered by default.

0 comments on commit 1f727cc

Please sign in to comment.