@@ -7,36 +7,50 @@ const easeShorthands = ['ease', 'ease-in', 'ease-out', 'ease-in-out']
7
7
const timingFunctions = [ ...easeShorthands , cubicFunction , stepsFunction ]
8
8
9
9
/**
10
- * Get before a parenthesis
10
+ * Test if a string has a parenthesis
11
+ * @param {String } str A text string
12
+ * @returns {Boolean } If a string has a "("
11
13
*/
12
- const hasParenthesis = ( str ) => str . indexOf ( '(' ) !== - 1
13
- const getBeforeParenthesisMaybe = ( str ) => hasParenthesis ( str ) ? str . substring ( 0 , str . indexOf ( '(' ) ) : str
14
+ const hasParenthesis = str => str . indexOf ( '(' ) !== - 1
14
15
15
16
/**
16
- * Test if a string matches a css timing function
17
- */
18
- exports . isTimingFunction = ( str ) => timingFunctions . includes ( getBeforeParenthesisMaybe ( str ) )
17
+ * Get substring before first parenthesis in a string
18
+ * @param {String } str A text string
19
+ * @returns {String } The substring if the provided string has a parenthesis. Otherwise the string.
20
+ */
21
+ const getBeforeParenthesisMaybe = str => hasParenthesis ( str ) ? str . substring ( 0 , str . indexOf ( '(' ) ) : str
22
+
23
+ /**
24
+ * Test if a string matches a css timing function
25
+ * @param {String } str A text string
26
+ * @returns {Boolean } If the string is a timing function
27
+ */
28
+ exports . isTimingFunction = str => timingFunctions . includes ( getBeforeParenthesisMaybe ( str ) )
19
29
20
30
/**
21
31
* Get insides of a parenthesis
22
- * Also used in this file so declared first and exported after
32
+ * @param {String } str A text string
33
+ * @returns {String } The substring within the parenthesis
34
+ * Note: It's also used in this file so declared first and exported after
23
35
*/
24
- const getParenthesisInsides = ( str ) => str . match ( / \( ( .* ) \) / ) . pop ( )
36
+ const getParenthesisInsides = str => str . match ( / \( ( .* ) \) / ) . pop ( )
25
37
exports . getParenthesisInsides = getParenthesisInsides
26
38
27
39
/**
28
40
* If a color is transparent then convert it to a hsl-transparent of the paired color
41
+ * @param {Array } colors An array with two colors
42
+ * @returns {Object } A color as chroma object
29
43
*/
30
- exports . transparentFix = ( colors ) => colors . map ( ( color , i ) => {
31
- return color === 'transparent'
32
- ? chroma ( colors [ Math . abs ( i - 1 ) ] ) . alpha ( 0 ) . css ( 'hsl' )
33
- : color
44
+ exports . transparentFix = colors => colors . map ( ( color , i ) => {
45
+ return color === 'transparent' ? chroma ( colors [ Math . abs ( i - 1 ) ] ) . alpha ( 0 ) . css ( 'hsl' ) : color
34
46
} )
35
47
36
48
/**
37
49
* Change value to ';' on child objects of type 'div'
50
+ * @param {Array.<Object> } obj An array of objects
51
+ * @returns {Array.<Object> } An array of objects
38
52
*/
39
- exports . divToSemiColon = ( obj ) => {
53
+ exports . divToSemiColon = obj => {
40
54
obj . map ( childObj => {
41
55
if ( childObj . type === 'div' ) {
42
56
childObj . value = ';'
@@ -48,24 +62,26 @@ exports.divToSemiColon = (obj) => {
48
62
49
63
/**
50
64
* Round alpha in hsl colors to alphaDecimals
65
+ * @param {String } color As an hsl value
66
+ * @param {Number } alphaDecimals An integer specifying max number of deicamals
67
+ * @returns {String } A alpha value rounded version of the hsl color string
51
68
*/
52
69
exports . roundHslAlpha = ( color , alphaDecimals ) => {
53
70
const prefix = getBeforeParenthesisMaybe ( color )
54
71
const values = getParenthesisInsides ( color )
55
72
. split ( ',' )
56
- . map ( string => string . indexOf ( '%' ) === - 1
57
- ? + Number ( string ) . toFixed ( alphaDecimals )
58
- : string . trim ( )
59
- )
60
- color = `${ prefix } (${ values . join ( ', ' ) } )`
73
+ . map ( string => string . indexOf ( '%' ) === - 1 ? + Number ( string ) . toFixed ( alphaDecimals ) : string . trim ( ) )
74
+ color = `${ prefix } (${ values . join ( ', ' ) } )`
61
75
return color
62
76
}
63
77
64
78
/**
65
- * Return an error message
79
+ * Wrap a string telling the user we couldn't parse it
80
+ * @param {String } input A string
81
+ * @returns {String } The full error message wrapped around the string
66
82
*/
67
- exports . errorMsg = ( input ) => {
83
+ exports . errorMsg = input => {
68
84
return `Couldn't parse:
69
- ${ input }
85
+ ${ input }
70
86
Check the syntax to see if it's correct/supported.`
71
87
}
0 commit comments