Skip to content

Repository files navigation

node-unicode-data

JavaScript-compatible Unicode data generator. Arrays of code points, arrays of symbols, and regular expressions for every Unicode version’s categories, scripts, script extensions, blocks, bidi data, and other properties — neatly packaged into a separate npm package per Unicode version.

Using the data in your scripts

To use the generated data, simply install one of the npm modules generated by this script. Separate packages are available for each Unicode version. This allows you to do stuff like:

// Get an array of all code points with the `White_Space` property:
import whiteSpaceCodePoints from '@unicode/unicode-6.3.0/Binary_Property/White_Space/code-points.mjs';
// Get an array of strings (containing one symbol each) in the `Lu` category:
import luSymbols from '@unicode/unicode-6.3.0/General_Category/Uppercase_Letter/symbols.mjs';
// Get a regular expression that matches any symbol in the `Aegean Numbers` block:
import aegeanNumbersRegex from '@unicode/unicode-6.3.0/Block/Aegean_Numbers/regex.mjs';
// Get an array of all code points in the `Egyptian_Hieroglyphs` script:
import hieroglyphs from '@unicode/unicode-6.3.0/Script/Egyptian_Hieroglyphs/code-points.mjs';
// Get the canonical category a given code point belongs to:
// (Note: U+0041 is LATIN CAPITAL LETTER A)
import generalCategory from '@unicode/unicode-6.3.0/General_Category/index.mjs';
const category = generalCategory.get(0x41);
// Get an array of all code points with a given bidi class:
import lre from '@unicode/unicode-6.3.0/Bidi_Class/Left_To_Right_Embedding/code-points.mjs';
// Get the directionality of a given code point:
import bidiClass from '@unicode/unicode-6.3.0/Bidi_Class/index.mjs';
const directionality = bidiClass.get(0x41);
// What glyph is the mirror image of `«` (U+00AB)?
import bidiMirroringGlyph from '@unicode/unicode-6.3.0/Bidi_Mirroring_Glyph/index.mjs';
const mirrored = bidiMirroringGlyph.get(0xab);
// Get a regular expression that matches all opening brackets:
import openingBrackets from '@unicode/unicode-6.3.0/Bidi_Paired_Bracket_Type/Open/regex.mjs';
// …you get the idea.

For more information, see the README for the package you’re interested in. Here’s the full list of npm packages generated by this script:

Note that these READMEs are auto-generated by this script, too – they describe all the data that is available for that particular Unicode version. To programmatically get this list of available categories, scripts, script extensions, blocks, and properties for a given Unicode version, just import the main module for that version:

> import unicode630 from '@unicode/unicode-6.3.0';
{
	'Binary_Property': [
		'Alphabetic', 'Any', 'ASCII', 'ASCII_Hex_Digit', 'Assigned', 
	],
	'General_Category': [
		'Cased_Letter','Close_Punctuation','Connector_Punctuation', 
	],
	'Script': [
		'Arabic', 'Armenian', 'Avestan', 
	],
	'Script_Extensions': [
		'Arabic', 'Armenian', 'Avestan', 
	],
	'Block': [
		'Aegean Numbers', 'Alchemical Symbols', 
	],
	'Case_Folding': [
		'C', 'F', 'S', 'T'
	],
	'Simple_Case_Mapping': [
		'Uppercase', 'Lowercase', 'Titlecase'
	],
	'Special_Casing': [
		'Uppercase', 'Lowercase', 'Titlecase', 
	],
	'Bidi_Class': [
		'Arabic_Letter', 'Arabic_Number', 'Boundary_Neutral', 
	],
	'Bidi_Mirroring_Glyph': [],
	'Bidi_Paired_Bracket_Type': [
		'Close', 'None', 'Open'
	]
}

For project maintainers

After cloning this repository, before doing anything else, run:

./clone-repos.sh

This clones all the generated repositories to your local output folder. You can then make changes to node-unicode-data, and use ./bootstrap.sh to commit and push changes to each of these repositories.

Generating the data

npm run download (re-)downloads the Unicode source files for all the Unicode versions defined in data/resources.mjs, saving them in the data folder.

npm run build generates data for all the Unicode versions defined in data/resources.mjs. This may take a few minutes… The regular expressions are generated using Regenerate.

Testing

npm test generates the data for the oldest and latest available Unicode version. This is a good way to test changes to the generator scripts before running npm run-script generate.

npm run-script cover generates the code coverage report.

Author

twitter/mathias
Mathias Bynens

License

This module is available under the MIT license.

About

JavaScript-compatible Unicode data generator. Arrays of code points, arrays of symbols, and regular expressions for every Unicode version’s categories, scripts, blocks, and properties — neatly packaged into a separate npm package per Unicode version.

Resources

Stars

154 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages