How to use postcss-value-parser - 10 common examples

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 parcel-bundler / parcel / packages / core / parcel-bundler / src / assets / CSSAsset.js View on Github external
throw new Error('Could not find import name for ' + rule);
      }

      if (PROTOCOL_RE.test(dep)) {
        return;
      }

      // If this came from an inline <style> tag, don't inline the imported file. Replace with the correct URL instead.
      // TODO: run CSSPackager on inline style tags.
      let inlineHTML =
        this.options.rendition && this.options.rendition.inlineHTML;
      if (inlineHTML) {
        name.value = this.addURLDependency(dep, {loc: rule.source.start});
        rule.params = params.toString();
      } else {
        media = valueParser.stringify(media).trim();
        this.addDependency(dep, {media, loc: rule.source.start});
        rule.remove();
      }

      this.ast.dirty = true;
    });
</style>
github corysimmons / postcss-ant / lib / helpers / generate-grid.js View on Github external
export default (node, localOpts, direction, decl, firstColumnSetLength, foundColumnsAndRows, prevSourceIndex, locallySpecified, lastColumnSetLength) =&gt; {
  // Grab all the contents within the function and sort them into size sets.
  const value: string = valueParser.stringify(node.nodes)
  const sizeSets: Array = postcss.list.comma(value)
  let totalSizes: number = 0
  sizeSets.map(sizeSet =&gt; {
    totalSizes += postcss.list.space(sizeSet).length
  })

  // Determine if this is the last/first columns() or rows() call in the declaration value.
  let lastCall: boolean = false
  let firstCall: boolean = false
  if (node.sourceIndex &gt; prevSourceIndex) {
    lastCall = true
  }
  if (node.sourceIndex === 0){
    firstCall = true
  }
github corysimmons / postcss-ant / lib / index.js View on Github external
break

            case `${localOpts.namespace}support`:
              localOpts.support = valueParser.stringify(node.nodes) ? valueParser.stringify(node.nodes) : opts.support
              break

            case `${localOpts.namespace}pluck`:
              localOpts.pluck = Number(valueParser.stringify(node.nodes)) ? Number(valueParser.stringify(node.nodes)) : opts.pluck
              break

            case `${localOpts.namespace}bump`:
              localOpts.bump = ` ${valueParser.stringify(node.nodes)}` ? ` ${valueParser.stringify(node.nodes)}` : opts.bump
              break

            case `${localOpts.namespace}technique`:
              localOpts.technique = valueParser.stringify(node.nodes) ? valueParser.stringify(node.nodes) : opts.technique
              break

            case `${localOpts.namespace}children`:
              localOpts.children = valueParser.stringify(node.nodes) ? valueParser.stringify(node.nodes) : opts.children
              break

            default:
              break
          }

          // Poorly erase the function (leaves whitespace). It would be nice if there was a .remove() method in valueParser.
          node.value = ''
        }
      }, false) // shallow
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 makuga01 / dnsFookup / FE / node_modules / autoprefixer / lib / hacks / gradient.js View on Github external
_proto.oldWebkit = function oldWebkit(node) {
    var nodes = node.nodes;
    var string = parser.stringify(node.nodes);

    if (this.name !== 'linear-gradient') {
      return false;
    }

    if (nodes[0] && nodes[0].value.includes('deg')) {
      return false;
    }

    if (string.includes('px') || string.includes('-corner') || string.includes('-side')) {
      return false;
    }

    var params = [[]];

    for (var _iterator4 = _createForOfIteratorHelperLoose(nodes), _step4; !(_step4 = _iterator4()).done;) {
github daviddbarrero / Ionic-4-firebase / node_modules / autoprefixer / lib / hacks / gradient.js View on Github external
Gradient.prototype.oldWebkit = function oldWebkit(node) {
        var nodes = node.nodes;

        var string = parser.stringify(node.nodes);

        if (this.name !== 'linear-gradient') {
            return false;
        }
        if (nodes[0] && nodes[0].value.indexOf('deg') !== -1) {
            return false;
        }
        if (string.indexOf('px') !== -1 || string.indexOf('-corner') !== -1 || string.indexOf('-side') !== -1) {
            return false;
        }

        var params = [[]];
        for (var _iterator3 = nodes, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
            var _ref3;

            if (_isArray3) {

postcss-value-parser

Transforms css values and at-rule params into the tree

MIT
Latest version published 3 years ago

Package Health Score

74 / 100
Full package analysis