@wix/zero-config-implementation 1.28.0 → 1.29.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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "registry": "https://registry.npmjs.org/",
5
5
  "access": "public"
6
6
  },
7
- "version": "1.28.0",
7
+ "version": "1.29.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": "b9b7aa47b7618d7b031628208f9fb26661e34ddb5fe300679306084e"
86
+ "falconPackageHash": "9f12ded214e8668f280831d8bb3e03f08b14e2a9a46a97c8a423c29b"
87
87
  }
@@ -13,4 +13,28 @@ 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('truncates at 50 characters when a single word exceeds the limit', () => {
34
+ // capitalCase of 51 repeated 'a' characters is a single word starting with uppercase
35
+ const longSingleWord = 'a'.repeat(51)
36
+ const expected = `A${'a'.repeat(49)}` // 50 chars total
37
+ expect(formatDisplayName(longSingleWord)).toBe(expected)
38
+ expect(formatDisplayName(longSingleWord).length).toBe(50)
39
+ })
16
40
  })
@@ -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
- return capitalCase(input, { keepSpecialCharacters: false })
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
  }