@formatjs/icu-skeleton-parser 1.3.8 → 1.3.11

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 ADDED
@@ -0,0 +1,80 @@
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("@npm//:defs.bzl", "npm_link_all_packages")
4
+ load("//tools:index.bzl", "check_format", "generate_src_file", "package_json_test", "ts_compile")
5
+ load("//tools:jest.bzl", "jest_test")
6
+
7
+ npm_link_all_packages(name = "node_modules")
8
+
9
+ PACKAGE_NAME = "icu-skeleton-parser"
10
+
11
+ npm_package(
12
+ name = PACKAGE_NAME,
13
+ srcs = [
14
+ "LICENSE.md",
15
+ "README.md",
16
+ "package.json",
17
+ ":dist",
18
+ ],
19
+ package = "@formatjs/%s" % PACKAGE_NAME,
20
+ visibility = ["//visibility:public"],
21
+ )
22
+
23
+ SRCS = glob(["*.ts"])
24
+
25
+ SRC_DEPS = [
26
+ ":node_modules/@formatjs/ecma402-abstract",
27
+ ]
28
+
29
+ ts_compile(
30
+ name = "dist",
31
+ srcs = SRCS,
32
+ package = "@formatjs/%s" % PACKAGE_NAME,
33
+ skip_esm = False,
34
+ deps = SRC_DEPS,
35
+ )
36
+
37
+ jest_test(
38
+ name = "unit",
39
+ srcs = SRCS + glob([
40
+ "tests/**/*.ts",
41
+ "tests/**/*.tsx",
42
+ "tests/**/*.snap",
43
+ ]),
44
+ deps = SRC_DEPS,
45
+ )
46
+
47
+ write_source_files(
48
+ name = "tsconfig_json",
49
+ files = {"tsconfig.json": "//tools:tsconfig.golden.json"},
50
+ )
51
+
52
+ check_format(
53
+ name = "prettier",
54
+ srcs = glob(
55
+ [
56
+ "**/*",
57
+ ],
58
+ exclude = [
59
+ "**/*.generated.ts",
60
+ "CHANGELOG.md",
61
+ "tests/__snapshots__/*",
62
+ ],
63
+ ),
64
+ )
65
+
66
+ generate_src_file(
67
+ name = "regex",
68
+ src = "regex.generated.ts",
69
+ data = [
70
+ "scripts/global.ts",
71
+ "//:node_modules/@unicode/unicode-13.0.0",
72
+ "//:node_modules/regenerate",
73
+ ],
74
+ entry_point = "scripts/regex-gen.ts",
75
+ )
76
+
77
+ package_json_test(
78
+ name = "package_json_test",
79
+ deps = SRC_DEPS,
80
+ )
package/CHANGELOG.md ADDED
@@ -0,0 +1,133 @@
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
+ ## [1.3.11](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.3.10...@formatjs/icu-skeleton-parser@1.3.11) (2022-08-18)
7
+
8
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
9
+
10
+ ## [1.3.10](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.3.9...@formatjs/icu-skeleton-parser@1.3.10) (2022-07-04)
11
+
12
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
13
+
14
+ ## [1.3.9](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.3.8...@formatjs/icu-skeleton-parser@1.3.9) (2022-06-06)
15
+
16
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
17
+
18
+ ## [1.3.8](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.3.7...@formatjs/icu-skeleton-parser@1.3.8) (2022-05-19)
19
+
20
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
21
+
22
+ ## [1.3.7](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.3.6...@formatjs/icu-skeleton-parser@1.3.7) (2022-05-19)
23
+
24
+ ### Bug Fixes
25
+
26
+ * **react-intl:** fix type issue with react18, fix [#3550](https://github.com/formatjs/formatjs/issues/3550) ([2567b93](https://github.com/formatjs/formatjs/commit/2567b932c5d18b097a43842563046c20ce0c49f1))
27
+
28
+ ## [1.3.6](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.3.5...@formatjs/icu-skeleton-parser@1.3.6) (2022-03-26)
29
+
30
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
31
+
32
+ ## [1.3.5](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.3.4...@formatjs/icu-skeleton-parser@1.3.5) (2022-02-06)
33
+
34
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
35
+
36
+ ## [1.3.4](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.3.3...@formatjs/icu-skeleton-parser@1.3.4) (2022-01-24)
37
+
38
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
39
+
40
+ ## [1.3.3](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.3.2...@formatjs/icu-skeleton-parser@1.3.3) (2022-01-03)
41
+
42
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
43
+
44
+ ## [1.3.2](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.3.1...@formatjs/icu-skeleton-parser@1.3.2) (2021-12-01)
45
+
46
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
47
+
48
+ ## [1.3.1](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.3.0...@formatjs/icu-skeleton-parser@1.3.1) (2021-10-22)
49
+
50
+ ### Bug Fixes
51
+
52
+ * **@formatjs/icu-skeleton-parser:** update package.json to include the repository ([#3230](https://github.com/formatjs/formatjs/issues/3230)) ([36dc6bc](https://github.com/formatjs/formatjs/commit/36dc6bc5d8049caaf377f378d81eb6703eb091d5))
53
+
54
+ # [1.3.0](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.13...@formatjs/icu-skeleton-parser@1.3.0) (2021-10-17)
55
+
56
+ ### Features
57
+
58
+ * **@formatjs/icu-skeleton-parser:** parse out NumberFormat v3 options, fix [#3191](https://github.com/formatjs/formatjs/issues/3191) ([24e14d0](https://github.com/formatjs/formatjs/commit/24e14d072467401727a5a96324e5d7e7b758c630))
59
+
60
+ ## [1.2.13](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.12...@formatjs/icu-skeleton-parser@1.2.13) (2021-09-27)
61
+
62
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
63
+
64
+ ## [1.2.12](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.11...@formatjs/icu-skeleton-parser@1.2.12) (2021-08-21)
65
+
66
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
67
+
68
+ ## [1.2.11](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.10...@formatjs/icu-skeleton-parser@1.2.11) (2021-08-15)
69
+
70
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
71
+
72
+ ## [1.2.10](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.9...@formatjs/icu-skeleton-parser@1.2.10) (2021-08-06)
73
+
74
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
75
+
76
+ ## [1.2.9](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.8...@formatjs/icu-skeleton-parser@1.2.9) (2021-07-24)
77
+
78
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
79
+
80
+ ## [1.2.8](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.7...@formatjs/icu-skeleton-parser@1.2.8) (2021-06-26)
81
+
82
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
83
+
84
+ ## [1.2.7](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.6...@formatjs/icu-skeleton-parser@1.2.7) (2021-06-05)
85
+
86
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
87
+
88
+ ## [1.2.6](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.5...@formatjs/icu-skeleton-parser@1.2.6) (2021-06-01)
89
+
90
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
91
+
92
+ ## [1.2.5](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.4...@formatjs/icu-skeleton-parser@1.2.5) (2021-05-23)
93
+
94
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
95
+
96
+ ## [1.2.4](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.3...@formatjs/icu-skeleton-parser@1.2.4) (2021-05-20)
97
+
98
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
99
+
100
+ ## [1.2.3](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.2...@formatjs/icu-skeleton-parser@1.2.3) (2021-05-17)
101
+
102
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
103
+
104
+ ## [1.2.2](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.1...@formatjs/icu-skeleton-parser@1.2.2) (2021-05-10)
105
+
106
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
107
+
108
+ ## [1.2.1](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.2.0...@formatjs/icu-skeleton-parser@1.2.1) (2021-04-26)
109
+
110
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
111
+
112
+ # [1.2.0](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.1.2...@formatjs/icu-skeleton-parser@1.2.0) (2021-04-26)
113
+
114
+ ### Features
115
+
116
+ * **@formatjs/icu-skeleton-parser:** expose ESM entry point ([97f4d38](https://github.com/formatjs/formatjs/commit/97f4d389c521df7cec055d7bac46c8ecb5f32aff))
117
+
118
+ ## [1.1.2](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.1.1...@formatjs/icu-skeleton-parser@1.1.2) (2021-04-12)
119
+
120
+ **Note:** Version bump only for package @formatjs/icu-skeleton-parser
121
+
122
+ ## [1.1.1](https://github.com/formatjs/formatjs/compare/@formatjs/icu-skeleton-parser@1.1.0...@formatjs/icu-skeleton-parser@1.1.1) (2021-03-28)
123
+
124
+ ### Bug Fixes
125
+
126
+ * **@formatjs/icu-skeleton-parser:** fix missing dep, fix [#2760](https://github.com/formatjs/formatjs/issues/2760) ([ddcb76a](https://github.com/formatjs/formatjs/commit/ddcb76a5b567cf6b53d80eec04d733a637ebe886))
127
+
128
+ # 1.1.0 (2021-03-26)
129
+
130
+ ### Features
131
+
132
+ * **@formatjs/icu-messageformat-parser:** add skeleton parsing ([3eec04d](https://github.com/formatjs/formatjs/commit/3eec04d033891ce5192b692f9b079a672b6aae47))
133
+ * **@formatjs/icu-skeleton-parser:** add package ([f6e9aeb](https://github.com/formatjs/formatjs/commit/f6e9aebe56624b8d473be848c68be620827593c2))
package/LICENSE.md CHANGED
File without changes
package/README.md CHANGED
File without changes
package/date-time.ts ADDED
@@ -0,0 +1,144 @@
1
+ /**
2
+ * https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
3
+ * Credit: https://github.com/caridy/intl-datetimeformat-pattern/blob/master/index.js
4
+ * with some tweaks
5
+ */
6
+ const DATE_TIME_REGEX =
7
+ /(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g
8
+
9
+ /**
10
+ * Parse Date time skeleton into Intl.DateTimeFormatOptions
11
+ * Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
12
+ * @public
13
+ * @param skeleton skeleton string
14
+ */
15
+ export function parseDateTimeSkeleton(
16
+ skeleton: string
17
+ ): Intl.DateTimeFormatOptions {
18
+ const result: Intl.DateTimeFormatOptions = {}
19
+ skeleton.replace(DATE_TIME_REGEX, match => {
20
+ const len = match.length
21
+ switch (match[0]) {
22
+ // Era
23
+ case 'G':
24
+ result.era = len === 4 ? 'long' : len === 5 ? 'narrow' : 'short'
25
+ break
26
+ // Year
27
+ case 'y':
28
+ result.year = len === 2 ? '2-digit' : 'numeric'
29
+ break
30
+ case 'Y':
31
+ case 'u':
32
+ case 'U':
33
+ case 'r':
34
+ throw new RangeError(
35
+ '`Y/u/U/r` (year) patterns are not supported, use `y` instead'
36
+ )
37
+ // Quarter
38
+ case 'q':
39
+ case 'Q':
40
+ throw new RangeError('`q/Q` (quarter) patterns are not supported')
41
+ // Month
42
+ case 'M':
43
+ case 'L':
44
+ result.month = ['numeric', '2-digit', 'short', 'long', 'narrow'][
45
+ len - 1
46
+ ] as 'numeric'
47
+ break
48
+ // Week
49
+ case 'w':
50
+ case 'W':
51
+ throw new RangeError('`w/W` (week) patterns are not supported')
52
+ case 'd':
53
+ result.day = ['numeric', '2-digit'][len - 1] as 'numeric'
54
+ break
55
+ case 'D':
56
+ case 'F':
57
+ case 'g':
58
+ throw new RangeError(
59
+ '`D/F/g` (day) patterns are not supported, use `d` instead'
60
+ )
61
+ // Weekday
62
+ case 'E':
63
+ result.weekday = len === 4 ? 'short' : len === 5 ? 'narrow' : 'short'
64
+ break
65
+ case 'e':
66
+ if (len < 4) {
67
+ throw new RangeError('`e..eee` (weekday) patterns are not supported')
68
+ }
69
+ result.weekday = ['short', 'long', 'narrow', 'short'][
70
+ len - 4
71
+ ] as 'short'
72
+ break
73
+ case 'c':
74
+ if (len < 4) {
75
+ throw new RangeError('`c..ccc` (weekday) patterns are not supported')
76
+ }
77
+ result.weekday = ['short', 'long', 'narrow', 'short'][
78
+ len - 4
79
+ ] as 'short'
80
+ break
81
+
82
+ // Period
83
+ case 'a': // AM, PM
84
+ result.hour12 = true
85
+ break
86
+ case 'b': // am, pm, noon, midnight
87
+ case 'B': // flexible day periods
88
+ throw new RangeError(
89
+ '`b/B` (period) patterns are not supported, use `a` instead'
90
+ )
91
+ // Hour
92
+ case 'h':
93
+ result.hourCycle = 'h12'
94
+ result.hour = ['numeric', '2-digit'][len - 1] as 'numeric'
95
+ break
96
+ case 'H':
97
+ result.hourCycle = 'h23'
98
+ result.hour = ['numeric', '2-digit'][len - 1] as 'numeric'
99
+ break
100
+ case 'K':
101
+ result.hourCycle = 'h11'
102
+ result.hour = ['numeric', '2-digit'][len - 1] as 'numeric'
103
+ break
104
+ case 'k':
105
+ result.hourCycle = 'h24'
106
+ result.hour = ['numeric', '2-digit'][len - 1] as 'numeric'
107
+ break
108
+ case 'j':
109
+ case 'J':
110
+ case 'C':
111
+ throw new RangeError(
112
+ '`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead'
113
+ )
114
+ // Minute
115
+ case 'm':
116
+ result.minute = ['numeric', '2-digit'][len - 1] as 'numeric'
117
+ break
118
+ // Second
119
+ case 's':
120
+ result.second = ['numeric', '2-digit'][len - 1] as 'numeric'
121
+ break
122
+ case 'S':
123
+ case 'A':
124
+ throw new RangeError(
125
+ '`S/A` (second) patterns are not supported, use `s` instead'
126
+ )
127
+ // Zone
128
+ case 'z': // 1..3, 4: specific non-location format
129
+ result.timeZoneName = len < 4 ? 'short' : 'long'
130
+ break
131
+ case 'Z': // 1..3, 4, 5: The ISO8601 varios formats
132
+ case 'O': // 1, 4: miliseconds in day short, long
133
+ case 'v': // 1, 4: generic non-location format
134
+ case 'V': // 1, 2, 3, 4: time zone ID or city
135
+ case 'X': // 1, 2, 3, 4: The ISO8601 varios formats
136
+ case 'x': // 1, 2, 3, 4: The ISO8601 varios formats
137
+ throw new RangeError(
138
+ '`Z/O/v/V/X/x` (timeZone) patterns are not supported, use `z` instead'
139
+ )
140
+ }
141
+ return ''
142
+ })
143
+ return result
144
+ }
package/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './date-time'
2
+ export * from './number'