@primer/primitives
Version:
Typography, spacing, and color primitives for Primer design system
26 lines (25 loc) • 1.65 kB
JavaScript
import { namePathToDotNotation } from '../namePathToDotNotation.js';
const composeValueErrorMessage = (token) => {
var _a, _b;
const originalValue = (_a = token.original.$value) !== null && _a !== void 0 ? _a : token.original.value;
const value = (_b = token.$value) !== null && _b !== void 0 ? _b : token.value;
return `Invalid token "${namePathToDotNotation.transform(token, {}, {})}" in file "${token.filePath}". Transformed value: "${JSON.stringify(value)}". ${originalValue ? `Original value: "${JSON.stringify(originalValue)}" ` : ''}This may be due to referencing a token that does not exists.`;
};
const composeValuePropertyErrorMessage = (token, property) => {
var _a, _b;
const originalValue = (_a = token.original.$value) !== null && _a !== void 0 ? _a : token.original.value;
const value = (_b = token.$value) !== null && _b !== void 0 ? _b : token.value;
return `Invalid property "${property}" of token "${namePathToDotNotation.transform(token, {}, {})}" in file "${token.filePath}". Transformed property value: "${value[property]}". ${originalValue ? `Original value: "${originalValue[property]}" ` : ''}This may be due to referencing a token that does not exists.`;
};
export class invalidTokenValueError extends Error {
constructor(token) {
super(composeValueErrorMessage(token));
Error.captureStackTrace(this, invalidTokenValueError);
}
}
export class invalidTokenValuePropertyError extends Error {
constructor(token, property) {
super(composeValuePropertyErrorMessage(token, property));
Error.captureStackTrace(this, invalidTokenValuePropertyError);
}
}