You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

styleSelector.js 853B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Module dependencies.
  3. */
  4. const specificity = require('specificity');
  5. /**
  6. * Returns specificity based on selector text and tokens.
  7. *
  8. * @param {String} selector
  9. * @param {Array} tokens
  10. * @api private.
  11. */
  12. function getSpecificity(text) {
  13. const spec = specificity.calculate(text);
  14. return spec[0].specificity.split(',');
  15. }
  16. /**
  17. * CSS selector constructor.
  18. *
  19. * @param {String} selector text
  20. * @param {Array} optionally, precalculated specificity
  21. * @api public
  22. */
  23. module.exports = (text, spec) => {
  24. let _spec = spec;
  25. const /**
  26. * Lazy specificity getter
  27. *
  28. * @api public
  29. */
  30. _specificity = () => {
  31. if (!spec) {
  32. _spec = getSpecificity(text);
  33. }
  34. return _spec;
  35. };
  36. return {
  37. spec: _spec,
  38. specificity: _specificity
  39. };
  40. };