{"id":17194,"library":"codepoints","title":"Unicode Codepoint Database Parser","description":"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.","status":"maintenance","version":"1.3.0","language":"javascript","source_language":"en","source_url":"git://github.com/devongovett/codepoints","tags":["javascript","unicode","ucd","codepoint"],"install":[{"cmd":"npm install codepoints","lang":"bash","label":"npm"},{"cmd":"yarn add codepoints","lang":"bash","label":"yarn"},{"cmd":"pnpm add codepoints","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-first. Direct `import` syntax is not supported and will result in a runtime error in a pure ESM environment.","wrong":"import codepoints from 'codepoints';","symbol":"codepoints","correct":"const codepoints = require('codepoints');"},{"note":"Accesses the parser directly, allowing a custom Unicode Character Database (UCD) path. Like the main export, it is CommonJS-first.","wrong":"import parser from 'codepoints/parser';","symbol":"parser","correct":"const parser = require('codepoints/parser');"},{"note":"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.","symbol":"CodepointData","correct":"// No direct import for type; data is an array of objects.\n// Example accessing a property:\n// const category = codepoints[65].category;"}],"quickstart":{"code":"const parser = require('codepoints/parser');\nconst path = require('path');\nconst fs = require('fs');\n\n// In a real build script, you would download and extract the UCD yourself.\n// For this example, we'll simulate a UCD directory.\nconst mockUCDPath = path.join(__dirname, 'mock-ucd');\nif (!fs.existsSync(mockUCDPath)) {\n  fs.mkdirSync(mockUCDPath);\n  // Simulate a minimal UnicodeData.txt for the parser to find\n  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;');\n}\n\n// Parse a custom version of the UCD from the specified directory\ntry {\n  const codepointData = parser(mockUCDPath);\n\n  console.log(`Total codepoints parsed: ${codepointData.length}`);\n  console.log('Data for LATIN CAPITAL LETTER A (U+0041):', {\n    code: codepointData[0x41].code,\n    name: codepointData[0x41].name,\n    category: codepointData[0x41].category,\n    lowercase: codepointData[0x41].lowercase\n  });\n\n  console.log('Data for LATIN SMALL LETTER B (U+0062):', {\n    code: codepointData[0x62].code,\n    name: codepointData[0x62].name,\n    category: codepointData[0x62].category,\n    uppercase: codepointData[0x62].uppercase\n  });\n} catch (error) {\n  console.error('Error parsing UCD:', error.message);\n  console.log('Ensure that the mock-ucd directory contains necessary UCD files, e.g., UnicodeData.txt');\n}\n\n// Clean up mock UCD directory\nfs.rmSync(mockUCDPath, { recursive: true, force: true });","lang":"javascript","description":"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."},"warnings":[{"fix":"For production applications, use modules that provide precompiled and compressed Unicode data, such as `unicode-properties`, as recommended by the `codepoints` README.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The `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).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"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()`.","cause":"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.","error":"TypeError: require is not defined"},{"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.","cause":"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.","error":"Error: Cannot find module 'codepoints' or 'codepoints/parser'"}],"ecosystem":"npm","meta_description":null}