@formatjs/cli-lib 5.1.13 → 6.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/cli-lib",
3
- "version": "5.1.13",
3
+ "version": "6.0.1",
4
4
  "description": "Lib for CLI for formatjs.",
5
5
  "keywords": [
6
6
  "intl",
@@ -31,8 +31,8 @@
31
31
  "url": "https://github.com/formatjs/formatjs/issues"
32
32
  },
33
33
  "dependencies": {
34
- "@formatjs/icu-messageformat-parser": "2.2.0",
35
- "@formatjs/ts-transformer": "3.11.6",
34
+ "@formatjs/icu-messageformat-parser": "2.3.0",
35
+ "@formatjs/ts-transformer": "3.12.0",
36
36
  "@types/estree": "^0.0.50",
37
37
  "@types/fs-extra": "^9.0.1",
38
38
  "@types/json-stable-stringify": "^1.0.32",
@@ -2,6 +2,22 @@ import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
2
2
  export declare function generateXXLS(msg: string | MessageFormatElement[]): MessageFormatElement[];
3
3
  export declare function generateXXAC(msg: string | MessageFormatElement[]): MessageFormatElement[];
4
4
  export declare function generateXXHA(msg: string | MessageFormatElement[]): MessageFormatElement[];
5
+ /**
6
+ * accented - Ȧȧƈƈḗḗƞŧḗḗḓ Ḗḗƞɠŀīīşħ
7
+ * --------------------------------
8
+ *
9
+ * This locale replaces all Latin characters with their accented equivalents, and duplicates some
10
+ * vowels to create roughly 30% longer strings. Strings are wrapped in markers (square brackets),
11
+ * which help with detecting truncation.
12
+ */
5
13
  export declare function generateENXA(msg: string | MessageFormatElement[]): MessageFormatElement[];
14
+ /**
15
+ * bidi - ɥsıʅƃuƎ ıpıԐ
16
+ * -------------------
17
+ *
18
+ * This strategy replaces all Latin characters with their 180 degree rotated versions and enforces
19
+ * right to left text flow using Unicode UAX#9 Explicit Directional Embeddings. In this mode, the UI
20
+ * directionality will also be set to right-to-left.
21
+ */
6
22
  export declare function generateENXB(msg: string | MessageFormatElement[]): MessageFormatElement[];
7
23
  //# sourceMappingURL=pseudo_locale.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pseudo_locale.d.ts","sourceRoot":"","sources":["pseudo_locale.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EAMrB,MAAM,oCAAoC,CAAA;AAE3C,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAQxB;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAcxB;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAQxB;AAKD,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAuBxB;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CA4BxB"}
1
+ {"version":3,"file":"pseudo_locale.d.ts","sourceRoot":"","sources":["pseudo_locale.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EAOrB,MAAM,oCAAoC,CAAA;AAmB3C,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAQxB;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAMxB;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAQxB;AA4DD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAUxB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,oBAAoB,EAAE,GACnC,oBAAoB,EAAE,CAUxB"}
@@ -2,6 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateENXB = exports.generateENXA = exports.generateXXHA = exports.generateXXAC = exports.generateXXLS = void 0;
4
4
  const icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
5
+ function forEachLiteralElement(ast, fn) {
6
+ ast.forEach(el => {
7
+ if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
8
+ fn(el);
9
+ }
10
+ else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
11
+ for (const opt of Object.values(el.options)) {
12
+ forEachLiteralElement(opt.value, fn);
13
+ }
14
+ }
15
+ else if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
16
+ forEachLiteralElement(el.children, fn);
17
+ }
18
+ });
19
+ }
5
20
  function generateXXLS(msg) {
6
21
  const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
7
22
  const lastChunk = ast[ast.length - 1];
@@ -14,18 +29,8 @@ function generateXXLS(msg) {
14
29
  exports.generateXXLS = generateXXLS;
15
30
  function generateXXAC(msg) {
16
31
  const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
17
- ast.forEach(el => {
18
- if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
19
- el.value = el.value.toUpperCase();
20
- }
21
- else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
22
- for (const opt of Object.values(el.options)) {
23
- generateXXAC(opt.value);
24
- }
25
- }
26
- else if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
27
- generateXXAC(el.children);
28
- }
32
+ forEachLiteralElement(ast, el => {
33
+ el.value = el.value.toUpperCase();
29
34
  });
30
35
  return ast;
31
36
  }
@@ -40,61 +45,79 @@ function generateXXHA(msg) {
40
45
  return [{ type: icu_messageformat_parser_1.TYPE.literal, value: '[javascript]' }, ...ast];
41
46
  }
42
47
  exports.generateXXHA = generateXXHA;
43
- const ASCII = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
44
- const ACCENTED_ASCII = 'âḃćḋèḟĝḫíĵǩĺṁńŏṗɋŕśṭůṿẘẋẏẓḀḂḈḊḔḞḠḢḬĴḴĻḾŊÕṔɊŔṠṮŨṼẄẌŸƵ';
45
- function generateENXA(msg) {
46
- const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
47
- ast.forEach(el => {
48
- if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
49
- el.value = el.value
50
- .split('')
51
- .map(c => {
52
- const i = ASCII.indexOf(c);
53
- if (i < 0) {
54
- return c;
55
- }
56
- return ACCENTED_ASCII[i];
57
- })
58
- .join('');
59
- }
60
- else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
61
- for (const opt of Object.values(el.options)) {
62
- generateENXA(opt.value);
48
+ const ACCENTED_MAP = {
49
+ // ȦƁƇḒḖƑƓĦĪĴĶĿḾȠǾƤɊŘŞŦŬṼẆẊẎẐ
50
+ // prettier-ignore
51
+ "caps": [550, 385, 391, 7698, 7702, 401, 403, 294, 298, 308, 310, 319, 7742, 544, 510, 420, 586, 344, 350, 358, 364, 7804, 7814, 7818, 7822, 7824],
52
+ // ȧƀƈḓḗƒɠħīĵķŀḿƞǿƥɋřşŧŭṽẇẋẏẑ
53
+ // prettier-ignore
54
+ "small": [551, 384, 392, 7699, 7703, 402, 608, 295, 299, 309, 311, 320, 7743, 414, 511, 421, 587, 345, 351, 359, 365, 7805, 7815, 7819, 7823, 7825],
55
+ };
56
+ const FLIPPED_MAP = {
57
+ // ∀ԐↃᗡƎℲ⅁HIſӼ⅂WNOԀÒᴚS⊥∩ɅMX⅄Z
58
+ // prettier-ignore
59
+ "caps": [8704, 1296, 8579, 5601, 398, 8498, 8513, 72, 73, 383, 1276, 8514, 87, 78, 79, 1280, 210, 7450, 83, 8869, 8745, 581, 77, 88, 8516, 90],
60
+ // ɐqɔpǝɟƃɥıɾʞʅɯuodbɹsʇnʌʍxʎz
61
+ // prettier-ignore
62
+ "small": [592, 113, 596, 112, 477, 607, 387, 613, 305, 638, 670, 645, 623, 117, 111, 100, 98, 633, 115, 647, 110, 652, 653, 120, 654, 122],
63
+ };
64
+ /**
65
+ * Based on: https://hg.mozilla.org/mozilla-central/file/a1f74e8c8fb72390d22054d6b00c28b1a32f6c43/intl/l10n/L10nRegistry.jsm#l425
66
+ */
67
+ function transformString(map, elongate = false, msg) {
68
+ return msg.replace(/[a-z]/gi, ch => {
69
+ const cc = ch.charCodeAt(0);
70
+ if (cc >= 97 && cc <= 122) {
71
+ const newChar = String.fromCodePoint(map.small[cc - 97]);
72
+ // duplicate "a", "e", "o" and "u" to emulate ~30% longer text
73
+ if (elongate && (cc === 97 || cc === 101 || cc === 111 || cc === 117)) {
74
+ return newChar + newChar;
63
75
  }
76
+ return newChar;
64
77
  }
65
- else if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
66
- generateENXA(el.children);
78
+ if (cc >= 65 && cc <= 90) {
79
+ return String.fromCodePoint(map.caps[cc - 65]);
67
80
  }
81
+ return ch;
68
82
  });
69
- return ast;
83
+ }
84
+ /**
85
+ * accented - Ȧȧƈƈḗḗƞŧḗḗḓ Ḗḗƞɠŀīīşħ
86
+ * --------------------------------
87
+ *
88
+ * This locale replaces all Latin characters with their accented equivalents, and duplicates some
89
+ * vowels to create roughly 30% longer strings. Strings are wrapped in markers (square brackets),
90
+ * which help with detecting truncation.
91
+ */
92
+ function generateENXA(msg) {
93
+ const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
94
+ forEachLiteralElement(ast, el => {
95
+ el.value = transformString(ACCENTED_MAP, true, el.value);
96
+ });
97
+ return [
98
+ { type: icu_messageformat_parser_1.TYPE.literal, value: '[' },
99
+ ...ast,
100
+ { type: icu_messageformat_parser_1.TYPE.literal, value: ']' },
101
+ ];
70
102
  }
71
103
  exports.generateENXA = generateENXA;
104
+ /**
105
+ * bidi - ɥsıʅƃuƎ ıpıԐ
106
+ * -------------------
107
+ *
108
+ * This strategy replaces all Latin characters with their 180 degree rotated versions and enforces
109
+ * right to left text flow using Unicode UAX#9 Explicit Directional Embeddings. In this mode, the UI
110
+ * directionality will also be set to right-to-left.
111
+ */
72
112
  function generateENXB(msg) {
73
113
  const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
74
- ast.forEach(el => {
75
- if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
76
- const pseudoString = el.value
77
- .split('')
78
- .map((c, index) => {
79
- const i = ASCII.indexOf(c);
80
- const canPad = (index + 1) % 3 === 0;
81
- if (i < 0) {
82
- return c;
83
- }
84
- return canPad ? ACCENTED_ASCII[i].repeat(3) : ACCENTED_ASCII[i];
85
- })
86
- .join('');
87
- el.value = `[!! ${pseudoString} !!]`;
88
- }
89
- else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
90
- for (const opt of Object.values(el.options)) {
91
- generateENXB(opt.value);
92
- }
93
- }
94
- else if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
95
- generateENXB(el.children);
96
- }
114
+ forEachLiteralElement(ast, el => {
115
+ el.value = transformString(FLIPPED_MAP, false, el.value);
97
116
  });
98
- return ast;
117
+ return [
118
+ { type: icu_messageformat_parser_1.TYPE.literal, value: '\u202e' },
119
+ ...ast,
120
+ { type: icu_messageformat_parser_1.TYPE.literal, value: '\u202c' },
121
+ ];
99
122
  }
100
123
  exports.generateENXB = generateENXB;