-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): add sass-export util
- Loading branch information
1 parent
6570383
commit 1b3ab73
Showing
3 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './property-checkers'; | ||
export * from './is-motion-reduced'; | ||
export * from './sass-export'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export function parse(scss: object) { | ||
const output: { [key: string]: any } = {}; | ||
|
||
return Object.entries(scss).reduce((object, [path, value]) => { | ||
let temp: any = object; | ||
|
||
path.split('_').forEach((key: string, index: number, values: string[]) => { | ||
const isJsonArray = typeof value === 'string' && /^\[.*\]$/.test(value); | ||
const parsedValue = isJsonArray ? JSON.parse(value) : value; | ||
const v = index === values.length - 1 ? parsedValue : temp[key] || {}; | ||
|
||
temp[key] = v; | ||
temp = temp[key]; | ||
}); | ||
|
||
return object; | ||
}, output); | ||
} | ||
|
||
export function formatAsMap(obj: object) { | ||
return JSON.stringify(obj, null, 2).replace(/[{\[]/g, '(').replace(/[}\]]/g, ')'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters