How to use the postcss-media-query-parser.default function in postcss-media-query-parser

To help you get started, we’ve selected a few postcss-media-query-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 brodybits / prettierx / src / language-css / parser-postcss.js View on Github external
function parseMediaQuery(params) {
  const mediaParser = require("postcss-media-query-parser").default;

  let result = null;

  try {
    result = mediaParser(params);
  } catch (e) {
    // Ignore bad media queries
    return {
      type: "selector-unknown",
      value: params
    };
  }

  return addTypePrefix(addMissingType(result), "media-");
}
github stylelint / stylelint / lib / rules / unit-blacklist / index.js View on Github external
function checkMedia(node, value, getIndex) {
			mediaParser(node.params).walk(/^media-feature$/i, (mediaFeatureNode) => {
				const mediaName = getMediaFeatureName(mediaFeatureNode);
				const parentValue = mediaFeatureNode.parent.value;

				valueParser(value).walk(function(valueNode) {
					// Ignore all non-word valueNode and
					// the values not included in the parentValue string
					if (valueNode.type !== 'word' || !parentValue.includes(valueNode.value)) {
						return;
					}

					check(
						node,
						getIndex(node),
						valueNode,
						mediaName,
						options ? options.ignoreMediaFeatureNames : {},
github stylelint / stylelint / lib / rules / media-feature-name-value-whitelist / index.js View on Github external
root.walkAtRules(/^media$/i, (atRule) => {
			mediaParser(atRule.params).walk(/^media-feature-expression$/i, (node) => {
				// Ignore boolean and range context
				if (!node.value.includes(':')) {
					return;
				}

				const mediaFeatureNode = _.find(node.nodes, { type: 'media-feature' });
				const valueNode = _.find(node.nodes, { type: 'value' });
				const mediaFeatureName = mediaFeatureNode.value;
				const value = valueNode.value;
				const unprefixedMediaFeatureName = postcss.vendor.unprefixed(mediaFeatureName);

				const featureWhitelist = _.find(whitelist, (v, whitelistFeatureName) =>
					matchesStringOrRegExp(unprefixedMediaFeatureName, whitelistFeatureName),
				);

				if (featureWhitelist === undefined) {
github stylelint / stylelint / lib / rules / no-duplicate-at-import-rules / index.js View on Github external
root.walkAtRules(/^import$/i, (atRule) => {
			const params = valueParser(atRule.params).nodes;

			if (!params.length) {
				return;
			}

			// extract uri from url() if exists
			const uri =
				params[0].type === 'function' && params[0].value === 'url'
					? params[0].nodes[0].value
					: params[0].value;
			// extract media queries if any
			const media = mediaParser(valueParser.stringify(params.slice(1)))
				.nodes.map((n) => n.value.replace(/\s/g, ''))
				.filter((n) => n.length);

			const isDuplicate = media.length
				? imports[uri] && media.some((q) => imports[uri].includes(q))
				: imports[uri];

			if (isDuplicate) {
				report({
					message: messages.rejected(uri),
					node: atRule,
					result,
					ruleName,
				});

				return;
github SuperOl3g / postcss-image-set-polyfill / index.js View on Github external
result[size] = images.url[i] + suffix;
                        } else {
                            result.default = images.url[i] + suffix;
                        }
                    }
                }

                return result;
            });

            // add the default image to the decl
            decl.value = parsedValues.map(val => val.default).join(',');

            // check for the media queries
            const media = decl.parent.parent.params;
            const parsedMedia = media && mediaParser(media);

            Object.keys(mediaQueryList)
                .sort()
                .forEach(size => {
                    const minResQuery = `(min-resolution: ${size}dpi)`;
                    const minDPRQuery = `(-webkit-min-device-pixel-ratio: ${mediaQueryList[size]})`;

                    const paramStr = parsedMedia ?
                        parsedMedia.nodes
                            .map(queryNode => `${queryNode.value} and ${minDPRQuery}, ${queryNode.value} and ${minResQuery}`)
                            .join(',') :
                        `${minDPRQuery}, ${minResQuery}`;

                    const atrule = postcss.atRule({
                        name: 'media',
                        params: paramStr
github stylelint / stylelint / lib / rules / media-feature-name-whitelist / index.js View on Github external
root.walkAtRules(/^media$/i, (atRule) => {
			mediaParser(atRule.params).walk(/^media-feature$/i, (mediaFeatureNode) => {
				const parent = mediaFeatureNode.parent;
				const sourceIndex = mediaFeatureNode.sourceIndex;
				const value = mediaFeatureNode.value;

				if (
					isRangeContextMediaFeature(parent.value) ||
					!isStandardSyntaxMediaFeatureName(value) ||
					isCustomMediaQuery(value)
				) {
					return;
				}

				if (matchesStringOrRegExp(value, whitelist)) {
					return;
				}
github stylelint / stylelint / lib / rules / media-feature-name-blacklist / index.js View on Github external
root.walkAtRules(/^media$/i, (atRule) => {
			mediaParser(atRule.params).walk(/^media-feature$/i, (mediaFeatureNode) => {
				const parent = mediaFeatureNode.parent;
				const sourceIndex = mediaFeatureNode.sourceIndex;
				const value = mediaFeatureNode.value;

				if (
					isRangeContextMediaFeature(parent.value) ||
					!isStandardSyntaxMediaFeatureName(value) ||
					isCustomMediaQuery(value)
				) {
					return;
				}

				if (!matchesStringOrRegExp(value, blacklist)) {
					return;
				}
github stylelint / stylelint / lib / rules / media-feature-name-case / index.js View on Github external
root.walkAtRules(/^media$/i, (atRule) => {
			let hasComments = _.get(atRule, 'raws.params.raw');
			const mediaRule = hasComments ? hasComments : atRule.params;

			mediaParser(mediaRule).walk(/^media-feature$/i, (mediaFeatureNode) => {
				const parent = mediaFeatureNode.parent;
				const sourceIndex = mediaFeatureNode.sourceIndex;
				const value = mediaFeatureNode.value;

				if (
					isRangeContextMediaFeature(parent.value) ||
					!isStandardSyntaxMediaFeatureName(value) ||
					isCustomMediaQuery(value)
				) {
					return;
				}

				const expectedFeatureName =
					expectation === 'lower' ? value.toLowerCase() : value.toUpperCase();

				if (value === expectedFeatureName) {
github stylelint / stylelint / lib / rules / media-feature-name-no-unknown / index.js View on Github external
root.walkAtRules(/^media$/i, (atRule) => {
			mediaParser(atRule.params).walk(/^media-feature$/i, (mediaFeatureNode) => {
				const parent = mediaFeatureNode.parent;
				const sourceIndex = mediaFeatureNode.sourceIndex;
				const value = mediaFeatureNode.value;

				if (
					isRangeContextMediaFeature(parent.value) ||
					!isStandardSyntaxMediaFeatureName(value) ||
					isCustomMediaQuery(value)
				) {
					return;
				}

				if (optionsMatches(options, 'ignoreMediaFeatureNames', value)) {
					return;
				}

postcss-media-query-parser

A tool for parsing media query lists.

MIT
Latest version published 8 years ago

Package Health Score

65 / 100
Full package analysis

Popular postcss-media-query-parser functions