@primer/primitives 9.0.3 → 9.1.0-rc.a6a70c5b

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": "@primer/primitives",
3
- "version": "9.0.3",
3
+ "version": "9.1.0-rc.a6a70c5b",
4
4
  "description": "Typography, spacing, and color primitives for Primer design system",
5
5
  "engines": {
6
6
  "node": ">=18.18.0 <18.19.0"
@@ -0,0 +1,13 @@
1
+ import type StyleDictionary from 'style-dictionary'
2
+ import {toPascalCase} from '../utilities/toPascalCase'
3
+ /**
4
+ * @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a PascalCase string, preserves casing of parts
5
+ * @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
6
+ * @matcher omitted to match all tokens
7
+ * @transformer returns `string` PascalCase
8
+ */
9
+ export const namePathToPascalCase: StyleDictionary.Transform = {
10
+ type: `name`,
11
+ transformer: (token: StyleDictionary.TransformedToken, options?: StyleDictionary.Platform): string =>
12
+ toPascalCase([options?.prefix || '', ...token.path]),
13
+ }
@@ -0,0 +1,14 @@
1
+ export const filterStringArray = (string: string[]): string[] => {
2
+ // match unsupported characters
3
+ const regex = /[^a-zA-Z0-9]+/g
4
+ // replace any non-letter and non-number character and split into word array
5
+ const stringArray = string
6
+ .filter(Boolean)
7
+ .join(' ')
8
+ .replace(regex, ' ')
9
+ .split(' ')
10
+ // remove undefined if exists
11
+ .filter((part: unknown): part is string => Boolean(part) && typeof part === 'string')
12
+
13
+ return stringArray
14
+ }
@@ -1,22 +1,13 @@
1
+ import {filterStringArray} from './filterStringArray'
1
2
  import {upperCaseFirstCharacter} from './upperCaseFirstCharacter'
2
3
 
3
4
  export const toCamelCase = (string: string | string[]) => {
4
5
  if (!Array.isArray(string)) {
5
6
  string = [string]
6
7
  }
7
- // match unsupported characters
8
- const regex = /[^a-zA-Z0-9]+/g
9
- // replace any non-letter and non-number character and split into word array
10
- const stringArray = string
11
- .filter(part => part !== '@')
12
- .filter(Boolean)
13
- .join(' ')
14
- .replace(regex, ' ')
15
- .split(' ')
8
+
16
9
  return (
17
- stringArray
18
- // remove undefined if exists
19
- .filter((part: unknown): part is string => typeof part === 'string')
10
+ filterStringArray(string)
20
11
  // ucFirst all but first part
21
12
  .map((part: string, index: number) => {
22
13
  if (index > 0) {
@@ -0,0 +1,17 @@
1
+ import {filterStringArray} from './filterStringArray'
2
+ import {upperCaseFirstCharacter} from './upperCaseFirstCharacter'
3
+
4
+ export const toPascalCase = (string: string | string[]) => {
5
+ if (!Array.isArray(string)) {
6
+ string = [string]
7
+ }
8
+
9
+ return (
10
+ filterStringArray(string)
11
+ // ucFirst all but first part
12
+ .map((part: string) => {
13
+ return upperCaseFirstCharacter(part)
14
+ })
15
+ .join('')
16
+ )
17
+ }