UNPKG

stylelint-8-point-grid

Version:

Stylelint plugin to validate CSS with 8-point grid guideline

24 lines (23 loc) 927 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validBase = function (base) { return base > 0; }; exports.hasSupportedValue = function (value) { return String(value).includes('px') || String(value).includes('rem'); }; var isAllowlist = function (allowlist, value) { return (allowlist && allowlist.includes(value)) || false; }; var divisibleBy = function (value, base) { // parseFloat() drops units at the end automatically var number = parseFloat(value); return number % Number(base) === 0; }; exports.validSupportedValue = function (value, base, allowlist) { return ( // handle multiple supported values // e.g. padding: 8px 8px 1px 8px or padding: 3em 8px 8px 8px; value .split(/[\s\r\n]+/) .filter(exports.hasSupportedValue) .every(function (value) { return isAllowlist(allowlist, value) || divisibleBy(value, base); })); };