Download chakra-ui/packages/react/src/styled-system/references.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/react/src/styled-system/references.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/react/src/styled-system/references.ts
-
curl -L -o references.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/react/src/styled-system/references.ts
1.17 kB
| import { isString } from "../utils" | |
| import type { Token } from "./types" | |
| const REFERENCE_REGEX = /({([^}]*)})/g | |
| const CURLY_REGEX = /[{}]/g | |
| export const TOKEN_PATH_REGEX = /\w+\.\w+/ | |
| export const getReferences = (value: string) => { | |
| if (!isString(value)) return [] | |
| const matches = value.match(REFERENCE_REGEX) | |
| if (!matches) return [] | |
| return matches | |
| .map((match) => match.replace(CURLY_REGEX, "")) | |
| .map((value) => value.trim()) | |
| } | |
| export const hasReference = (value: string) => REFERENCE_REGEX.test(value) | |
| export function expandReferences(token: Token) { | |
| if (!token.extensions?.references) { | |
| return token.extensions?.cssVar?.ref ?? token.value | |
| } | |
| const references = token.extensions.references ?? {} | |
| token.value = Object.keys(references).reduce((valueStr, key) => { | |
| const referenceToken = references[key] | |
| // If a conditional token is referenced, we'll keep the reference | |
| if (referenceToken.extensions.conditions) { | |
| return valueStr | |
| } | |
| const value = expandReferences(referenceToken) | |
| return valueStr.replace(`{${key}}`, value) | |
| }, token.value) | |
| delete token.extensions.references | |
| return token.value | |
| } | |