@transferwise/components 46.123.0 → 46.123.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/build/common/initials.js
CHANGED
|
@@ -4,12 +4,16 @@ function startsWithParenthesis(part) {
|
|
|
4
4
|
return /^[({[<]/.test(part);
|
|
5
5
|
}
|
|
6
6
|
// Reuse a single Intl.Segmenter instance to avoid repeated allocations
|
|
7
|
-
const GRAPHEME_SEGMENTER = new Intl.Segmenter('en', {
|
|
7
|
+
const GRAPHEME_SEGMENTER = typeof Intl.Segmenter === 'function' ? new Intl.Segmenter('en', {
|
|
8
8
|
granularity: 'grapheme'
|
|
9
|
-
});
|
|
9
|
+
}) : undefined;
|
|
10
10
|
// Helper to split the string into grapheme clusters, which handles complex characters correctly
|
|
11
11
|
function getGraphemes(str) {
|
|
12
|
-
|
|
12
|
+
if (GRAPHEME_SEGMENTER) {
|
|
13
|
+
return Array.from(GRAPHEME_SEGMENTER.segment(str), s => s.segment);
|
|
14
|
+
}
|
|
15
|
+
// Fallback to still splitting by Unicode code points when Intl.Segmenter is not available (NOTE: Won't handle complex graphemes perfectly)
|
|
16
|
+
return Array.from(str);
|
|
13
17
|
}
|
|
14
18
|
function getInitials(name) {
|
|
15
19
|
if (name.length === 2 && /^[A-Z]{2}$/.test(name)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initials.js","sources":["../../src/common/initials.ts"],"sourcesContent":["function startsWithParenthesis(part: string) {\n return /^[({[<]/.test(part);\n}\n\n// Reuse a single Intl.Segmenter instance to avoid repeated allocations\nconst GRAPHEME_SEGMENTER
|
|
1
|
+
{"version":3,"file":"initials.js","sources":["../../src/common/initials.ts"],"sourcesContent":["function startsWithParenthesis(part: string) {\n return /^[({[<]/.test(part);\n}\n\n// Reuse a single Intl.Segmenter instance to avoid repeated allocations\nconst GRAPHEME_SEGMENTER =\n typeof Intl.Segmenter === 'function'\n ? new Intl.Segmenter('en', { granularity: 'grapheme' })\n : undefined;\n\n// Helper to split the string into grapheme clusters, which handles complex characters correctly\nfunction getGraphemes(str: string): string[] {\n if (GRAPHEME_SEGMENTER) {\n return Array.from(GRAPHEME_SEGMENTER.segment(str), (s) => s.segment);\n }\n // Fallback to still splitting by Unicode code points when Intl.Segmenter is not available (NOTE: Won't handle complex graphemes perfectly)\n return Array.from(str);\n}\n\nexport function getInitials(name: string) {\n if (name.length === 2 && /^[A-Z]{2}$/.test(name)) {\n return name;\n }\n\n const allInitials = name\n .split(' ')\n .filter((part) => !startsWithParenthesis(part))\n .map((part) => getGraphemes(part)[0])\n .join('')\n .toUpperCase();\n\n // Get graphemes of the initials string to handle complex characters correctly\n const graphemes = getGraphemes(allInitials);\n\n if (graphemes.length === 1) {\n return graphemes[0];\n }\n\n return graphemes[0] + graphemes[graphemes.length - 1];\n}\n"],"names":["startsWithParenthesis","part","test","GRAPHEME_SEGMENTER","Intl","Segmenter","granularity","undefined","getGraphemes","str","Array","from","segment","s","getInitials","name","length","allInitials","split","filter","map","join","toUpperCase","graphemes"],"mappings":";;AAAA,SAASA,qBAAqBA,CAACC,IAAY,EAAA;AACzC,EAAA,OAAO,SAAS,CAACC,IAAI,CAACD,IAAI,CAAC;AAC7B;AAEA;AACA,MAAME,kBAAkB,GACtB,OAAOC,IAAI,CAACC,SAAS,KAAK,UAAU,GAChC,IAAID,IAAI,CAACC,SAAS,CAAC,IAAI,EAAE;AAAEC,EAAAA,WAAW,EAAE;CAAY,CAAC,GACrDC,SAAS;AAEf;AACA,SAASC,YAAYA,CAACC,GAAW,EAAA;AAC/B,EAAA,IAAIN,kBAAkB,EAAE;AACtB,IAAA,OAAOO,KAAK,CAACC,IAAI,CAACR,kBAAkB,CAACS,OAAO,CAACH,GAAG,CAAC,EAAGI,CAAC,IAAKA,CAAC,CAACD,OAAO,CAAC;AACtE,EAAA;AACA;AACA,EAAA,OAAOF,KAAK,CAACC,IAAI,CAACF,GAAG,CAAC;AACxB;AAEM,SAAUK,WAAWA,CAACC,IAAY,EAAA;AACtC,EAAA,IAAIA,IAAI,CAACC,MAAM,KAAK,CAAC,IAAI,YAAY,CAACd,IAAI,CAACa,IAAI,CAAC,EAAE;AAChD,IAAA,OAAOA,IAAI;AACb,EAAA;AAEA,EAAA,MAAME,WAAW,GAAGF,IAAI,CACrBG,KAAK,CAAC,GAAG,CAAC,CACVC,MAAM,CAAElB,IAAI,IAAK,CAACD,qBAAqB,CAACC,IAAI,CAAC,CAAC,CAC9CmB,GAAG,CAAEnB,IAAI,IAAKO,YAAY,CAACP,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CACpCoB,IAAI,CAAC,EAAE,CAAC,CACRC,WAAW,EAAE;AAEhB;AACA,EAAA,MAAMC,SAAS,GAAGf,YAAY,CAACS,WAAW,CAAC;AAE3C,EAAA,IAAIM,SAAS,CAACP,MAAM,KAAK,CAAC,EAAE;IAC1B,OAAOO,SAAS,CAAC,CAAC,CAAC;AACrB,EAAA;AAEA,EAAA,OAAOA,SAAS,CAAC,CAAC,CAAC,GAAGA,SAAS,CAACA,SAAS,CAACP,MAAM,GAAG,CAAC,CAAC;AACvD;;;;"}
|
|
@@ -2,12 +2,16 @@ function startsWithParenthesis(part) {
|
|
|
2
2
|
return /^[({[<]/.test(part);
|
|
3
3
|
}
|
|
4
4
|
// Reuse a single Intl.Segmenter instance to avoid repeated allocations
|
|
5
|
-
const GRAPHEME_SEGMENTER = new Intl.Segmenter('en', {
|
|
5
|
+
const GRAPHEME_SEGMENTER = typeof Intl.Segmenter === 'function' ? new Intl.Segmenter('en', {
|
|
6
6
|
granularity: 'grapheme'
|
|
7
|
-
});
|
|
7
|
+
}) : undefined;
|
|
8
8
|
// Helper to split the string into grapheme clusters, which handles complex characters correctly
|
|
9
9
|
function getGraphemes(str) {
|
|
10
|
-
|
|
10
|
+
if (GRAPHEME_SEGMENTER) {
|
|
11
|
+
return Array.from(GRAPHEME_SEGMENTER.segment(str), s => s.segment);
|
|
12
|
+
}
|
|
13
|
+
// Fallback to still splitting by Unicode code points when Intl.Segmenter is not available (NOTE: Won't handle complex graphemes perfectly)
|
|
14
|
+
return Array.from(str);
|
|
11
15
|
}
|
|
12
16
|
function getInitials(name) {
|
|
13
17
|
if (name.length === 2 && /^[A-Z]{2}$/.test(name)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initials.mjs","sources":["../../src/common/initials.ts"],"sourcesContent":["function startsWithParenthesis(part: string) {\n return /^[({[<]/.test(part);\n}\n\n// Reuse a single Intl.Segmenter instance to avoid repeated allocations\nconst GRAPHEME_SEGMENTER
|
|
1
|
+
{"version":3,"file":"initials.mjs","sources":["../../src/common/initials.ts"],"sourcesContent":["function startsWithParenthesis(part: string) {\n return /^[({[<]/.test(part);\n}\n\n// Reuse a single Intl.Segmenter instance to avoid repeated allocations\nconst GRAPHEME_SEGMENTER =\n typeof Intl.Segmenter === 'function'\n ? new Intl.Segmenter('en', { granularity: 'grapheme' })\n : undefined;\n\n// Helper to split the string into grapheme clusters, which handles complex characters correctly\nfunction getGraphemes(str: string): string[] {\n if (GRAPHEME_SEGMENTER) {\n return Array.from(GRAPHEME_SEGMENTER.segment(str), (s) => s.segment);\n }\n // Fallback to still splitting by Unicode code points when Intl.Segmenter is not available (NOTE: Won't handle complex graphemes perfectly)\n return Array.from(str);\n}\n\nexport function getInitials(name: string) {\n if (name.length === 2 && /^[A-Z]{2}$/.test(name)) {\n return name;\n }\n\n const allInitials = name\n .split(' ')\n .filter((part) => !startsWithParenthesis(part))\n .map((part) => getGraphemes(part)[0])\n .join('')\n .toUpperCase();\n\n // Get graphemes of the initials string to handle complex characters correctly\n const graphemes = getGraphemes(allInitials);\n\n if (graphemes.length === 1) {\n return graphemes[0];\n }\n\n return graphemes[0] + graphemes[graphemes.length - 1];\n}\n"],"names":["startsWithParenthesis","part","test","GRAPHEME_SEGMENTER","Intl","Segmenter","granularity","undefined","getGraphemes","str","Array","from","segment","s","getInitials","name","length","allInitials","split","filter","map","join","toUpperCase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SAAS,CAACA,SAAS,CAACP,MAAM,GAAG,CAAC,CAAC;AACvD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initials.d.ts","sourceRoot":"","sources":["../../../src/common/initials.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"initials.d.ts","sourceRoot":"","sources":["../../../src/common/initials.ts"],"names":[],"mappings":"AAmBA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAoBvC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "46.123.
|
|
3
|
+
"version": "46.123.1",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -86,9 +86,9 @@
|
|
|
86
86
|
"storybook-addon-tag-badges": "^3.0.4",
|
|
87
87
|
"storybook-addon-test-codegen": "^3.0.1",
|
|
88
88
|
"@transferwise/less-config": "3.1.2",
|
|
89
|
-
"@transferwise/neptune-css": "14.26.1",
|
|
90
89
|
"@wise/components-theming": "1.10.1",
|
|
91
|
-
"@wise/wds-configs": "0.0.0"
|
|
90
|
+
"@wise/wds-configs": "0.0.0",
|
|
91
|
+
"@transferwise/neptune-css": "14.26.1"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"@transferwise/icons": "^3 || ^4",
|
package/src/common/initials.ts
CHANGED
|
@@ -3,11 +3,18 @@ function startsWithParenthesis(part: string) {
|
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
// Reuse a single Intl.Segmenter instance to avoid repeated allocations
|
|
6
|
-
const GRAPHEME_SEGMENTER =
|
|
6
|
+
const GRAPHEME_SEGMENTER =
|
|
7
|
+
typeof Intl.Segmenter === 'function'
|
|
8
|
+
? new Intl.Segmenter('en', { granularity: 'grapheme' })
|
|
9
|
+
: undefined;
|
|
7
10
|
|
|
8
11
|
// Helper to split the string into grapheme clusters, which handles complex characters correctly
|
|
9
12
|
function getGraphemes(str: string): string[] {
|
|
10
|
-
|
|
13
|
+
if (GRAPHEME_SEGMENTER) {
|
|
14
|
+
return Array.from(GRAPHEME_SEGMENTER.segment(str), (s) => s.segment);
|
|
15
|
+
}
|
|
16
|
+
// Fallback to still splitting by Unicode code points when Intl.Segmenter is not available (NOTE: Won't handle complex graphemes perfectly)
|
|
17
|
+
return Array.from(str);
|
|
11
18
|
}
|
|
12
19
|
|
|
13
20
|
export function getInitials(name: string) {
|