1
1
/**
2
- * Convert group name, token name and possible prefix into camelCased string, joining everything together
3
- */
4
- Pulsar . registerFunction ( "readableVariableName" , function ( token , tokenGroup , prefix ) {
5
-
2
+ * Convert group name, token name and possible prefix into camelCased string, joining everything together
3
+ */
4
+ Pulsar . registerFunction (
5
+ "readableVariableName" ,
6
+ function ( token , tokenGroup , prefix ) {
6
7
// Create array with all path segments and token name at the end
7
- let segments = [ ...tokenGroup . path , token . name ]
8
+ let segments = [ ...tokenGroup . path , token . name ] ;
8
9
if ( prefix && prefix . length > 0 ) {
9
- segments . unshift ( prefix )
10
+ segments . unshift ( prefix ) ;
10
11
}
11
12
12
13
// Create "sentence" separated by spaces so we can camelcase it all
13
- let sentence = segments . join ( " " )
14
+ let sentence = segments . join ( " " ) ;
14
15
15
16
// Return camelcased string from all segments
16
- return sentence . toLowerCase ( ) . replace ( / [ ^ a - z A - Z 0 - 9 ] + ( .) / g, ( m , chr ) => chr . toUpperCase ( ) ) ;
17
- } )
17
+ sentence = sentence
18
+ . toLowerCase ( )
19
+ . replace ( / [ ^ a - z A - Z 0 - 9 ] + ( .) / g, ( m , chr ) => chr . toUpperCase ( ) ) ;
20
+
21
+ if ( / ^ \d / . test ( sentence ) ) {
22
+ sentence = "_" + sentence ;
23
+ }
24
+ return sentence ;
25
+ }
26
+ ) ;
18
27
19
28
/**
20
- * Behavior configuration of the exporter
21
- * Prefixes: Add prefix for each category of the tokens. For example, all colors can start with "color, if needed"
22
- */
29
+ * Behavior configuration of the exporter
30
+ * Prefixes: Add prefix for each category of the tokens. For example, all colors can start with "color, if needed"
31
+ */
23
32
Pulsar . registerPayload ( "behavior" , {
24
- colorTokenPrefix : "color" ,
25
- borderTokenPrefix : "border" ,
26
- gradientTokenPrefix : "gradient" ,
27
- measureTokenPrefix : "measure" ,
28
- shadowTokenPrefix : "shadow" ,
29
- typographyTokenPrefix : "typography"
30
- } )
33
+ colorTokenPrefix : "color" ,
34
+ borderTokenPrefix : "border" ,
35
+ gradientTokenPrefix : "gradient" ,
36
+ measureTokenPrefix : "measure" ,
37
+ shadowTokenPrefix : "shadow" ,
38
+ typographyTokenPrefix : "typography" ,
39
+ } ) ;
0 commit comments