source: trip-planner-front/node_modules/csso/lib/usage.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1var hasOwnProperty = Object.prototype.hasOwnProperty;
2
3function buildMap(list, caseInsensitive) {
4 var map = Object.create(null);
5
6 if (!Array.isArray(list)) {
7 return null;
8 }
9
10 for (var i = 0; i < list.length; i++) {
11 var name = list[i];
12
13 if (caseInsensitive) {
14 name = name.toLowerCase();
15 }
16
17 map[name] = true;
18 }
19
20 return map;
21}
22
23function buildList(data) {
24 if (!data) {
25 return null;
26 }
27
28 var tags = buildMap(data.tags, true);
29 var ids = buildMap(data.ids);
30 var classes = buildMap(data.classes);
31
32 if (tags === null &&
33 ids === null &&
34 classes === null) {
35 return null;
36 }
37
38 return {
39 tags: tags,
40 ids: ids,
41 classes: classes
42 };
43}
44
45function buildIndex(data) {
46 var scopes = false;
47
48 if (data.scopes && Array.isArray(data.scopes)) {
49 scopes = Object.create(null);
50
51 for (var i = 0; i < data.scopes.length; i++) {
52 var list = data.scopes[i];
53
54 if (!list || !Array.isArray(list)) {
55 throw new Error('Wrong usage format');
56 }
57
58 for (var j = 0; j < list.length; j++) {
59 var name = list[j];
60
61 if (hasOwnProperty.call(scopes, name)) {
62 throw new Error('Class can\'t be used for several scopes: ' + name);
63 }
64
65 scopes[name] = i + 1;
66 }
67 }
68 }
69
70 return {
71 whitelist: buildList(data),
72 blacklist: buildList(data.blacklist),
73 scopes: scopes
74 };
75}
76
77module.exports = {
78 buildIndex: buildIndex
79};
Note: See TracBrowser for help on using the repository browser.