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.
47 lines
1.2 KiB
47 lines
1.2 KiB
3 years ago
|
var mdnProperties = require('mdn-data/css/properties.json');
|
||
|
var mdnSyntaxes = require('mdn-data/css/syntaxes.json');
|
||
|
var patch = require('./patch.json');
|
||
|
var data = {
|
||
|
properties: {},
|
||
|
types: {}
|
||
|
};
|
||
|
|
||
|
function normalizeSyntax(syntax) {
|
||
|
return syntax
|
||
|
.replace(/</g, '<')
|
||
|
.replace(/>/g, '>')
|
||
|
.replace(/ /g, ' ')
|
||
|
.replace(/&/g, '&');
|
||
|
}
|
||
|
|
||
|
function patchDict(dict, patchDict) {
|
||
|
for (var key in patchDict) {
|
||
|
if (key in dict) {
|
||
|
if (patchDict[key].syntax) {
|
||
|
dict[key].syntax = patchDict[key].syntax;
|
||
|
} else {
|
||
|
delete dict[key];
|
||
|
}
|
||
|
} else {
|
||
|
if (patchDict[key].syntax) {
|
||
|
dict[key] = patchDict[key];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// apply patch
|
||
|
patchDict(mdnProperties, patch.properties);
|
||
|
patchDict(mdnSyntaxes, patch.syntaxes);
|
||
|
|
||
|
// normalize source mdnProperties syntaxes, since it uses html token
|
||
|
for (var key in mdnProperties) {
|
||
|
data.properties[key] = normalizeSyntax(mdnProperties[key].syntax);
|
||
|
}
|
||
|
|
||
|
for (var key in mdnSyntaxes) {
|
||
|
data.types[key] = normalizeSyntax(mdnSyntaxes[key].syntax);
|
||
|
}
|
||
|
|
||
|
module.exports = data;
|