Skip to content

Commit 5beb4d5

Browse files
add gradient filter
1 parent e62756f commit 5beb4d5

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/filters/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {isDuration} from './isDuration.js'
77
export {isFromFile} from './isFromFile.js'
88
export {isFontFamily} from './isFontFamily.js'
99
export {isFontWeight} from './isFontWeight.js'
10+
export {isGradient} from './isGradient.js'
1011
export {isNumber} from './isNumber.js'
1112
export {isShadow} from './isShadow.js'
1213
export {isSource} from './isSource.js'

src/filters/isGradient.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
})

src/filters/isGradient.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}

0 commit comments

Comments
 (0)