How to use postcss-message-helpers - 10 common examples

To help you get started, we’ve selected a few postcss-message-helpers 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 kristoferjoseph / postcss-color-scale / index.js View on Github external
declarations.forEach(function(decl) {
      decl.value = helpers.try(function transformCS() {
        return reduceFunctionCall(decl.value, 'cs', function reduceCS(body) {
          if (!body) {
            return false;
          }
          var parts = body.split(',');
          var value = parseInt(parts[0], 10);
          // Defaults to the --cs-color variable
          var name = parts[1] ? parts[1].trim() : 'color';
          var colorObj = colors[name];
          if (!colorObj) {
            return 'cs(' + body + ')';
          }
          cs = colorObj.func;
          return cs(value);
        });
      }, decl.source);
github zaim / postcss-color-palette / index.js View on Github external
css.eachDecl(function transformDecl (decl) {
      // Check if the decl is of a color-related property and make sure
      // it has a value containing a replaceable color
      if (PROPS.indexOf(decl.prop) === -1 ||
          !decl.value ||
          !KEYWORD_REGEX.test(decl.value)) {
        return;
      }
      // Transform!
      decl.value = helpers.try(function transformValue () {
        return transforms.reduce(function (value, args) {
          return value.replace.apply(value, args);
        }, decl.value);
      }, decl.source);
    });
  };
github btholt / postcss-colors.css / index.js View on Github external
style.eachDecl(function transformDecl(decl) {
      helpers.try(function() {
        var stringArray = decl.value.toLowerCase().split(' ');
        var colorsToReplace = intersection(stringArray, colorsKeys);
        if (colorsToReplace.length > 0) {
          colorsToReplace.map(function(el) {
            decl.value = decl.value.replace( new RegExp(el, 'ig'), colors[el] );
          });
        }
      }, decl.source);
    });
  };
github adam-h / postcss-sass-color-functions / index.js View on Github external
style.walkDecls(function transformDecl(decl) {
      if (!decl.value || !functionsRegex.test(decl.value)) {
        return;
      }

      decl.value = helpers.try(function() {
        return handleFunction(decl.value, decl.source);
      }, decl.source)
    })
  }
github aemoe / webpack-react-framework / node_modules / postcss-calc / index.js View on Github external
function transformValue(node, property) {
      var value = node[property]

      if (!value || !CONTAINS_CALC.test(value)) {
        return
      }

      helpers.try(function transformCSSCalc() {
        var reducedValue = reduceCSSCalc(value, precision)

        if (warnWhenCannotResolve && CONTAINS_CALC.test(reducedValue)) {
          result.warn("Could not reduce expression: " + value,
            {plugin: "postcss-calc", node: node})
        }

        if (!preserve) {
          node[property] = reducedValue
          return
        }

        if (reducedValue != value) {
          var clone = node.clone()
          clone[property] = reducedValue
          node.parent.insertBefore(node, clone)
github sx1989827 / DOClever / Desktop / node_modules / postcss-calc / index.js View on Github external
function transformValue(node, property) {
      var value = node[property]

      if (!value || !CONTAINS_CALC.test(value)) {
        return
      }

      helpers.try(function transformCSSCalc() {
        var reducedValue = reduceCSSCalc(value, precision)

        if (warnWhenCannotResolve && CONTAINS_CALC.test(reducedValue)) {
          result.warn("Could not reduce expression: " + value,
            {plugin: "postcss-calc", node: node})
        }

        if (!preserve) {
          node[property] = reducedValue
          return
        }

        if (reducedValue != value) {
          var clone = node.clone()
          clone[property] = reducedValue
          node.parent.insertBefore(node, clone)
github postcss / postcss-color-function / index.js View on Github external
return
        }
        result.messages.push({
          plugin: "postcss-color-function",
          type: "skipped-color-function-with-custom-property",
          word: decl.value,
          message:
            "Skipped color function with custom property `" +
            decl.value +
            "`",
        })
        return
      } 

      try {
        decl.value = helpers.try(function transformColorValue() {
          return transformColor(decl.value)
        }, decl.source)
      }
      catch (error) {
        decl.warn(result, error.message, {
          word: decl.value,
          index: decl.index,
        })
      }
    })
  }
github btholt / postcss-colorblind / index.js View on Github external
function transformValue(decl, method) {
  var promises = [];
  var cache = '';
  helpers.try(function() {
    cache = valueParser(decl.value).walk(function(node) {
      if (node.type === 'function') {
        var toLower = node.value.toLowerCase();
        if (~['hsl', 'hsla', 'rgb', 'rgba'].indexOf(toLower)) {
          var value = colorTransformer(stringify(node), method);
          node.type = 'word';
          node.value = value;
          return;
        }
        if (toLower === 'url') {
          promises.push(
            getBase64Data(node.nodes[0].value, method).then(function(dataUrl) {
              node.nodes[0].value = dataUrl;
            })
          );
        }
github iamstarkov / postcss-color-mix / index.js View on Github external
const transformDecl = (decl) => {
  if (!decl.value || decl.value.indexOf('mix(') === -1) {
    return;
  }

  decl.value = postcssTry(() => transformColor(decl.value, decl.source), decl.source )
};
github shauns / postcss-math / index.js View on Github external
else if (node.type === 'atrule' && node.name === 'media') {
                nodeProp = 'params';
            }
            else if (node.type === 'rule') {
                nodeProp = 'selector';
            }
            else {
                return;
            }

            var match = functionName + '(';
            if (!node[nodeProp] || node[nodeProp].indexOf(match) === -1) {
                return;
            }

            node[nodeProp] = helpers.try(function () {
                return transformResolve(node[nodeProp], functionName);
            }, node.source);
        })
    };

postcss-message-helpers

PostCSS helpers to throw or output GNU style messages

MIT
Latest version published 10 years ago

Package Health Score

65 / 100
Full package analysis

Popular postcss-message-helpers functions