项目原始demo,不改动
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
Tento repozitář je archivovaný. Můžete prohlížet soubory, klonovat, ale nemůžete nahrávat a vytvářet nové úkoly a požadavky na natažení.
 
 
 
 

59 řádky
1.3 KiB

  1. var hasOwnProperty = Object.prototype.hasOwnProperty;
  2. function buildMap(list, caseInsensitive) {
  3. var map = Object.create(null);
  4. if (!Array.isArray(list)) {
  5. return false;
  6. }
  7. for (var i = 0; i < list.length; i++) {
  8. var name = list[i];
  9. if (caseInsensitive) {
  10. name = name.toLowerCase();
  11. }
  12. map[name] = true;
  13. }
  14. return map;
  15. }
  16. function buildIndex(data) {
  17. var scopes = false;
  18. if (data.scopes && Array.isArray(data.scopes)) {
  19. scopes = Object.create(null);
  20. for (var i = 0; i < data.scopes.length; i++) {
  21. var list = data.scopes[i];
  22. if (!list || !Array.isArray(list)) {
  23. throw new Error('Wrong usage format');
  24. }
  25. for (var j = 0; j < list.length; j++) {
  26. var name = list[j];
  27. if (hasOwnProperty.call(scopes, name)) {
  28. throw new Error('Class can\'t be used for several scopes: ' + name);
  29. }
  30. scopes[name] = i + 1;
  31. }
  32. }
  33. }
  34. return {
  35. tags: buildMap(data.tags, true),
  36. ids: buildMap(data.ids),
  37. classes: buildMap(data.classes),
  38. scopes: scopes
  39. };
  40. }
  41. module.exports = {
  42. buildIndex: buildIndex
  43. };