summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/export-data.js47
-rw-r--r--scripts/process-data.js9
2 files changed, 22 insertions, 34 deletions
diff --git a/scripts/export-data.js b/scripts/export-data.js
index d9f374a..ef1ca05 100644
--- a/scripts/export-data.js
+++ b/scripts/export-data.js
@@ -4,12 +4,8 @@ var regenerate = require('regenerate');
var difference = require('lodash.difference');
require('string.fromcodepoint');
-var readJSON = function(fileName) {
- var contents = fs.readFileSync('data/' + fileName + '.json', 'utf-8');
- var object = JSON.parse(contents);
- if (Array.isArray(object)) {
- return object;
- }
+var formatJSON = function(fileName) {
+ var object = require('../data/' + fileName + '.json');
return jsesc(object, {
'compact': true,
'quotes': 'single'
@@ -23,8 +19,8 @@ var joinStrings = function(a, b) {
return a + b;
};
-var loneCodePoints = readJSON('encode-lone-code-points');
-var arrayEncodeMultipleSymbols = readJSON('encode-paired-symbols');
+var loneCodePoints = require('../data/encode-lone-code-points.json');
+var arrayEncodeMultipleSymbols = require('../data/encode-paired-symbols.json');
var arrayEncodeMultipleSymbolsASCII = arrayEncodeMultipleSymbols
.filter(function(string) {
return /^[\0-\x7F]+$/.test(string);
@@ -43,48 +39,45 @@ var encodeMultipleSymbolsNonASCII = jsesc(
arrayEncodeMultipleSymbolsASCII
).join('|')
);
-var encodeASCII = joinStrings(
+var regexEncodeASCII = joinStrings(
encodeMultipleSymbolsASCII,
encodeSingleSymbolsASCII
);
-var encodeNonASCII = joinStrings(
+var regexEncodeNonASCII = joinStrings(
encodeMultipleSymbolsNonASCII,
encodeSingleSymbolsNonASCII
);
-var invalidRawCodePoints = readJSON('invalid-raw-code-points');
+var invalidRawCodePoints = require('../data/invalid-raw-code-points.json');
// U+0000 is a parse error in the Data state (which is the state where `he`’s
// input and output is supposed to end up in), so add it to the set of invalid
// raw code points. http://whatwg.org/html/tokenization.html#data-state
invalidRawCodePoints.unshift(0x0000);
var overrides = Object.keys(
- JSON.parse(fs.readFileSync('data/decode-map-overrides.json', 'utf-8'))
-).map(function(codePoint) {
- return Number(codePoint);
-});
+ require('../data/decode-map-overrides.json')
+).map(Number);
module.exports = {
- 'encodeMap': readJSON('encode-map'),
- 'encodeASCII': encodeASCII, // not used
- 'regexEncodeNonASCII': encodeNonASCII,
- 'decodeOverrides': readJSON('decode-map-overrides'),
- 'decodeMap': readJSON('decode-map'),
- 'decodeMapLegacy': readJSON('decode-map-legacy'),
- 'invalidReferenceCodePoints': (function() {
- return jsesc(readJSON('invalid-character-reference-code-points'));
- }()),
+ 'encodeMap': formatJSON('encode-map'),
+ 'decodeMapOverrides': formatJSON('decode-map-overrides'),
+ 'decodeMap': formatJSON('decode-map'),
+ 'decodeMapLegacy': formatJSON('decode-map-legacy'),
+ 'invalidReferenceCodePoints': formatJSON('invalid-character-reference-code-points'),
'invalidCodePointsString': (function() {
var string = String.fromCodePoint.apply(0, invalidRawCodePoints);
return jsesc(string, { 'wrap': true });
}()),
+ 'regexEncodeASCII': regexEncodeASCII, // not used
+ 'regexEncodeNonASCII': regexEncodeNonASCII,
'regexInvalidRawCodePoints': regenerate(invalidRawCodePoints).toString(),
'regexAstralSymbol': regenerate().addRange(0x010000, 0x10FFFF).toString(),
'regexDecimalEscapeSource': '&#([0-9]+)(;?)',
'regexHexadecimalEscapeSource': '&#[xX]([a-fA-F0-9]+)(;?)',
'regexNamedReferenceSource': '&([0-9a-zA-Z]+);',
'regexLegacyReferenceSource': (function() {
- return '&(' + readJSON('decode-legacy-named-references').join('|') +
+ return '&(' +
+ require('../data/decode-legacy-named-references.json').join('|') +
')([=a-zA-Z0-9])?';
}()),
'regexLoneSurrogate': '[\\uD800-\\uDBFF](?:[^\\uDC00-\\uDFFF]|$)|(?:[^\\uD800-\uDBFF]|^)[\\uDC00-\\uDFFF]',
@@ -110,6 +103,6 @@ module.exports = {
.remove(overrides)
.toString();
}()),
- 'testData': fs.readFileSync('data/entities.json', 'utf-8').trim(),
- 'version': JSON.parse(fs.readFileSync('package.json', 'utf-8')).version
+ 'testData': formatJSON('entities'),
+ 'version': require('../package.json').version
};
diff --git a/scripts/process-data.js b/scripts/process-data.js
index 3ad9a3c..8189178 100644
--- a/scripts/process-data.js
+++ b/scripts/process-data.js
@@ -1,14 +1,9 @@
var fs = require('fs');
var jsesc = require('jsesc');
var _ = require('lodash');
-require('string.fromcodepoint');
-var readJSON = function(file) {
- return JSON.parse(fs.readFileSync(file, 'utf8'));
-};
-
-// http://www.whatwg.org/specs/web-apps/current-work/multipage/entities.json
-var data = readJSON('data/entities.json');
+// http://www.whatwg.org/specs/web-apps/current-work/entities.json
+var data = require('../data/entities.json');
var encodeMap = {};
var encodeMultipleSymbols = [];