@wix/zero-config-implementation 1.28.0 → 1.30.0
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/dist/converters/utils.d.ts +3 -0
- package/dist/index.js +3388 -3380
- package/package.json +2 -2
- package/src/converters/utils.test.ts +33 -0
- package/src/converters/utils.ts +15 -1
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"registry": "https://registry.npmjs.org/",
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.30.0",
|
|
8
8
|
"description": "Core library for extracting component manifests from JS and CSS files",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "dist/index.js",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
]
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
|
-
"falconPackageHash": "
|
|
86
|
+
"falconPackageHash": "7c40209d1126d0b860d10bc39a13660c52b5a97620afd671085c8c41"
|
|
87
87
|
}
|
|
@@ -13,4 +13,37 @@ describe('formatDisplayName', () => {
|
|
|
13
13
|
it('formats camelCase', () => {
|
|
14
14
|
expect(formatDisplayName('camelCaseExample')).toBe('Camel Case Example')
|
|
15
15
|
})
|
|
16
|
+
|
|
17
|
+
it('returns name unchanged when exactly 50 characters', () => {
|
|
18
|
+
// 10 words of 4 chars + 9 spaces = 49 chars; add one more char to hit 50
|
|
19
|
+
const input = 'Word One Two Three Four Five Six Seven Eight Nine'
|
|
20
|
+
expect(input.length).toBe(49)
|
|
21
|
+
expect(formatDisplayName(input)).toBe(input)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('drops leading words when formatted name exceeds 50 characters', () => {
|
|
25
|
+
// capitalCase('myVeryLongComponentWithAnExtremelyLongDisplayName')
|
|
26
|
+
// => "My Very Long Component With An Extremely Long Display Name" (58 chars)
|
|
27
|
+
// Drop "My" => 55 chars, drop "Very" => "Long Component With An Extremely Long Display Name" (50 chars)
|
|
28
|
+
expect(formatDisplayName('myVeryLongComponentWithAnExtremelyLongDisplayName')).toBe(
|
|
29
|
+
'Long Component With An Extremely Long Display Name',
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('drops leading words and result is less than 50 characters', () => {
|
|
34
|
+
// capitalCase('myComponentWithAVeryShortAndLongEnoughName')
|
|
35
|
+
// => "My Component With A Very Short And Long Enough Name" (51 chars)
|
|
36
|
+
// Drop "My" => "Component With A Very Short And Long Enough Name" (48 chars) < 50
|
|
37
|
+
const result = formatDisplayName('myComponentWithAVeryShortAndLongEnoughName')
|
|
38
|
+
expect(result).toBe('Component With A Very Short And Long Enough Name')
|
|
39
|
+
expect(result.length).toBe(48)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('truncates at 50 characters when a single word exceeds the limit', () => {
|
|
43
|
+
// capitalCase of 51 repeated 'a' characters is a single word starting with uppercase
|
|
44
|
+
const longSingleWord = 'a'.repeat(51)
|
|
45
|
+
const expected = `A${'a'.repeat(49)}` // 50 chars total
|
|
46
|
+
expect(formatDisplayName(longSingleWord)).toBe(expected)
|
|
47
|
+
expect(formatDisplayName(longSingleWord).length).toBe(50)
|
|
48
|
+
})
|
|
16
49
|
})
|
package/src/converters/utils.ts
CHANGED
|
@@ -8,10 +8,14 @@ const DISPLAY_NAME_OVERRIDES = {
|
|
|
8
8
|
a11y: 'Accessibility',
|
|
9
9
|
} as const
|
|
10
10
|
|
|
11
|
+
const DISPLAY_NAME_MAX_LENGTH = 50
|
|
12
|
+
|
|
11
13
|
/**
|
|
12
14
|
* Formats any string format to Title Case display name
|
|
13
15
|
* Handles: kebab-case, camelCase, PascalCase, snake_case, SCREAMING_SNAKE_CASE, and mixed formats
|
|
14
16
|
*
|
|
17
|
+
* If the result exceeds 50 characters, leading words are dropped (end words are more specific).
|
|
18
|
+
*
|
|
15
19
|
* Examples:
|
|
16
20
|
* "input-field-weight" -> "Input Field Weight"
|
|
17
21
|
* "camelCaseExample" -> "Camel Case Example"
|
|
@@ -20,10 +24,20 @@ const DISPLAY_NAME_OVERRIDES = {
|
|
|
20
24
|
* "SCREAMING_SNAKE_CASE" -> "Screaming Snake Case"
|
|
21
25
|
* "mixed-format_example" -> "Mixed Format Example"
|
|
22
26
|
* "a11y" -> "Accessibility"
|
|
27
|
+
* "myVeryLongComponentWithAnExtremelyLongDisplayName" -> "With An Extremely Long Display Name"
|
|
23
28
|
*/
|
|
24
29
|
export function formatDisplayName(input: string): string {
|
|
25
30
|
if (input in DISPLAY_NAME_OVERRIDES) {
|
|
26
31
|
return DISPLAY_NAME_OVERRIDES[input as keyof typeof DISPLAY_NAME_OVERRIDES]
|
|
27
32
|
}
|
|
28
|
-
|
|
33
|
+
const formatted = capitalCase(input, { keepSpecialCharacters: false })
|
|
34
|
+
if (formatted.length <= DISPLAY_NAME_MAX_LENGTH) {
|
|
35
|
+
return formatted
|
|
36
|
+
}
|
|
37
|
+
const words = formatted.split(' ')
|
|
38
|
+
while (words.length > 1 && words.join(' ').length > DISPLAY_NAME_MAX_LENGTH) {
|
|
39
|
+
words.shift()
|
|
40
|
+
}
|
|
41
|
+
const result = words.join(' ')
|
|
42
|
+
return result.slice(0, DISPLAY_NAME_MAX_LENGTH)
|
|
29
43
|
}
|