@primer/primitives
Version:
Typography, spacing, and color primitives for Primer design system
27 lines (26 loc) • 1.61 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 { jsonToNestedValue } from './utilities/jsonToNestedValue.js';
import { prefixTokens } from './utilities/prefixTokens.js';
import { fileHeader } from 'style-dictionary/utils';
/**
* @description Converts `StyleDictionary.dictionary.tokens` to javascript commonJS module
* @param arguments [FormatterArguments](https://github.com/amzn/style-dictionary/blob/main/types/Format.d.ts)
* @returns formatted `string`
*/
export const javascriptCommonJs = (_a) => __awaiter(void 0, [_a], void 0, function* ({ dictionary, file, platform }) {
// add prefix if defined
const tokens = prefixTokens(dictionary.tokens, platform);
// add file header and convert output
const output = `${yield fileHeader({ file })}module.exports = ${JSON.stringify(jsonToNestedValue(tokens), null, 2)}\n`;
// return prettified
return format(output, { parser: 'typescript', printWidth: 500 });
});