How to use the css-select.compile function in css-select

To help you get started, we’ve selected a few css-select 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 webhintio / hint / packages / utils-dom / src / htmldocument.ts View on Github external
public querySelectorAll(selector: string): HTMLElement[] {
        if (!CACHED_CSS_SELECTORS.has(selector)) {
            CACHED_CSS_SELECTORS.set(selector, cssSelect.compile(selector));
        }

        const matches: any[] = cssSelect(
            CACHED_CSS_SELECTORS.get(selector) as cssSelect.CompiledQuery,
            this._document.children
        );

        const result = matches.map((element) => {
            return new HTMLElement(element, this);
        });

        return result;
    }
github broadly / css-inliner / lib / match_rule.js View on Github external
function matcherFromSelector(declarations, selector) {
  const match       = CSSselect.compile(selector);
  const specificity = calculateSpecificity(selector);
  const properties  = declarationsToProperties(declarations, specificity);

  return {
    match(element) {
      return match(element) ? properties : null;
    },
    specificity
  };
}
github aMarcireau / origami / source / actions / manageScholar.js View on Github external
}

export function unblockScholar() {
    return {type: UNBLOCK_SCHOLAR};
}

export function changeRecaptchaVisibility() {
    return {type: CHANGE_RECAPTCHA_VISIBILITY};
}

export function scholarDisconnect() {
    return {type: SCHOLAR_DISCONNECT};
}

const firstCategoryRecaptchaQuery = cssSelect.compile('#gs_captcha_c');
const secondCategoryRecaptchaQuery = cssSelect.compile('.g-recaptcha');
const titleQuery = cssSelect.compile('head title');
const publicationsQuery = cssSelect.compile('.gs_r.gs_or.gs_scl .gs_ri');
const titleFromPublicationQuery = cssSelect.compile('.gs_rt a');
const citersLinkFromPublicationQuery = cssSelect.compile('.gs_fl a');
const metadataFromPublicationQuery = cssSelect.compile('.gs_a');

export function resolveHtml(url, text) {
    return (dispatch, getState) => {
        const dispatchAndEcho = (action, refractoryPeriod) => {
            if (action != null) {
                const now = Date.now();
                dispatch({
                    ...action,
                    beginOfRefractoryPeriod: now,
                    endOfRefractoryPeriod: now + refractoryPeriod,
                });
github broadly / css-inliner / lib / matcher.js View on Github external
module.exports = function matcher(rule, selector) {
  const match = CSSselect.compile(selector);

  const specificity   = calculateSpecificity(selector);
  const declarations  = rule.nodes.filter(node => node.type === 'decl');
  const properties    = declarations.map(function(decl) {
    const name        = decl.prop.trim();
    const value       = decl.value.trim();
    const important   = decl.important;
    const property    = { name, value, important, specificity };
    return property;
  });

  return function(element) {
    if (match(element))
      return properties;
  };
}
github webhintio / hint / packages / utils / src / dom / html.ts View on Github external
public querySelectorAll(selector: string): HTMLElement[] {
        if (!CACHED_CSS_SELECTORS.has(selector)) {
            CACHED_CSS_SELECTORS.set(selector, cssSelect.compile(selector));
        }

        const matches: any[] = cssSelect(
            CACHED_CSS_SELECTORS.get(selector) as cssSelect.CompiledQuery,
            this._document.children
        );

        const result = matches.map((element) => {
            return new HTMLElement(element, this);
        });

        return result;
    }
github cheeriojs / cheerio / lib / api / traversing.js View on Github external
return function(match, container) {
    var testFn;
    container = container || this;

    if (typeof match === 'string') {
      testFn = select.compile(match, container.options);
    } else if (typeof match === 'function') {
      testFn = function(el, i) {
        return match.call(el, i, el);
      };
    } else if (match.cheerio) {
      testFn = match.is.bind(match);
    } else {
      testFn = function(el) {
        return match === el;
      };
    }

    return container._make(filterFn(this, testFn));
  };
};
github cheeriojs / cheerio / lib / api / traversing.js View on Github external
return function(match, container) {
    var testFn;
    container = container || this;

    if (typeof match === 'string') {
      testFn = select.compile(match, container.options);
    } else if (typeof match === 'function') {
      testFn = function(el, i) {
        return match.call(el, i, el);
      };
    } else if (match.cheerio) {
      testFn = match.is.bind(match);
    } else {
      testFn = function(el) {
        return match === el;
      };
    }

    return container._make(filterFn(this, testFn));
  };
};
github spritejs / sprite-core / src / modules / dom / selector.js View on Github external
export function compile(query) {
  return CSSselect.compile(resolveQuery(query), {adapter});
}
github aMarcireau / origami / source / actions / manageScholar.js View on Github external
export function changeRecaptchaVisibility() {
    return {type: CHANGE_RECAPTCHA_VISIBILITY};
}

export function scholarDisconnect() {
    return {type: SCHOLAR_DISCONNECT};
}

const firstCategoryRecaptchaQuery = cssSelect.compile('#gs_captcha_c');
const secondCategoryRecaptchaQuery = cssSelect.compile('.g-recaptcha');
const titleQuery = cssSelect.compile('head title');
const publicationsQuery = cssSelect.compile('.gs_r.gs_or.gs_scl .gs_ri');
const titleFromPublicationQuery = cssSelect.compile('.gs_rt a');
const citersLinkFromPublicationQuery = cssSelect.compile('.gs_fl a');
const metadataFromPublicationQuery = cssSelect.compile('.gs_a');

export function resolveHtml(url, text) {
    return (dispatch, getState) => {
        const dispatchAndEcho = (action, refractoryPeriod) => {
            if (action != null) {
                const now = Date.now();
                dispatch({
                    ...action,
                    beginOfRefractoryPeriod: now,
                    endOfRefractoryPeriod: now + refractoryPeriod,
                });
            }
            setTimeout(() => {
                dispatch({type: SCHOLAR_REQUEST_REFRACTORY_PERIOD_DONE});
            }, refractoryPeriod);
        }

css-select

a CSS selector compiler/engine

BSD-2-Clause
Latest version published 2 years ago

Package Health Score

82 / 100
Full package analysis