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
|
'use strict';
const fs = require('fs');
const jsesc = require('jsesc');
const propertyAliases = require('unicode-property-aliases-ecmascript');
const parsePropertyValueAliases = function() {
const propertyValueAliasesPerProperty = new Map();
const source = fs.readFileSync('./data/PropertyValueAliases.txt', 'utf8');
const lines = source.split('\n');
for (const line of lines) {
if (!line || /^#/.test(line)) {
continue;
}
const data = line.split('#')[0].split(';');
const propertyAlias = data[0].trim();
if (!propertyAliases.has(propertyAlias)) {
continue;
}
const property = propertyAliases.get(propertyAlias);
if (!propertyValueAliasesPerProperty.has(property)) {
propertyValueAliasesPerProperty.set(property, new Map());
}
// In the case of `ccc`, there are 4 fields. The second field is numeric,
// third is abbreviated, and fourth is long. We don’t need the numeric
// field.
if (property == 'Canonical_Combining_Class') {
data.splice(1, 1);
}
const map = propertyValueAliasesPerProperty.get(property);
const alias1 = data[1].trim();
const canonicalName = data[2].split('#')[0].trim();
console.assert(!map.has(alias1));
map.set(alias1, canonicalName);
const remaining = data.slice(3);
for (const otherAliasData of remaining) {
const otherAlias = otherAliasData.trim();
console.assert(!map.has(otherAlias));
map.set(otherAlias, canonicalName);
}
}
return propertyValueAliasesPerProperty;
};
const mappings = parsePropertyValueAliases();
// Delete binary properties.
for (const [property, values] of mappings) {
if (
values.size == 6 &&
values.get('False') == 'No' &&
values.get('True') == 'Yes'
) {
mappings.delete(property);
}
}
// Re-use the `Script` mappings for `Script_Extensions`.
const scriptMappings = mappings.get('Script');
mappings.set('Script_Extensions', scriptMappings);
const header = '// Generated using `npm run build`. Do not edit!';
const output = `${ header }\nmodule.exports = ${
jsesc(mappings, {
'compact': false
})
};\n`;
require('fs').writeFileSync('./index.js', output);
|