(obj: any, path: string[] = [], level = 1)
| 90 | const _tailwindConfig = getTWConfig() |
| 91 | |
| 92 | const declareModule = (obj: any, path: string[] = [], level = 1) => |
| 93 | Object.entries(obj).map(([key, value = {} as any]): string => { |
| 94 | const subpath = path.concat(key).join('/') |
| 95 | if ( |
| 96 | level >= config.level // if recursive call is more than desired |
| 97 | || !isJSObject(value) // if its not an object, no more recursion required |
| 98 | || Object.keys(value).find(k => !k.match(NON_ALPHANUMERIC_RE)) // object has non-alphanumeric property (unsafe var name) |
| 99 | ) { |
| 100 | if (isJSObject(value)) { |
| 101 | const [validKeys, invalidKeys]: [string[], string[]] = [[], []] |
| 102 | Object.keys(value).forEach(i => (NON_ALPHANUMERIC_RE.test(i) ? validKeys : invalidKeys).push(i)) |
| 103 | |
| 104 | return `declare module "${config.alias}/${subpath}" { ${validKeys.map(i => `export const _${i}: ${JSON.stringify(value[i])};`).join('')} const defaultExport: { ${validKeys.map(i => `"${i}": typeof _${i}, `).join('')}${invalidKeys.map(i => `"${i}": ${JSON.stringify(value[i])}, `).join('')} }; export default defaultExport; }\n` |
| 105 | } |
| 106 | |
| 107 | return `declare module "${config.alias}/${subpath}" { const defaultExport: ${JSON.stringify(value)}; export default defaultExport; }\n` |
| 108 | } |
| 109 | |
| 110 | const values = Object.keys(value) |
| 111 | return declareModule(value, path.concat(key), level + 1).join('') + `declare module "${config.alias}/${subpath}" {${Object.keys(value).map(v => ` export const _${v}: typeof import("${config.alias}/${join(`${key}/${subpath}`, `../${v}`)}")["default"];`).join('')} const defaultExport: { ${values.map(k => `"${k}": typeof _${k}`).join(', ')} }; export default defaultExport; }\n` |
| 112 | }) |
| 113 | |
| 114 | const configOptions = Object.keys(_tailwindConfig) |
| 115 | return declareModule(_tailwindConfig).join('') + `declare module "${config.alias}" {${configOptions.map(v => ` export const ${v}: typeof import("${join(config.alias, v)}")["default"];`).join('')} const defaultExport: { ${configOptions.map(v => `"${v}": typeof ${v}`)} }; export default defaultExport; }` |
no test coverage detected