index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. var mdnProperties = require('mdn-data/css/properties.json');
  2. var mdnSyntaxes = require('mdn-data/css/syntaxes.json');
  3. var patch = require('./patch.json');
  4. var data = {
  5. properties: {},
  6. types: {}
  7. };
  8. function normalizeSyntax(syntax) {
  9. return syntax
  10. .replace(/&lt;/g, '<')
  11. .replace(/&gt;/g, '>')
  12. .replace(/&nbsp;/g, ' ')
  13. .replace(/&amp;/g, '&');
  14. }
  15. function patchDict(dict, patchDict) {
  16. for (var key in patchDict) {
  17. if (key in dict) {
  18. if (patchDict[key].syntax) {
  19. dict[key].syntax = patchDict[key].syntax;
  20. } else {
  21. delete dict[key];
  22. }
  23. } else {
  24. if (patchDict[key].syntax) {
  25. dict[key] = patchDict[key];
  26. }
  27. }
  28. }
  29. }
  30. // apply patch
  31. patchDict(mdnProperties, patch.properties);
  32. patchDict(mdnSyntaxes, patch.syntaxes);
  33. // normalize source mdnProperties syntaxes, since it uses html token
  34. for (var key in mdnProperties) {
  35. data.properties[key] = normalizeSyntax(mdnProperties[key].syntax);
  36. }
  37. for (var key in mdnSyntaxes) {
  38. data.types[key] = normalizeSyntax(mdnSyntaxes[key].syntax);
  39. }
  40. module.exports = data;