How to use the postcss.parse function in postcss

To help you get started, we’ve selected a few postcss 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 iamvdo / pleeease / test / pleeease.js View on Github external
it('parses CSS as PostCSS AST', function () {
      var css = 'a{a:a}';
      var ast = postcss.parse(css);
      parsed = internal.parse(ast);
    });
github postcss / postcss-js / test / objectifier.js View on Github external
test('converts declarations to array', t => {
    let root = parse('color: black; color: rgba(0,0,0,.5); color: #000.5;');
    t.deepEqual(postcssJS.objectify(root), {
        color: [
            'black',
            'rgba(0,0,0,.5)',
            '#000.5'
        ]
    });
});
github blivesta / svgpack / test / result.js View on Github external
it('svgpack.css', function (done) {
    var content = readFileSync(dest + '/' + name + '.css')
    var className = postcss.parse(content).nodes[0].selector
    assert.equal(className, '.icon')
    done()
  })
github wix / stylable / tests / formatters.spec.ts View on Github external
function processSource(source: string, options: postcss.ProcessOptions = {}) {
    return process(postcss.parse(source, options));
}
github wix / stylable / tests / formatters.spec.ts View on Github external
function processFormattersFromSource(source: string, options: postcss.ProcessOptions = {}) {
    const parsed = postcss.parse(source, options).nodes![0] as postcss.Rule;

    const formatters = parsed.nodes!.map((decl: any) => {
        return processFormatters(decl).stylable.formatters;
    });

    return formatters;
}
github reactioncommerce / reaction / server / api / core / ui.js View on Github external
function cssToObject(styles) {
  check(styles, Match.OneOf(String, null, undefined, void 0));

  const parsedStyle = postcss.parse(styles || baseStyles);
  const styleObject = postcssJS.objectify(parsedStyle);

  return styleObject;
}
github vovanbo / css2modernizr / lib / css2modernizr.js View on Github external
CSS2Modernizr.prototype.usage = function () {
  var regex, css, results, modules;

  results = [];
  regex = new RegExp("\\." + this.prefix + "(no-)?(" + _.keys(tests).join('|').toLowerCase() + ")", "g");
  css = postcss.parse(this.css);
  css.eachRule(function (rule) {
    _.forEach(rule.selectors, function(selector) {
      var found, key, index;
      found = regex.exec(selector);
      if (found) {
        key = found[2];
        index = _.findKey(results, { 'name': key });
        if (index) {
          results[index]["count"]++;
        } else {
          results.push({
            'name': key,
            'count': 1
          });
        }
      }
github ambar / reiconify / packages / reiconify / lib / svg2jsx.js View on Github external
const styleToObject = styleText => {
  const styleObject = postcssJs.objectify(postcss.parse(styleText))
  return JSON5.stringify(styleObject)
}
github markfinger / unfort / compiler / compiler.js View on Github external
.then(text => {
            const ast = postcss.parse(text);
            const outcome = postcss_ast_dependencies_1.postcssAstDependencies(ast);
            const scan = new FileScan(file);
            scan.identifiers = outcome.identifiers;
            return scan;
        });
    }
github jacobp100 / cssta / compiler / css / getRoot.ts View on Github external
export default (
  inputCss: string,
  allowCombinators = false
): { root: Root; propTypes: PropTypes } => {
  const transformedInput = inputCss.replace(/(\[\s*)@(\w)/g, `$1cssta|$2`);
  const root = postcss.parse(transformedInput);

  iterateChildren(root, nestNode);

  const propTypes = {};
  const validateAndTransformSelectors = selectorParser(container => {
    container.each(selector => {
      if (selector.type !== "selector") {
        throw new Error("Expected selector");
      }

      let didScopeNode = false;

      selector.walk(node => {
        if (node.type === "combinator" && !allowCombinators) {
          throw new Error("Invalid use of combinator in selector");
        } else if (node.type === "nesting") {