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

To help you get started, we’ve selected a few postcss-values-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 Pavliko / postcss-svg / src / lib / transpile-decl.js View on Github external
export default function transpileDecl(result, promises, decl, opts, cache) { // eslint-disable-line max-params
	// path to the current working file and directory by declaration
	const declWF = path.resolve(decl.source && decl.source.input && decl.source.input.file ? decl.source.input.file : result.root.source && result.root.source.input && result.root.source.input.file ? result.root.source.input.file : path.join(process.cwd(), 'index.css'));
	const declWD = path.dirname(declWF);

	// list of files to watch
	const files = {};

	// walk each node of the declaration
	const declAST = parser(decl.value).parse();

	declAST.walk(node => {
		// if the node is a url containing an svg fragment
		if (isExternalURLFunction(node)) {
			//  of url()
			const urlNode = node.nodes[1];

			//  split by fragment identifier symbol (#)
			const urlParts = urlNode.value.split('#');

			//  src
			const src = urlParts[0];

			//  fragment identifier
			const id = urlParts.slice(1).join('#');
github signal-noise / stylelint-scales / lib / rules / word-spacing / index.js View on Github external
function check(decl, size) {
      // Parse the size and walk through Numerics
      parse(size, {
        ignoreUnknownWords: true
      }).walkNumerics(({ value, unit: valueUnit }) => {
        // Return early if not a checked unit
        if (!lengthUnits.includes(valueUnit)) return;

        // Validate scale and units
        const validUnit = unit ? valueUnit === unit : true;
        const validScale = scale.includes(Math.abs(Number(value)));

        // Get message of the violation
        let message;
        if (!validScale) {
          message = messages.expected(`${value}`, scale.join(", "));
        } else if (!validUnit) {
          message = messages.expected(`${valueUnit}`, `${unit}`);
        } else {
github signal-noise / stylelint-scales / lib / rules / font-size / index.js View on Github external
function check(decl, size) {
      // Parse the size and walk through Numerics
      parse(size, {
        ignoreUnknownWords: true
      }).walkNumerics(({ value, unit: valueUnit }) => {
        // Return early if not a checked unit
        if (!lengthUnits.includes(valueUnit)) return;

        // Validate scale and units
        const validUnit = unit ? valueUnit === unit : true;
        const validScale = scale.includes(Number(value));

        // Get message of the violation
        let message;
        if (!validScale) {
          message = messages.expected(`${value}`, scale.join(", "));
        } else if (!validUnit) {
          message = messages.expected(`${valueUnit}`, `${unit}`);
        } else {
github signal-noise / stylelint-scales / lib / rules / sizes / index.js View on Github external
function check(decl, size) {
      // Parse the size and walk through Numerics
      parse(size, {
        ignoreUnknownWords: true
      }).walkNumerics(({ value, unit: valueUnit }) => {
        // Return early if not a checked unit
        if (!lengthUnits.includes(valueUnit)) return;

        // Validate scale and units
        const validUnit = unit ? valueUnit === unit : true;
        const validScale = scale.includes(Number(value));

        // Get message of the violation
        let message;
        if (!validScale) {
          message = messages.expected(`${value}`, scale.join(", "));
        } else if (!validUnit) {
          message = messages.expected(`${valueUnit}`, `${unit}`);
        } else {
github signal-noise / stylelint-scales / lib / rules / letter-spacing / index.js View on Github external
function check(decl, size) {
      // Parse the size and walk through Numerics
      parse(size, {
        ignoreUnknownWords: true
      }).walkNumerics(({ value, unit: valueUnit }) => {
        // Return early if not a checked unit
        if (!lengthUnits.includes(valueUnit)) return;

        // Validate scale and units
        const validUnit = unit ? valueUnit === unit : true;
        const validScale = scale.includes(Math.abs(Number(value)));

        // Get message of the violation
        let message;
        if (!validScale) {
          message = messages.expected(`${value}`, scale.join(", "));
        } else if (!validUnit) {
          message = messages.expected(`${valueUnit}`, `${unit}`);
        } else {
github postcss / postcss-custom-properties / src / lib / get-custom-properties-from-root.js View on Github external
rule.nodes.slice().forEach(decl => {
				if (isCustomDecl(decl) && !isBlockIgnored(decl)) {
					const { prop } = decl;

					// write the parsed value to the custom property
					customPropertiesObject[prop] = parse(decl.value).nodes;

					// conditionally remove the custom property declaration
					if (!opts.preserve) {
						decl.remove();
					}
				}
			});
github csstools / postcss-env-function / src / lib / get-replaced-value.js View on Github external
export default (originalValue, variables) => {
	// get the ast of the original value
	const ast = parse(originalValue);

	// walk all of the css env() functions
	walkEnvFuncs(ast, node => {
		// update the environment value for the css env() function
		updateEnvValue(node, variables);
	});

	// return the stringified ast
	return String(ast);
};
github projectwallace / css-analyzer / src / analyzer / values / animations.js View on Github external
function getSingleTimingFunction(animation) {
  let timingFunction

  parse(animation).walk(node => {
    // There should only be one timing function per shorthand
    if (timingFunction) {
      return
    }

    // Look for timing keywords
    if (
      node.type === 'word' &&
      [
        'ease',
        'ease-in',
        'ease-in-out',
        'ease-out',
        'linear',
        'step-start',
        'step-end'
github signal-noise / stylelint-scales / lib / rules / border-width / index.js View on Github external
function check(decl, size) {
      // Parse the size and walk through Numerics
      parse(size, {
        ignoreUnknownWords: true
      }).walkNumerics(({ value, unit: valueUnit }) => {
        // Return early if not a checked unit
        if (!lengthUnits.includes(valueUnit)) return;

        // Validate scale and units
        const validUnit = unit ? valueUnit === unit : true;
        const validScale = scale.includes(Math.abs(Number(value)));

        // Get message of the violation
        let message;
        if (!validScale) {
          message = messages.expected(`${value}`, scale.join(", "));
        } else if (!validUnit) {
          message = messages.expected(`${valueUnit}`, `${unit}`);
        } else {
github Pavliko / postcss-svg / src / lib / transpile-styles.js View on Github external
styleAST.walkDecls(decl => {
		const declAST = parser(decl.value).parse();

		// update the declaration with all transpiled var()s
		declAST.walk(node => {
			// conditionally update the var()
			if (isVarFuntion(node)) {
				transpileVar(node, params);
			}
		});

		decl.value = declAST.toString();
	});