Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

nodeContextLookup.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. /**
  3. * Create a collection of Maps that serve to contextualize a given node.
  4. * This is useful to ensure that you only compare nodes that share a certain
  5. * context.
  6. *
  7. * All nodes are initially contextualized by their input source.
  8. * From there, you can contextualize them however you want.
  9. *
  10. * For a usage example, see `selector-no-descending-specificity`.
  11. */
  12. module.exports = function () {
  13. const contextMap = new Map();
  14. return {
  15. /**
  16. * @param {import('postcss').Node} node
  17. */
  18. getContext(node, /** @type {any[]} */ ...subContexts) {
  19. // TODO TYPES node.source possible undefined
  20. const nodeSource = /** @type {import('postcss').NodeSource} */ (node.source).input.from;
  21. const baseContext = creativeGetMap(contextMap, nodeSource);
  22. return subContexts.reduce((result, context) => {
  23. return creativeGetMap(result, context);
  24. }, baseContext);
  25. },
  26. };
  27. };
  28. /**
  29. * TODO TYPES
  30. * @param {Map<any, any>} someMap
  31. * @param {any} someThing
  32. */
  33. function creativeGetMap(someMap, someThing) {
  34. if (!someMap.has(someThing)) {
  35. someMap.set(someThing, new Map());
  36. }
  37. return someMap.get(someThing);
  38. }