Skip to content

Instantly share code, notes, and snippets.

@mathiasbynens mathiasbynens/.gitignore
Last active May 8, 2019

Embed
What would you like to do?
Unicode version diff for ECMAScript
node_modules
package-lock.json
const aliasesToProperties = require('unicode-property-aliases');
const propertiesToAliases = new Map();
for (const [property, alias] of aliasesToProperties) {
propertiesToAliases.set(alias, property);
}
const aliasesToValuesPerProperty = require('unicode-property-value-aliases');
const valuesToAliasesPerProperty = new Map();
for (const [property, aliasesToValues] of aliasesToValuesPerProperty) {
const valuesToAliases = new Map();
for (const [alias, value] of aliasesToValues) {
if (valuesToAliases.has(value)) {
valuesToAliases.get(value).push(alias);
} else {
valuesToAliases.set(value, [alias]);
}
}
valuesToAliasesPerProperty.set(property, valuesToAliases);
}
module.exports = {
propertiesToAliases,
valuesToAliasesPerProperty,
};
const NEW_VERSION = '12.1.0';
const PREVIOUS_VERSION = '12.0.0';
const {
propertiesToAliases,
valuesToAliasesPerProperty
} = require('./aliases.js');
const formatter = new Intl.NumberFormat();
const formatNumber = (number) => formatter.format(number);
console.log(`Comparing Unicode v${ NEW_VERSION } to Unicode v${ PREVIOUS_VERSION }`);
const diffProperties = (name) => {
const a = require(`unicode-${ PREVIOUS_VERSION }`)[name];
const b = new Set(require(`unicode-${ NEW_VERSION }`)[name]);
const diff = new Set(a.filter(x => !b.has(x)));
if (diff.size) {
console.log(diff);
console.log(`Note: didn’t check for new ${ name } values`); // TODO
} else {
const delta = b.size - a.length;
console.log(`${ name }: ${ formatNumber(delta) } new values`);
if (delta) {
const props = [...b].filter(x => !a.includes(x));
for (const prop of props) {
const aliases = name === 'Binary_Property'
? propertiesToAliases.get(prop)
: valuesToAliasesPerProperty.get(name).get(prop);
const aliasText = aliases ? ` (${ aliases.join(', ') })` : '';
console.log(`- ${ prop }${ aliasText }`);
}
}
}
};
diffProperties('Binary_Property');
diffProperties('General_Category');
diffProperties('Script');
diffProperties('Script_Extensions');
const properties = [
'Binary_Property/ID_Start',
'Binary_Property/ID_Continue',
'General_Category/Space_Separator',
];
for (const property of properties) {
const a = require(`unicode-${ PREVIOUS_VERSION }/${ property }/code-points.js`);
const b = new Set(require(`unicode-${ NEW_VERSION }/${ property }/code-points.js`));
const diff = new Set(a.filter(x => !b.has(x)));
console.log(`${ property }: ${ formatNumber(diff.size) } removals`);
if (diff.size) {
console.log(diff);
console.log('Note: didn’t check for new code points'); // TODO
} else {
const delta = b.size - a.length;
console.log(`${ property }: ${ formatNumber(delta) } new code points`);
}
}
const caseFoldings = ['S', 'F'];
for (const form of caseFoldings) {
const a = Object.keys(require(`unicode-${ PREVIOUS_VERSION }/Case_Folding/${ form }/code-points.js`));
const b = new Set(Object.keys(require(`unicode-${ NEW_VERSION }/Case_Folding/${ form }/code-points.js`)));
const removals = new Set(a.filter(x => !b.has(x)));
console.log(`Case_Folding=${ form }: ${ formatNumber(removals.size) } removals`);
if (removals.size) {
console.log(removals);
console.log('Note: didn’t check for new code points'); // TODO
} else {
const delta = b.size - a.length;
console.log(`Case_Folding=${ form }: ${ formatNumber(delta) } new code points`);
}
}
{
"private": true,
"dependencies": {
"unicode-12.0.0": "*",
"unicode-12.1.0": "*",
"unicode-property-aliases": "^1.4.0",
"unicode-property-value-aliases": "^3.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.