@formatjs/ecma376 0.3.2 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BUILD +71 -0
- package/CHANGELOG.md +46 -0
- package/LICENSE.md +0 -0
- package/README.md +0 -0
- package/index.ts +33 -0
- package/package.json +6 -6
- package/tests/index.test.ts +78 -0
- package/tsconfig.json +5 -0
- package/index.d.ts +0 -2
- package/index.d.ts.map +0 -1
- package/index.js +0 -33
- package/lib/index.d.ts +0 -2
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -29
package/BUILD
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
|
|
2
|
+
load("@aspect_rules_js//npm/private:npm_package.bzl", "npm_package")
|
|
3
|
+
load("//tools:index.bzl", "check_format", "package_json_test", "ts_compile")
|
|
4
|
+
load("//tools:jest.bzl", "jest_test")
|
|
5
|
+
|
|
6
|
+
exports_files([
|
|
7
|
+
"package.json",
|
|
8
|
+
"tsconfig.json",
|
|
9
|
+
])
|
|
10
|
+
|
|
11
|
+
PACKAGE_NAME = "ecma376"
|
|
12
|
+
|
|
13
|
+
npm_package(
|
|
14
|
+
name = PACKAGE_NAME,
|
|
15
|
+
srcs = [
|
|
16
|
+
"LICENSE.md",
|
|
17
|
+
"README.md",
|
|
18
|
+
"package.json",
|
|
19
|
+
":dist",
|
|
20
|
+
":dist-esm",
|
|
21
|
+
],
|
|
22
|
+
package = "@formatjs/%s" % PACKAGE_NAME,
|
|
23
|
+
visibility = ["//visibility:public"],
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
SRCS = glob([
|
|
27
|
+
"src/*.ts",
|
|
28
|
+
"*.ts",
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
SRC_DEPS = [
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
TESTS = glob(["tests/*"])
|
|
35
|
+
|
|
36
|
+
ts_compile(
|
|
37
|
+
name = "dist",
|
|
38
|
+
srcs = SRCS,
|
|
39
|
+
package = "@formatjs/%s" % PACKAGE_NAME,
|
|
40
|
+
skip_esm = False,
|
|
41
|
+
deps = SRC_DEPS,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
write_source_files(
|
|
45
|
+
name = "tsconfig_json",
|
|
46
|
+
files = {"tsconfig.json": "//tools:tsconfig.golden.json"},
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
check_format(
|
|
50
|
+
name = "prettier",
|
|
51
|
+
srcs = glob(
|
|
52
|
+
[
|
|
53
|
+
"**/*",
|
|
54
|
+
],
|
|
55
|
+
exclude = [
|
|
56
|
+
"CHANGELOG.md",
|
|
57
|
+
"tests/__snapshots__/*",
|
|
58
|
+
],
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
jest_test(
|
|
63
|
+
name = "unit",
|
|
64
|
+
srcs = SRCS + TESTS,
|
|
65
|
+
deps = SRC_DEPS,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
package_json_test(
|
|
69
|
+
name = "package_json_test",
|
|
70
|
+
deps = SRC_DEPS,
|
|
71
|
+
)
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [0.3.6](https://github.com/formatjs/formatjs/compare/@formatjs/ecma376@0.3.5...@formatjs/ecma376@0.3.6) (2022-08-18)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @formatjs/ecma376
|
|
9
|
+
|
|
10
|
+
## [0.3.5](https://github.com/formatjs/formatjs/compare/@formatjs/ecma376@0.3.4...@formatjs/ecma376@0.3.5) (2022-06-06)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @formatjs/ecma376
|
|
13
|
+
|
|
14
|
+
## [0.3.4](https://github.com/formatjs/formatjs/compare/@formatjs/ecma376@0.3.3...@formatjs/ecma376@0.3.4) (2022-05-19)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @formatjs/ecma376
|
|
17
|
+
|
|
18
|
+
## [0.3.3](https://github.com/formatjs/formatjs/compare/@formatjs/ecma376@0.3.2...@formatjs/ecma376@0.3.3) (2022-05-19)
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **react-intl:** fix type issue with react18, fix [#3550](https://github.com/formatjs/formatjs/issues/3550) ([2567b93](https://github.com/formatjs/formatjs/commit/2567b932c5d18b097a43842563046c20ce0c49f1))
|
|
23
|
+
|
|
24
|
+
## [0.3.2](https://github.com/formatjs/formatjs/compare/@formatjs/ecma376@0.3.1...@formatjs/ecma376@0.3.2) (2021-08-15)
|
|
25
|
+
|
|
26
|
+
**Note:** Version bump only for package @formatjs/ecma376
|
|
27
|
+
|
|
28
|
+
## [0.3.1](https://github.com/formatjs/formatjs/compare/@formatjs/ecma376@0.3.0...@formatjs/ecma376@0.3.1) (2021-08-06)
|
|
29
|
+
|
|
30
|
+
**Note:** Version bump only for package @formatjs/ecma376
|
|
31
|
+
|
|
32
|
+
# 0.3.0 (2021-05-20)
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
* **@formatjs/ecma376:** rename package ([6940184](https://github.com/formatjs/formatjs/commit/6940184b1a40e5abd70430593b1d5ea902138aef))
|
|
37
|
+
|
|
38
|
+
# 0.2.0 (2021-05-20)
|
|
39
|
+
|
|
40
|
+
### Bug Fixes
|
|
41
|
+
|
|
42
|
+
* **@formatjs/ecma376:** rm dead files ([94fdbb5](https://github.com/formatjs/formatjs/commit/94fdbb5a00b97ec63cc3634fea8c4a7c1a82279e))
|
|
43
|
+
|
|
44
|
+
### Features
|
|
45
|
+
|
|
46
|
+
* **@formatjs/ecma376:** new package that generate ecma376 numFmt pattern ([2a57d16](https://github.com/formatjs/formatjs/commit/2a57d1676f8fc840915b2750a5469934dfd765e8)), closes [#2885](https://github.com/formatjs/formatjs/issues/2885)
|
package/LICENSE.md
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const NUMBER = 10000
|
|
2
|
+
const ALL_ZEROS = /^0+$/
|
|
3
|
+
function partToPattern(part: Intl.NumberFormatPart): string {
|
|
4
|
+
switch (part.type) {
|
|
5
|
+
default:
|
|
6
|
+
return part.value
|
|
7
|
+
case 'currency':
|
|
8
|
+
case 'compact':
|
|
9
|
+
return `"${part.value}"`
|
|
10
|
+
case 'integer':
|
|
11
|
+
if (ALL_ZEROS.test(part.value)) {
|
|
12
|
+
return part.value
|
|
13
|
+
.split('')
|
|
14
|
+
.map((_, i, arr) => (i === arr.length - 1 ? '0' : '#'))
|
|
15
|
+
.join('')
|
|
16
|
+
}
|
|
17
|
+
return '#'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function generateNumFmtPattern(
|
|
22
|
+
locales: string | string[],
|
|
23
|
+
opts: Intl.NumberFormatOptions
|
|
24
|
+
) {
|
|
25
|
+
const nf = new Intl.NumberFormat(locales, opts)
|
|
26
|
+
const positivePattern = nf.formatToParts(NUMBER).reduce((pattern, part) => {
|
|
27
|
+
return pattern + partToPattern(part)
|
|
28
|
+
}, '')
|
|
29
|
+
const negativePattern = nf.formatToParts(-NUMBER).reduce((pattern, part) => {
|
|
30
|
+
return pattern + partToPattern(part)
|
|
31
|
+
}, '')
|
|
32
|
+
return positivePattern + ';' + negativePattern
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/ecma376",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "generate ecma376 numFmt in different locales & currencies",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
-
},
|
|
10
7
|
"repository": {
|
|
11
8
|
"type": "git",
|
|
12
9
|
"url": "git+ssh://git@github.com/formatjs/formatjs.git"
|
|
@@ -24,6 +21,9 @@
|
|
|
24
21
|
},
|
|
25
22
|
"homepage": "https://github.com/formatjs/formatjs#readme",
|
|
26
23
|
"dependencies": {
|
|
27
|
-
"tslib": "
|
|
24
|
+
"tslib": "2.4.0"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
28
28
|
}
|
|
29
|
-
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {generateNumFmtPattern} from '../index'
|
|
2
|
+
|
|
3
|
+
test.each`
|
|
4
|
+
locale | result
|
|
5
|
+
${'en'} | ${'"$"#,##0.00;-"$"#,##0.00'}
|
|
6
|
+
${'fr'} | ${'#\u202f##0,00\xa0"$US";-#\u202f##0,00\xa0"$US"'}
|
|
7
|
+
${'ko'} | ${'"US$"#,##0.00;-"US$"#,##0.00'}
|
|
8
|
+
${'zh-Hant'} | ${'"US$"#,##0.00;-"US$"#,##0.00'}
|
|
9
|
+
${'zh-Hans'} | ${'"US$"#,##0.00;-"US$"#,##0.00'}
|
|
10
|
+
${'ja'} | ${'"$"#,##0.00;-"$"#,##0.00'}
|
|
11
|
+
`('format USD in $locale to pattern $result', function ({locale, result}) {
|
|
12
|
+
expect(
|
|
13
|
+
generateNumFmtPattern(locale, {
|
|
14
|
+
style: 'currency',
|
|
15
|
+
currency: 'USD',
|
|
16
|
+
})
|
|
17
|
+
).toBe(result)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test.each`
|
|
21
|
+
locale | result
|
|
22
|
+
${'en'} | ${'"₩"#,##0;-"₩"#,##0'}
|
|
23
|
+
${'fr'} | ${'#\u202f##0\xa0"₩";-#\u202f##0\xa0"₩"'}
|
|
24
|
+
${'ko'} | ${'"₩"#,##0;-"₩"#,##0'}
|
|
25
|
+
${'zh-Hant'} | ${'"₩"#,##0;-"₩"#,##0'}
|
|
26
|
+
${'zh-Hans'} | ${'"₩"#,##0;-"₩"#,##0'}
|
|
27
|
+
${'ja'} | ${'"₩"#,##0;-"₩"#,##0'}
|
|
28
|
+
`('format KRW in $locale to pattern $result', function ({locale, result}) {
|
|
29
|
+
expect(
|
|
30
|
+
generateNumFmtPattern(locale, {
|
|
31
|
+
style: 'currency',
|
|
32
|
+
currency: 'KRW',
|
|
33
|
+
})
|
|
34
|
+
).toBe(result)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test.each`
|
|
38
|
+
locale | result
|
|
39
|
+
${'en'} | ${'"BHD"\xa0#,##0.000;-"BHD"\xa0#,##0.000'}
|
|
40
|
+
${'fr'} | ${'#\u202f##0,000\xa0"BHD";-#\u202f##0,000\xa0"BHD"'}
|
|
41
|
+
${'ko'} | ${'"BHD"\xa0#,##0.000;-"BHD"\xa0#,##0.000'}
|
|
42
|
+
${'zh-Hant'} | ${'"BHD"\xa0#,##0.000;-"BHD"\xa0#,##0.000'}
|
|
43
|
+
${'zh-Hans'} | ${'"BHD"\xa0#,##0.000;-"BHD"\xa0#,##0.000'}
|
|
44
|
+
${'ja'} | ${'"BHD"\xa0#,##0.000;-"BHD"\xa0#,##0.000'}
|
|
45
|
+
`('format BHD in $locale to pattern $result', function ({locale, result}) {
|
|
46
|
+
expect(
|
|
47
|
+
generateNumFmtPattern(locale, {
|
|
48
|
+
style: 'currency',
|
|
49
|
+
currency: 'BHD',
|
|
50
|
+
})
|
|
51
|
+
).toBe(result)
|
|
52
|
+
})
|
|
53
|
+
test.each`
|
|
54
|
+
locale | result
|
|
55
|
+
${'en'} | ${'"CLF"\xa0#,##0.0000;-"CLF"\xa0#,##0.0000'}
|
|
56
|
+
${'fr'} | ${'#\u202f##0,0000\xa0"CLF";-#\u202f##0,0000\xa0"CLF"'}
|
|
57
|
+
${'ko'} | ${'"CLF"\xa0#,##0.0000;-"CLF"\xa0#,##0.0000'}
|
|
58
|
+
${'zh-Hant'} | ${'"CLF"\xa0#,##0.0000;-"CLF"\xa0#,##0.0000'}
|
|
59
|
+
${'zh-Hans'} | ${'"CLF"\xa0#,##0.0000;-"CLF"\xa0#,##0.0000'}
|
|
60
|
+
${'ja'} | ${'"CLF"\xa0#,##0.0000;-"CLF"\xa0#,##0.0000'}
|
|
61
|
+
`('format CLF in $locale to pattern $result', function ({locale, result}) {
|
|
62
|
+
expect(
|
|
63
|
+
generateNumFmtPattern(locale, {
|
|
64
|
+
style: 'currency',
|
|
65
|
+
currency: 'CLF',
|
|
66
|
+
})
|
|
67
|
+
).toBe(result)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('format currency accounting', function () {
|
|
71
|
+
expect(
|
|
72
|
+
generateNumFmtPattern('en', {
|
|
73
|
+
style: 'currency',
|
|
74
|
+
currency: 'USD',
|
|
75
|
+
currencySign: 'accounting',
|
|
76
|
+
})
|
|
77
|
+
).toBe('"$"#,##0.00;("$"#,##0.00)')
|
|
78
|
+
})
|
package/tsconfig.json
ADDED
package/index.d.ts
DELETED
package/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/ecma376/index.ts"],"names":[],"mappings":"AAoBA,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,IAAI,EAAE,IAAI,CAAC,mBAAmB,UAU/B"}
|
package/index.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateNumFmtPattern = void 0;
|
|
4
|
-
var NUMBER = 10000;
|
|
5
|
-
var ALL_ZEROS = /^0+$/;
|
|
6
|
-
function partToPattern(part) {
|
|
7
|
-
switch (part.type) {
|
|
8
|
-
default:
|
|
9
|
-
return part.value;
|
|
10
|
-
case 'currency':
|
|
11
|
-
case 'compact':
|
|
12
|
-
return "\"" + part.value + "\"";
|
|
13
|
-
case 'integer':
|
|
14
|
-
if (ALL_ZEROS.test(part.value)) {
|
|
15
|
-
return part.value
|
|
16
|
-
.split('')
|
|
17
|
-
.map(function (_, i, arr) { return (i === arr.length - 1 ? '0' : '#'); })
|
|
18
|
-
.join('');
|
|
19
|
-
}
|
|
20
|
-
return '#';
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function generateNumFmtPattern(locales, opts) {
|
|
24
|
-
var nf = new Intl.NumberFormat(locales, opts);
|
|
25
|
-
var positivePattern = nf.formatToParts(NUMBER).reduce(function (pattern, part) {
|
|
26
|
-
return pattern + partToPattern(part);
|
|
27
|
-
}, '');
|
|
28
|
-
var negativePattern = nf.formatToParts(-NUMBER).reduce(function (pattern, part) {
|
|
29
|
-
return pattern + partToPattern(part);
|
|
30
|
-
}, '');
|
|
31
|
-
return positivePattern + ';' + negativePattern;
|
|
32
|
-
}
|
|
33
|
-
exports.generateNumFmtPattern = generateNumFmtPattern;
|
package/lib/index.d.ts
DELETED
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/ecma376/index.ts"],"names":[],"mappings":"AAoBA,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,IAAI,EAAE,IAAI,CAAC,mBAAmB,UAU/B"}
|
package/lib/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
var NUMBER = 10000;
|
|
2
|
-
var ALL_ZEROS = /^0+$/;
|
|
3
|
-
function partToPattern(part) {
|
|
4
|
-
switch (part.type) {
|
|
5
|
-
default:
|
|
6
|
-
return part.value;
|
|
7
|
-
case 'currency':
|
|
8
|
-
case 'compact':
|
|
9
|
-
return "\"" + part.value + "\"";
|
|
10
|
-
case 'integer':
|
|
11
|
-
if (ALL_ZEROS.test(part.value)) {
|
|
12
|
-
return part.value
|
|
13
|
-
.split('')
|
|
14
|
-
.map(function (_, i, arr) { return (i === arr.length - 1 ? '0' : '#'); })
|
|
15
|
-
.join('');
|
|
16
|
-
}
|
|
17
|
-
return '#';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function generateNumFmtPattern(locales, opts) {
|
|
21
|
-
var nf = new Intl.NumberFormat(locales, opts);
|
|
22
|
-
var positivePattern = nf.formatToParts(NUMBER).reduce(function (pattern, part) {
|
|
23
|
-
return pattern + partToPattern(part);
|
|
24
|
-
}, '');
|
|
25
|
-
var negativePattern = nf.formatToParts(-NUMBER).reduce(function (pattern, part) {
|
|
26
|
-
return pattern + partToPattern(part);
|
|
27
|
-
}, '');
|
|
28
|
-
return positivePattern + ';' + negativePattern;
|
|
29
|
-
}
|