@cobalt-ui/plugin-json
Advanced tools
Comparing version 0.0.0 to 0.1.0
@@ -1,2 +0,2 @@ | ||
import type { Plugin, SchemaNode } from '@cobalt-ui/core'; | ||
import type { Plugin, Token } from '@cobalt-ui/core'; | ||
export interface JSONOutput { | ||
@@ -17,4 +17,4 @@ name?: string; | ||
/** modify values */ | ||
transformValue?: (value: any, token: SchemaNode) => any; | ||
transformValue?: (token: Token, mode?: string) => any; | ||
} | ||
export default function json(options?: Options): Plugin; |
@@ -10,20 +10,13 @@ export default function json(options) { | ||
fileName, | ||
contents: JSON.stringify(schema, (_, v) => { | ||
// prevent circular refs for JSON | ||
if (v.group) | ||
delete v.group; | ||
contents: JSON.stringify(schema, (_, token) => { | ||
// apply transformValue() | ||
if (transform && (v.type === 'token' || v.type === 'url' || v.type === 'file') && typeof v.value === 'object') { | ||
if (Array.isArray(v.value)) { | ||
for (let n = 0; n < v.value.length; n++) { | ||
v.value[n] = transform(v.value[n], v); | ||
if (transform && typeof token.type == 'string') { | ||
token.value = transform(token); | ||
if (token.mode) { | ||
for (const mode of Object.keys(token.mode)) { | ||
token.mode[mode] = transform(token, mode); | ||
} | ||
} | ||
else { | ||
for (const k of Object.keys(v.value)) { | ||
v.value[k] = transform(v.value[k], v); | ||
} | ||
} | ||
} | ||
return v; | ||
return token; | ||
}, 2), | ||
@@ -30,0 +23,0 @@ }, |
{ | ||
"name": "@cobalt-ui/plugin-json", | ||
"description": "JSON builder for Cobalt UI design tokens", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"author": { | ||
@@ -9,13 +9,21 @@ "name": "Drew Powers", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/drwpow/cobalt-ui.git", | ||
"directory": "packages/plugin-json" | ||
}, | ||
"homepage": "https://cobalt-ui.pages.dev", | ||
"license": "MIT", | ||
"type": "module", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"devDependencies": { | ||
"@cobalt-ui/core": "^0.1.0" | ||
}, | ||
"scripts": { | ||
"build": "rm -rf dist && tsc", | ||
"build": "tsc", | ||
"dev": "tsc -w" | ||
}, | ||
"devDependencies": { | ||
"@cobalt-ui/core": "^0.0.0" | ||
} | ||
} | ||
"readme": "# @cobalt-ui/plugin-json\n\nGenerate JSON output from design tokens.\n\n```\nnpm i -D @cobalt-ui/plugin-json\n```\n\n```js\n// tokens.config.mjs\nimport json from \"@cobalt-ui/plugin-json\";\n\nexport default {\n plugins: [\n json({\n /** set the filename inside outDir */\n fileName: \"./tokens.json\",\n /** modify values */\n transformValue(value, token) {\n return value;\n },\n }),\n ],\n};\n```\n" | ||
} |
@@ -10,4 +10,4 @@ # @cobalt-ui/plugin-json | ||
```js | ||
// cobalt.config.mjs | ||
import json from '@cobalt-ui/plugin-json'; | ||
// tokens.config.mjs | ||
import json from "@cobalt-ui/plugin-json"; | ||
@@ -18,3 +18,3 @@ export default { | ||
/** set the filename inside outDir */ | ||
fileName: './tokens.json', | ||
fileName: "./tokens.json", | ||
/** modify values */ | ||
@@ -21,0 +21,0 @@ transformValue(value, token) { |
@@ -1,2 +0,2 @@ | ||
import type { BuildResult, Plugin, SchemaNode } from '@cobalt-ui/core'; | ||
import type { BuildResult, Plugin, Token } from '@cobalt-ui/core'; | ||
@@ -22,3 +22,3 @@ export interface JSONOutput { | ||
/** modify values */ | ||
transformValue?: (value: any, token: SchemaNode) => any; | ||
transformValue?: (token: Token, mode?: string) => any; | ||
} | ||
@@ -38,19 +38,13 @@ | ||
schema, | ||
(_, v) => { | ||
// prevent circular refs for JSON | ||
if (v.group) delete v.group; | ||
(_, token) => { | ||
// apply transformValue() | ||
if (transform && (v.type === 'token' || v.type === 'url' || v.type === 'file') && typeof v.value === 'object') { | ||
if (Array.isArray(v.value)) { | ||
for (let n = 0; n < v.value.length; n++) { | ||
v.value[n] = transform(v.value[n], v); | ||
if (transform && typeof token.type == 'string') { | ||
token.value = transform(token); | ||
if (token.mode) { | ||
for (const mode of Object.keys(token.mode)) { | ||
token.mode[mode] = transform(token, mode); | ||
} | ||
} else { | ||
for (const k of Object.keys(v.value)) { | ||
v.value[k] = transform(v.value[k], v); | ||
} | ||
} | ||
} | ||
return v; | ||
return token; | ||
}, | ||
@@ -57,0 +51,0 @@ 2 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
5661
7
1
0
93