@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
20 lines • 547 B
JavaScript
const emRegex = /(.*\d+)em$/;
const invalidSpacingUnitRegex = /(\d+rem$)|(vw$)|(vh$)/;
export const isValidSpacingValue = (value, fontSize) => {
if (typeof value === 'string') {
if (invalidSpacingUnitRegex.test(value)) {
return false;
}
} else if (Array.isArray(value)) {
// could be array due to shorthand
for (const val in value) {
if (invalidSpacingUnitRegex.test(val)) {
return false;
}
}
}
if (emRegex.test(value) && typeof fontSize !== 'number') {
return false;
}
return true;
};