@primer/primitives
Version:
Typography, spacing, and color primitives for Primer design system
31 lines (30 loc) • 1.62 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { format } from 'prettier';
import { prefixTokens } from './utilities/prefixTokens.js';
import { jsonToNestedValue } from './utilities/jsonToNestedValue.js';
/**
* @description Takes a style dictionary token dictionary and converts it to a nested json string.
* In contrast to the `json/nested` this formatter does add a prefix if provided
* @param FormatFnArguments
* @returns formatted json `string`
*/
export const jsonNestedPrefixed = (_a) => __awaiter(void 0, [_a], void 0, function* ({ dictionary, file: _file, options, platform }) {
const { outputVerbose } = options;
// add prefix if defined
let tokens = prefixTokens(dictionary.tokens, platform);
if (!outputVerbose) {
tokens = jsonToNestedValue(tokens);
}
// add file header and convert output
const output = JSON.stringify(tokens, null, 2);
// return prettified
return format(output, { parser: 'json', printWidth: 500 });
});