-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { withPrefix } from './with-prefix' | ||
import { Shape, FlattenToken, Token, TokensMap } from './token.h' | ||
|
||
/** | ||
* Returns flatten shape with tokens. | ||
* | ||
* @param tokens Map with tokens. | ||
*/ | ||
export function flatTokens(tokens: TokensMap, __prefix__?: string): Shape<FlattenToken> { | ||
const result: Shape<FlattenToken> = {} | ||
for (const key in tokens) { | ||
const transformedKey = withPrefix(key, __prefix__) | ||
const maybeToken = tokens[key] | ||
if (maybeToken.value === undefined) { | ||
Object.assign(result, flatTokens(maybeToken as TokensMap, transformedKey)) | ||
} else { | ||
result[transformedKey] = { | ||
...maybeToken as Token, | ||
name: transformedKey, | ||
} | ||
} | ||
} | ||
return result | ||
} |
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,12 @@ | ||
/** | ||
* Returns string with prefix. | ||
* | ||
* @param value Raw string. | ||
* @param prefix Prefix for string. | ||
*/ | ||
export function withPrefix(value: string, prefix?: string): string { | ||
if (prefix === undefined) { | ||
return value | ||
} | ||
return `${prefix}_${value}` | ||
} |