Last active
September 12, 2024 08:14
-
-
Save mathiasbynens/c08f45efdcdb9389adf3da57e16683de to your computer and use it in GitHub Desktop.
Unicode version diff for ECMAScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules | |
package-lock.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const aliasesToProperties = require('unicode-property-aliases'); | |
const propertiesToAliases = new Map(); | |
for (const [property, alias] of aliasesToProperties) { | |
if (propertiesToAliases.has(property)) { | |
propertiesToAliases.get(property).push(alias); | |
} else { | |
propertiesToAliases.set(property, [alias]); | |
} | |
} | |
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, | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const NEW_VERSION = '16.0.0'; | |
const PREVIOUS_VERSION = '15.1.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/unicode-${ PREVIOUS_VERSION }`)[name]; | |
const b = new Set(require(`@unicode/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'); | |
diffProperties('Sequence_Property'); | |
const properties = [ | |
'Binary_Property/ID_Start', | |
'Binary_Property/ID_Continue', | |
'General_Category/Space_Separator', | |
]; | |
for (const property of properties) { | |
const a = require(`@unicode/unicode-${ PREVIOUS_VERSION }/${ property }/code-points.js`); | |
const b = new Set(require(`@unicode/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/unicode-${ PREVIOUS_VERSION }/Case_Folding/${ form }/code-points.js`)); | |
const b = new Set(Object.keys(require(`@unicode/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`); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"private": true, | |
"dependencies": { | |
"@unicode/unicode-15.1.0": "*", | |
"@unicode/unicode-16.0.0": "*", | |
"unicode-property-aliases": "^2.0.0", | |
"unicode-property-value-aliases": "^3.8.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment