How to use the css-selector-tokenizer.parse function in css-selector-tokenizer

To help you get started, we’ve selected a few css-selector-tokenizer 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 elastic / timelion / node_modules / postcss-modules-local-by-default / index.js View on Github external
css.eachRule(function(rule) {
      if(rule.parent.type === "atrule" && /keyframes$/.test(rule.parent.name)) {
        // ignore keyframe rules
        return;
      }
      var selector = Tokenizer.parse(rule.selector);
      var context = {
        options: options,
        global: globalMode,
        hasPureGlobals: false
      };
      var newSelector;
      try {
        newSelector = localizeNode(selector, context);
      } catch(e) {
        throw rule.error(e.message);
      }
      if(pureMode && context.hasPureGlobals) {
        throw rule.error("Selector '" + Tokenizer.stringify(selector) + "' is not pure " +
          "(pure selectors must contain at least one local class or id)");
      }
      rule.nodes.forEach(function(decl) {
github decentraland / editor-legacy / node_modules / postcss-modules-local-by-default / index.js View on Github external
css.walkRules(function(rule) {
      if(rule.parent.type === 'atrule' && /keyframes$/.test(rule.parent.name)) {
        // ignore keyframe rules
        return;
      }
      var selector = Tokenizer.parse(rule.selector);
      var context = {
        options: options,
        global: globalMode,
        hasPureGlobals: false
      };
      var newSelector;
      try {
        newSelector = localizeNode(selector, context);
      } catch(e) {
        throw rule.error(e.message);
      }
      if(pureMode && context.hasPureGlobals) {
        throw rule.error('Selector "' + Tokenizer.stringify(selector) + '" is not pure ' +
          '(pure selectors must contain at least one local class or id)');
      }
      // Less-syntax mixins parse as rules with no nodes
github css-modules / postcss-icss-composes / src / index.js View on Github external
const getIdentifiers = (rule, result) => {
  const selectors = Tokenizer.parse(rule.selector).nodes;
  return selectors
    .map(selector => {
      const identifier = getSelectorIdentifier(selector);
      if (identifier === null) {
        result.warn(
          `composition is only allowed in single class selector, not in '${Tokenizer.stringify(
            selector
          )}'`,
          { node: rule }
        );
      }
      return identifier;
    })
    .filter(identifier => identifier !== null);
};
github ant-design / ant-design-pro-site / config / components / tool / AddlocalIdentName.js View on Github external
const localizeSelectors = (selectors, mode, getAlias) => {
  const node = Tokenizer.parse(selectors);
  return Tokenizer.stringify(
    Object.assign({}, node, {
      nodes: node.nodes.map(n => localizeNode(n, { mode, getAlias })),
    })
  );
};
const getValue = (messages, name) =>
github wix / stylable / packages / core / src / selector-utils.ts View on Github external
export function parseSelector(selector: string): SelectorAstNode {
    return tokenizer.parse(selector);
}
github SparkPost / heml / packages / heml-parse / src / preprocessStyles.js View on Github external
function generateClassesForSelector(selector) {
  const { nodes } = first(parseSelector(selector).nodes)
  const map = new Map()
  let selectorPartNodes = []

  /**
   * 1. gather all the nodes until a pseudo element or dynamic pseudo selector
   * 2. create a class for the selector part and add selector part/class to the map
   */
  nodes.forEach((node, index) => {
    /** we have a matched pseudo - drop the node, build the previous nodes to a string, and add it to the map entry */
    if (node.type.startsWith('pseudo') && (pseudoElements.includes(node.name) || dynamicPseudoSelectors.includes(node.name))) {
      const selectorPart = stringifySelectorNodes(selectorPartNodes)
      map.set(toClass(selectorPart), selectorPart)

      /**
       * keep the previous last node on so that the selector continues to work
       * .i.e. a:hover > b will become these selectors ['a', 'a > b']
github css-modules / postcss-icss-selectors / src / index.js View on Github external
const localizeSelectors = (selectors, mode, getAlias) => {
  const node = Tokenizer.parse(selectors);
  return Tokenizer.stringify(
    Object.assign({}, node, {
      nodes: node.nodes.map(n => localizeNode(n, { mode, getAlias }))
    })
  );
};
github SparkPost / heml / packages / heml-parse / src / preprocessStyles.js View on Github external
function queryableSelector(selector) {
  const { nodes } = first(parseSelector(selector).nodes)

  /** remove all non-static pseudo selectors/elements */
  return stringifySelectorNodes(nodes.filter((node) => {
    return !(node.type.startsWith('pseudo') && !staticPseudoSelectors.includes(node.name))
  }))
}

css-selector-tokenizer

Parses and stringifies CSS selectors

MIT
Latest version published 3 years ago

Package Health Score

71 / 100
Full package analysis