File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export {isDuration} from './isDuration.js'
7
7
export { isFromFile } from './isFromFile.js'
8
8
export { isFontFamily } from './isFontFamily.js'
9
9
export { isFontWeight } from './isFontWeight.js'
10
+ export { isGradient } from './isGradient.js'
10
11
export { isNumber } from './isNumber.js'
11
12
export { isShadow } from './isShadow.js'
12
13
export { isSource } from './isSource.js'
Original file line number Diff line number Diff line change
1
+ import { getMockToken } from '../test-utilities/index.js'
2
+ import { isGradient } from './isGradient.js'
3
+
4
+ describe ( 'Filter: isGradient' , ( ) => {
5
+ it ( 'returns true if $type property is `color`' , ( ) => {
6
+ expect ( isGradient ( getMockToken ( { $type : 'gradient' } ) ) ) . toStrictEqual ( true )
7
+ } )
8
+
9
+ it ( 'returns false if $type property is not `color`' , ( ) => {
10
+ expect ( isGradient ( getMockToken ( { $type : 'pumpkin' } ) ) ) . toStrictEqual ( false )
11
+ } )
12
+
13
+ it ( 'returns false if $type property is missing' , ( ) => {
14
+ expect ( isGradient ( getMockToken ( { alpha : 0.4 } ) ) ) . toStrictEqual ( false )
15
+ } )
16
+
17
+ it ( 'returns false if $type property is falsy' , ( ) => {
18
+ expect ( isGradient ( getMockToken ( { $type : false } ) ) ) . toStrictEqual ( false )
19
+ expect ( isGradient ( getMockToken ( { $type : undefined } ) ) ) . toStrictEqual ( false )
20
+ expect ( isGradient ( getMockToken ( { $type : null } ) ) ) . toStrictEqual ( false )
21
+ } )
22
+ } )
Original file line number Diff line number Diff line change
1
+ import type { TransformedToken } from 'style-dictionary/types'
2
+
3
+ /**
4
+ * @description Checks if token is of $type `gradient`
5
+ * @param token [TransformedToken](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts)
6
+ * @returns boolean
7
+ */
8
+ export const isGradient = ( token : TransformedToken ) : boolean => {
9
+ const typeValue = token . $type ?? token . type
10
+ return typeValue === 'gradient'
11
+ }
You can’t perform that action at this time.
0 commit comments