How to use the postcss-value-parser 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 stylelint / stylelint / src / rules / number-leading-zero / index.js View on Github external
function check(node, value, getIndex) {
      // Get out quickly if there are no periods
      if (value.indexOf(".") === -1) { return }

      valueParser(value).walk(valueNode => {
        // Ignore `url` function
        if (valueNode.type === "function" && valueNode.value.toLowerCase() === "url") { return false }

        // Ignore strings, comments, etc
        if (valueNode.type !== "word") { return }

        // Check leading zero
        if (expectation === "always") {
          const match = /(?:\D|^)(\.\d+)/.exec(valueNode.value)

          if (match === null) { return }

          // The regexp above consists of 2 capturing groups (or capturing parentheses).
          // We need the index of the second group. This makes sanse when we have "-.5" as an input
          // for regex. And we need the index of ".5".
          const capturingGroupIndex = match[0].length - match[1].length
github salesforce / lwc / packages / @lwc / style-compiler / src / custom-properties / transform.ts View on Github external
root.walkDecls(decl => {
        const valueRoot = parseValue(decl.value);
        let varFound = false;
        valueRoot.walk(({ type, value }) => {
            if (!varFound && type === 'function' && value === 'var') {
                // Add the imported to results messages
                const message = varFunctionMessage(value);
                result.messages.push(message);
                varFound = true;
            }
        });
    });
}
github stylelint / stylelint / src / rules / unit-no-unknown / index.js View on Github external
function check(node, value, getIndex) {
      valueParser(value).walk(function (valueNode) {
        // Ignore wrong units within `url` function
        if (valueNode.type === "function" && valueNode.value.toLowerCase() === "url") { return false }

        const unit = getUnitFromValueNode(valueNode)
        if (!unit) { return }

        if (optionsMatches(options, "ignoreUnits", unit)) { return }

        if (units.has(unit.toLowerCase())) { return }

        report({
          index: getIndex(node) + valueNode.sourceIndex,
          message: messages.rejected(unit),
          node,
          result,
          ruleName,
github jturle / postcss-sketch / src / index.js View on Github external
css.walkDecls(decl => {
            if (decl.value.indexOf('sketch(') !== -1) {
                let parsedValue = valueParser(decl.value);

                let file = parsedValue.nodes[0].nodes[0].value;

                // Resolve the file reference.
                let fileRef;
                if (decl.source.input.file)
                    fileRef = path.join(
                        path.dirname(decl.source.input.file),
                        file
                    ); // Relative to CSS File
                else fileRef = path.join(file); // No CSS file, probably testing

                // Retrieve the sketch JSON dump
                let sketchData = getSketchJSON(path.resolve(fileRef));

                // Add a dependency.
github stylelint / stylelint / src / rules / unit-case / index.js View on Github external
root.walkDecls(decl => {
      valueParser(decl.value).walk((node) => {
        // Ignore wrong units within `url` function
        if (node.type === "function" && node.value.toLowerCase() === "url") { return false }

        const unit = getUnitFromValueNode(node)

        if (!unit) { return }

        const expectedUnit = expectation === "lower" ? unit.toLowerCase() : unit.toUpperCase()

        if (unit === expectedUnit) { return }

        report({
          message: messages.expected(unit, expectedUnit),
          node: decl,
          index: declarationValueIndex(decl) + node.sourceIndex,
          result,
github parcel-bundler / parcel / packages / transformers / css / src / CSSTransformer.js View on Github external
ast.program.walkDecls(decl => {
      if (URL_RE.test(decl.value)) {
        let parsed = valueParser(decl.value);
        let isDirty = false;

        parsed.walk(node => {
          if (
            node.type === 'function' &&
            node.value === 'url' &&
            node.nodes.length
          ) {
            node.nodes[0].value = asset.addURLDependency(node.nodes[0].value, {
              loc: createDependencyLocation(
                decl.source.start,
                node.nodes[0].value
              )
            });
            isDirty = true;
          }
github simonsmith / postcss-at2x / lib / index.js View on Github external
function extractUrlValue(url, source, resolveImagePath) {
  const parsedValue = valueParser(url);
  let urlValue = '';

  parsedValue.walk((node) => {
    if (node.type !== 'function' || (node.type === 'function' && node.value !== 'url')) {
      return;
    }
    node.nodes.forEach((fp) => {
      if (!isUrl(fp.value)) {
        urlValue = resolveImagePath(fp.value, source);
      }
    });
  });
  return urlValue;
}
github ben-eb / postcss-resemble-image / src / index.js View on Github external
function resemblePromise (decl, opts, wrapped = true) {
    const promises = [];

    let url;
    let toString;

    decl.value = valueParser(decl.value).walk((node, index, nodes) => {
        const {type, value} = node;
        if (type !== 'function') {
            return false;
        }
        if (wrapped && value === resembleFunction) {
            url = node.nodes[0].nodes[0].value;
            toString = node.nodes[0];
        }
        if (!wrapped && value === 'url') {
            url = node.nodes[0].value;
            toString = node;
        }
        if (!url) {
            return false;
        }
        const second = node.nodes[2];
github styled-components / css-to-react-native / src / index.js View on Github external
const baseTransformShorthandValue = (propName, inputValue) => {
  const ast = parse(inputValue.trim())
  const tokenStream = new TokenStream(ast.nodes)
  return transforms[propName](tokenStream)
}

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