names.js
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var hasOwnProperty = Object.prototype.hasOwnProperty;
var knownKeywords = Object.create(null);
var knownProperties = Object.create(null);
function getVendorPrefix(string) {
if (string[0] === '-') {
// skip 2 chars to avoid wrong match with variables names
var secondDashIndex = string.indexOf('-', 2);
if (secondDashIndex !== -1) {
return string.substr(0, secondDashIndex + 1);
}
}
return '';
}
function getKeywordInfo(keyword) {
if (hasOwnProperty.call(knownKeywords, keyword)) {
return knownKeywords[keyword];
}
var lowerCaseKeyword = keyword.toLowerCase();
var vendor = getVendorPrefix(lowerCaseKeyword);
var name = lowerCaseKeyword;
if (vendor) {
name = name.substr(vendor.length);
}
return knownKeywords[keyword] = Object.freeze({
vendor: vendor,
prefix: vendor,
name: name
});
}
function getPropertyInfo(property) {
if (hasOwnProperty.call(knownProperties, property)) {
return knownProperties[property];
}
var lowerCaseProperty = property.toLowerCase();
var hack = lowerCaseProperty[0];
if (hack === '*' || hack === '_' || hack === '$') {
lowerCaseProperty = lowerCaseProperty.substr(1);
} else if (hack === '/' && property[1] === '/') {
hack = '//';
lowerCaseProperty = lowerCaseProperty.substr(2);
} else {
hack = '';
}
var vendor = getVendorPrefix(lowerCaseProperty);
var name = lowerCaseProperty;
if (vendor) {
name = name.substr(vendor.length);
}
return knownProperties[property] = Object.freeze({
hack: hack,
vendor: vendor,
prefix: hack + vendor,
name: name
});
}
module.exports = {
keyword: getKeywordInfo,
property: getPropertyInfo
};