How to use the postcss-value-parser.unit function in postcss-value-parser

To help you get started, we’ve selected a few postcss-value-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ben-eb / perfectionist / src / applyTransformFeatures.js View on Github external
export default function applyTransformFeatures (node, opts) {
    if (isHex(node)) {
        if (opts.colorCase === 'upper') {
            node.value = node.value.toUpperCase();
        }
        if (opts.colorCase === 'lower') {
            node.value = node.value.toLowerCase();
        }
        if (opts.colorShorthand === true) {
            node.value = toShorthand(node.value);
        }
        if (opts.colorShorthand === false) {
            node.value = toLonghand(node.value);
        }
    }
    const pair = unit(node.value);
    if (pair) {
        if (
            opts.zeroLengthNoUnit === true &&
            ~lengths.indexOf(pair.unit.toLowerCase()) &&
            Number(pair.number) === 0
        ) {
            node.value = '0';
            return;
        }

        const parts = pair.number.split('.');
        let pre = parts[0];
        let post = parts.slice(1).join('.');

        if (opts.trimLeadingZero === true && parts[1]) {
            pre = pre.replace(/^0+/, '');
github ben-eb / css-values / packages / css-values / index.js View on Github external
var isInteger = (function (_ref) {
    var type = _ref.type;
    var value = _ref.value;

    if (type !== 'word') {
        return false;
    }
    var int = unit(value);
    return int && !~value.indexOf('.') && !int.unit;
});
github ben-eb / css-values / src / validators / isInteger.js View on Github external
export default ({type, value}) => {
    if (type !== 'word') {
        return false;
    }
    let int = unit(value);
    return int && !~value.indexOf('.') && !int.unit;
};
github ben-eb / css-values / src / validators / isFrequency.js View on Github external
export default ({type, value}) => {
    if (type !== 'word')  {
        return false;
    }
    let freq = unit(value);
    return freq &&
        !endsWith(freq.number, '.') &&
        !~freq.unit.indexOf('.') &&
        (freq.number === '0' || ~frequencies.indexOf(freq.unit));
};
github stylelint / stylelint / lib / rules / time-no-imperceptible / index.js View on Github external
function isImperceptibleTime(time) {
      const parsedTime = valueParser.unit(time)
      if (!parsedTime) return false
      const absoluteTime = Math.abs(parsedTime.number)
      if (parsedTime.unit.toLowerCase() === "ms" && absoluteTime <= MINIMUM_MILLISECONDS) {
        return true
      }
      if (parsedTime.unit.toLowerCase() === "s" && absoluteTime * 1000 <= MINIMUM_MILLISECONDS) {
        return true
      }
      return false
    }
github ben-eb / css-values / packages / css-values / index.js View on Github external
function isMultiplier(_ref) {
    var type = _ref.type;
    var value = _ref.value;

    if (type !== 'word') {
        return false;
    }
    var int = unit(value);
    return int && !endsWith(int.number, '.') && !~int.unit.indexOf('.') && int.unit === 'x';
};
github ben-eb / css-values / packages / css-values / index.js View on Github external
var isPercentage = (function (_ref) {
    var value = _ref.value;

    var int = unit(value);
    return int && !endsWith(int.number, '.') && !~int.unit.indexOf('.') && int.unit === '%';
});
github ben-eb / css-values / packages / css-values / index.js View on Github external
var isLength = (function (node) {
    if (isCalc(node)) {
        return true;
    }
    if (node.type !== 'word') {
        return false;
    }
    var int = unit(node.value);
    return int && !endsWith(int.number, '.') && !~int.unit.indexOf('.') && (int.number === '0' || ~lengths.indexOf(int.unit));
});
github stylelint / stylelint / src / rules / time-no-imperceptible / index.js View on Github external
function isImperceptibleTime(time) {
      const parsedTime = valueParser.unit(time)
      if (!parsedTime) return false
      const absoluteTime = Math.abs(parsedTime.number)
      if (parsedTime.unit.toLowerCase() === "ms" && absoluteTime <= MINIMUM_MILLISECONDS) { return true }
      if (parsedTime.unit.toLowerCase() === "s" && absoluteTime * 1000 <= MINIMUM_MILLISECONDS) { return true }
      return false
    }

postcss-value-parser

Transforms css values and at-rule params into the tree

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis