Registry / serialization / codepoints

codepoints

JSON →
library1.0jsnpmunverified

The `codepoints` package provides a parser for the Unicode Character Database (UCD) files, producing a large array of JavaScript objects, each representing a Unicode codepoint with extensive properties like name, category, block, script, bidi class, and various casing and decomposition mappings. The current stable version is 1.3.0, and the package is primarily intended for use in build scripts, not directly in production applications, due to its significant memory footprint and unoptimized parsing speed. It bundles a default UCD, but also allows specifying a custom UCD path. For real-world applications requiring Unicode data, the project maintainers recommend using modules that provide precompiled and compressed data, such as `unicode-properties`. It does not follow a strict release cadence and has seen infrequent updates, reflecting its stable but specialized role.

npm install codepoints
INSTALL
IMPORT
SIG · CODEPOINTS
C
codepoints
serializationjavascriptv1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

codepoints
const codepoints = require('codepoints');
import codepoints from 'codepoints';
This package is CommonJS-first. Direct `import` syntax is not supported and will result in a runtime error in a pure ESM environment.
parser
const parser = require('codepoints/parser');
import parser from 'codepoints/parser';
Accesses the parser directly, allowing a custom Unicode Character Database (UCD) path. Like the main export, it is CommonJS-first.
CodepointData
// No direct import for type; data is an array of objects. // Example accessing a property: // const category = codepoints[65].category;
The package exports an array of codepoint objects directly. Individual codepoint data properties like `code`, `name`, `category`, and `script` are accessed on elements within the generated array.

This quickstart demonstrates how to use the `codepoints/parser` submodule to process a Unicode Character Database (UCD) from a custom directory, showcasing its primary use case for build scripts to generate structured Unicode data. It simulates a minimal UCD for demonstration purposes.

const parser = require('codepoints/parser'); const path = require('path'); const fs = require('fs'); // In a real build script, you would download and extract the UCD yourself. // For this example, we'll simulate a UCD directory. const mockUCDPath = path.join(__dirname, 'mock-ucd'); if (!fs.existsSync(mockUCDPath)) { fs.mkdirSync(mockUCDPath); // Simulate a minimal UnicodeData.txt for the parser to find fs.writeFileSync(path.join(mockUCDPath, 'UnicodeData.txt'), '0041;LATIN CAPITAL LETTER A;Lu;0;L;;;;;N;;;;0061;;;\n0062;LATIN SMALL LETTER B;Ll;0;L;;;;;N;;;0042;;0042;'); } // Parse a custom version of the UCD from the specified directory try { const codepointData = parser(mockUCDPath); console.log(`Total codepoints parsed: ${codepointData.length}`); console.log('Data for LATIN CAPITAL LETTER A (U+0041):', { code: codepointData[0x41].code, name: codepointData[0x41].name, category: codepointData[0x41].category, lowercase: codepointData[0x41].lowercase }); console.log('Data for LATIN SMALL LETTER B (U+0062):', { code: codepointData[0x62].code, name: codepointData[0x62].name, category: codepointData[0x62].category, uppercase: codepointData[0x62].uppercase }); } catch (error) { console.error('Error parsing UCD:', error.message); console.log('Ensure that the mock-ucd directory contains necessary UCD files, e.g., UnicodeData.txt'); } // Clean up mock UCD directory fs.rmSync(mockUCDPath, { recursive: true, force: true });
Debug
Known issues
gotchaThis package is explicitly designed for 'BUILD SCRIPTS ONLY'. It is not recommended for use in production applications due to performance and memory limitations. The parsers are not optimized for speed, and the resulting codepoint array consumes a substantial amount of memory.
fix
For production applications, use modules that provide precompiled and compressed Unicode data, such as `unicode-properties`, as recommended by the `codepoints` README.
affects: >=1.0.0
gotchaThe output is a 'giant array of codepoint objects' which can consume a huge amount of memory. Loading the entire Unicode database into memory is suitable for offline processing or build-time data generation but not for typical runtime usage in resource-constrained environments.
fix
If you need specific Unicode properties in a production application, consider pre-filtering and serializing only the necessary data during a build step using `codepoints`, or utilize libraries optimized for efficient runtime access to Unicode properties.
affects: >=1.0.0
gotchaThe `codepoints` package is primarily CommonJS-oriented, as indicated by its `require()` examples. Directly using ES Module `import` syntax might lead to interoperability issues or errors in some Node.js environments if not properly configured (e.g., using `type: 'module'` in `package.json` with appropriate transpilation or loaders).
fix
Ensure your environment supports CommonJS `require()`, or use a bundler that can handle CommonJS modules when targeting an ESM environment. If explicit ESM compatibility is required for newer Node.js versions, consider alternatives or a build process that transforms the output.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: require is not defined
Attempting to use `require()` in an ECMAScript Module (ESM) context without proper transpilation or configuration, such as in a file with `type: 'module'` in `package.json` or a `.mjs` file.
fix
Either convert your module to CommonJS (e.g., by ensuring `type: 'commonjs'` in `package.json` or using a `.cjs` extension) or use dynamic `import()` for loading, if supported by the package, although `codepoints` is designed for `require()`.
Error: Cannot find module 'codepoints' or 'codepoints/parser'
The package `codepoints` was not installed, or Node.js cannot resolve its path. This often happens if `npm install` was not run, or if the module is being imported from an incorrect location.
fix
Run `npm install codepoints` in your project directory. Verify that the `node_modules` directory contains the `codepoints` package. Ensure the import path is correct and relative to your project structure.
Upgrade
Version history
1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources
codepoints — npm install codepoints · libregistry