How to use the css.parse function in css

To help you get started, we’ve selected a few css 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 davidmerfield / Blot / app / brochure / routes / tools / inline-css.js View on Github external
$('style[type="text/css"]').each(function() {
      if ($(this).attr("data-skip-inline")) {
        $(this).removeAttr("data-skip-inline");
        return;
      }
      // If the style tag is inside a 
github robinpokorny / grunt-legacssy / tasks / legacssy.js View on Github external
this.files.forEach(function(f) {
      var src = f.src.filter(function(filepath) {
        // Warn on and remove invalid source files (if nonull was set).
        if (!grunt.file.exists(filepath)) {
          grunt.log.warn('Source file "' + filepath + '" not found.');
          return false;
        } else {
          return true;
        }
      }).map(function(filepath) {
        // Read file source.
        return grunt.file.read(filepath);
      }).join(grunt.util.normalizelf(grunt.util.linefeed));

      // Parse the style
      var style = css.parse(src);

      // Do the magic!
      style.stylesheet.rules = stripMediaQueries(style.stylesheet.rules, options.overridesOnly);

      var output = css.stringify(style);
      // Write the destination file.
      grunt.file.write(f.dest, output);

      // Print a success message.
      grunt.log.writeln('File "' + chalk.cyan(f.dest) + '" created: ' +
                        maxmin(src, output, false));
    });
  });
github w3c / Mobile-Checker / lib / checks / compatibility / css-prefixes.js View on Github external
browser.on('har', function(har, done) {
        if (har && har.log && har.log.entries) {
            for (var i = 0; i < har.log.entries.length; i++) {
                var entry = har.log.entries[i];
                if (entry.response.status === 200) {
                    var mediaType = utils.mediaTypeName(entry.response.content
                        .mimeType);
                    if (mediaType === "text/css") {
                        if (entry.response.content.text === undefined) {
                            // not sure why that happens
                            // but cssparser breaks on undefined
                            continue;
                        }

                        var url = entry.request.url;
                        var cssObj = cssParser.parse(entry.response.content
                            .text, {
                                silent: true
                            });
                        for (var j = 0; j < cssObj.stylesheet.rules.length; j++) {
                            var rule = cssObj.stylesheet.rules[j];
                            var prefixedProperties = {};
                            var unprefixedProperties = {};
                            if (rule.declarations) {
                                for (var k = 0; k < rule.declarations.length; k++) {
                                    var decl = rule.declarations[k];
                                    if (decl.property && hasprefix(decl.property)) {
                                        var unprefixed = unprefix(decl.property);
                                        if (!prefixedProperties[unprefixed]) {
                                            prefixedProperties[unprefixed] = {};
                                        }
                                        prefixedProperties[unprefixed][decl
github felipenmoura / sos-stackoverflow-search / src / highlighter.js View on Github external
tagStr = tagStr.replace(attr, cliColor.redBright(attr));
                        });
                    }
                    
                    tagStr = tagStr.replace(new RegExp('\\'+tagName, 'ig'), cliColor.blueBright(tagName));
                        
                    str = str.replace(tag, tagStr);
                }
            });
            str = str.replace(/\>/g, cliColor.blueBright('>'));
            str = str.replace(/\<\!DOCTYPE html(.+)?\>(.+)?/i, cliColor.bold.blackBright(''));
            
        }else if (str.match(/(^|\n)( +)?[\.\:\#\[\]][a-z0-9\-\_\=\(\)\, \[\]]([\s\S]+)?\{/i)) {
            // is probably css
            let css = require('css');
            let obj = css.parse(str, {silent:true});
            let cssResult = '';
            
            if(!obj.parsingErrors){
                
                let i = 1;
                obj.stylesheet.rules.forEach(rule=>{
                    let sels = [];
                    rule.selectors.forEach(selector => {
                        let selStr = cliColor.blueBright(selector
                            .replace(/\[/g, cliColor.magenta('['))
                            .replace(/\:hover/g, cliColor.redBright(":hover"))
                            .replace(/\:active/g, cliColor.redBright(":active"))
                            .replace(/\:visited/g, cliColor.redBright(":visited"))
                            .replace(/\:link/g, cliColor.redBright(":link"))
                            .replace(/\:after/g, cliColor.redBright(":after"))
                            .replace(/\:before/g, cliColor.redBright(":before"))
github emotion-js / emotion / next-packages / snapshot-serializer / src / index.js View on Github external
function getPrettyStylesFromClassNames(
  classNames: Array,
  elements: Array
) {
  let styles = getStylesFromClassNames(classNames, elements)

  let prettyStyles
  try {
    prettyStyles = css.stringify(css.parse(styles))
  } catch (e) {
    console.error(e)
    throw new Error(`There was an error parsing the following css: "${styles}"`)
  }
  return prettyStyles
}
github NickIliev / NativeScript-Firebase-Auth / firebaseAuth / platforms / android / build / intermediates / assets / F0F1 / debug / app / tns_modules / ui / styling / style-scope.js View on Github external
StyleScope.createSelectorsFromCss = function (css, cssFileName, keyframes) {
        try {
            var pageCssSyntaxTree = css ? cssParser.parse(css, { source: cssFileName }) : null;
            var pageCssSelectors = [];
            if (pageCssSyntaxTree) {
                pageCssSelectors = pageCssSelectors.concat(StyleScope.createSelectorsFromImports(pageCssSyntaxTree, keyframes));
                pageCssSelectors = pageCssSelectors.concat(StyleScope.createSelectorsFromSyntaxTree(pageCssSyntaxTree, keyframes));
            }
            return pageCssSelectors;
        }
        catch (e) {
            trace.write("Css styling failed: " + e, trace.categories.Error, trace.messageType.error);
        }
    };
    StyleScope.createSelectorsFromImports = function (tree, keyframes) {
github pubpub / pubpub-editor / src / utils / index.js View on Github external
const parseStyleToObject = (style) => {
	try {
		const styleObj = {};
		const wrappedStyle = `.whatever { ${style} } `;
		const cssAst = css.parse(wrappedStyle);
		const { declarations } = cssAst.stylesheet.rules[0];
		declarations.forEach(({ property, value }) => {
			const camelCaseProperty = camelCaseCss(property);
			styleObj[camelCaseProperty] = value;
		});
		return styleObj;
	} catch (_) {
		return {};
	}
};
github patternfly / patternfly-react / packages / react-styles / src / build / jest / snapshot-serializer / cssUtils.js View on Github external
function formatComputedStyles(nodeSelectors, computedStyles) {
  const selector = nodeSelectors.join('');
  const cssString = `${selector} {
    ${Object.keys(computedStyles)
      .map(k => `${k}: ${computedStyles[k]};`)
      .join('\n')}
  }`;
  return css.stringify(css.parse(cssString));
}
github twitter-archive / css-flip / lib / css-flip.js View on Github external
function flip(str, options) {
  var ast = css.parse(str, options);

  flipNode(ast.stylesheet);

  return css.stringify(ast, options);
}
github jhamlet / svg-react-loader / lib / sanitize / filters / prefix-style-class-id.js View on Github external
function processStyles (opts, source) {
    var ast = css.parse(source);
    var rules = ast.stylesheet.rules;

    rules.
        forEach(function (rule) {
            var selectors = rule.selectors;

            rule.selectors =
                selectors.
                map(function (sel) {
                    return sel.
                        replace(
                            CLASSNAME_OR_ID_SELECTOR_REGEX,
                            function (match, pre, post) {
                                var newname = pre + opts.prefix + post;
                                opts.cache[post] = newname;
                                return newname;