UNPKG

stylelint-8-point-grid

Version:

Stylelint plugin to validate CSS with 8-point grid guideline

32 lines (31 loc) 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validBase = function (base) { return base % 1 === 0; }; exports.hasSupportedValue = function (value) { return String(value).includes('px') || String(value).includes('rem'); }; exports.hasPixelValue = function (value) { return value.includes('px'); }; exports.hasRemValue = function (value) { return value.includes('rem'); }; exports.isString = function (value) { return typeof value === 'string'; }; var isAllowlist = function (allowlist, value) { return (allowlist && allowlist.includes(value)) || false; }; var divisibleBy = function (value, base) { var baseRem = base / 16; if (exports.hasRemValue(value)) { // parseFloat() drops units at the end automatically var number_1 = parseFloat(value); return number_1 % Number(baseRem) === 0; } var number = value.match(/\d+/); return Number(number) % Number(base) === 0; }; exports.validSupportedValue = function (value, base, allowlist) { return ( // handle multiple supported values // e.g. padding: 8px 8px 1px 8px or padding: 3rem 8px 8px 8px; value .split(/[\s\r\n]+/) .filter(exports.hasSupportedValue) .every(function (value) { return isAllowlist(allowlist, value) || divisibleBy(value, base); })); };