Socket
Book a DemoInstallSign in
Socket

unicharadata

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unicharadata

Access Unicode character data from UnicodeData.txt

9.0.0-alpha.6
latest
Source
npmnpm
Version published
Weekly downloads
56
-55.2%
Maintainers
1
Weekly downloads
 
Created
Source

unicharadata module

JavaScript module for accessing Unicode character data from UnicodeData.txt.

For nodejs

Install with npm command as:

npm install unicharadata
  • npm package page

then, load it in js files as:

const unicharadata = require("unicharadata");

Option: Using prebuilt database version

NOTE: For file size reducing, The current module implementation embeds UnicodeData.txt source and builds complete character database on load time.

This method uses large pre built database json file. It would be about 1sec fatser than building database (around 4sec).

const unicharadata = require("unicharadata/trial/unicharadata-load");

For browsers

Load with standard script tag as:

<script src="unicharadata.js"></script>

see: browser-example.html ( demo )

Links via CDN

API

NOTE: Detail of the character propeties are in http://www.unicode.org/reports/tr44/#UnicodeData.txt

  • unicharadata.lookup(name, defaultch = ""): search character from its name
    • use "Name" otherwise "Unicode 1 Name" property
  • unicharadata.lookupname(ch, defaultname = ""): get the name used lookup(name)
  • unicharadata.name(ch, defaultname = ""): get "Name" string
  • unicharadata.category(ch): get "General Category" string
  • unicharadata.combining(ch): get "Canonical Combining Class" number
  • unicharadata.bidirectional(ch): get "Bidi Class" string
  • unicharadata.decomposition(ch): get "Decomposition Mapping" text
    • return ch itself when no decomposition mapping
  • unicharadata.decompositionTag(ch): get "Decomposition Type" tag string
  • unicharadata.decimal(ch, defaultval = NaN): get "Numeric Value" integer as single decimal type
  • unicharadata.digit(ch, defaultval = NaN): get "Numeric Value" integer as single digit type
    • overwrapped decimal(ch). this includes as superscript (e.g. U+00B9)
  • unicharadata.numeric(ch, defaultval = NaN): get "Numeric Value" float number as numeric type
    • overwrapped digit(ch), this includes non single digit numbers.
  • unicharadata.mirrored(ch): get "Bidi Mirrored" string
    • "Y" or "N"
  • unicharadata.unicode1name(ch, defaultname = ""): get "Unicode 1 Name" string
  • unicharadata.isocomment(ch, defaultcomment = ""): get "ISO Comment" string
  • unicharadata.upper(ch, defaultch = ""): get "Simple Uppercase Mapping" character
  • unicharadata.lower(ch, defaultch = ""): get "Simple Lowercase Mapping" character
  • unicharadata.title(ch, defaultch = ""): get "Simple Titlecase Mapping" character
  • unicharadata.splitCombined(text): split a text to an array of strings that contains a character and following combining characters.

Example

"use strict";

const unicharadata = require("unicharadata");

// API
console.assert(unicharadata.name("A") === "LATIN CAPITAL LETTER A");
console.assert(unicharadata.lookup("LATIN CAPITAL LETTER A") === "A");
console.assert(unicharadata.category("A") === "Lu");
console.assert(unicharadata.combining("A") === 0);
console.assert(unicharadata.bidirectional("A") === "L");
console.assert(unicharadata.decomposition("A") === "A");
console.assert(unicharadata.decompositionTag("A") === "");
console.assert(isNaN(unicharadata.decimal("A")));
console.assert(isNaN(unicharadata.digit("A")));
console.assert(isNaN(unicharadata.numeric("A")));
console.assert(unicharadata.mirrored("A") === "N");
console.assert(unicharadata.unicode1name("A") === "");
console.assert(unicharadata.lookupname("A") === "LATIN CAPITAL LETTER A");
console.assert(unicharadata.isocomment("A") === "");
console.assert(unicharadata.upper("A") === "");
console.assert(unicharadata.lower("A") === "a");
console.assert(unicharadata.title("A") === "");

const splitted = unicharadata.splitCombined("これが🔑です".normalize("NFD"));
console.assert(splitted[0] === "こ");
console.assert(splitted[1] === "れ");
console.assert(splitted[2] === "が".normalize("NFD"));
console.assert(splitted[3] === "🔑");
console.assert(splitted[4] === "で".normalize("NFD"));
console.assert(splitted[5] === "す");

// specific
console.assert(unicharadata.decomposition("㍍") === "メートル");
console.assert(unicharadata.decompositionTag("㍍") === "<square>");

console.assert(unicharadata.decimal("1") === 1);
console.assert(unicharadata.digit("④") === 4);
console.assert(unicharadata.numeric("⅛") === 1 / 8);
console.assert(unicharadata.unicode1name("\n") === "LINE FEED (LF)");
console.assert(unicharadata.lookupname("\n") === "LINE FEED (LF)");

Build

  • npm run download: update UnicodeData.json from UnicodeData.txt on the web
  • npm run build: update unicharadata.js from unicharadata-raw.js and UnicodeData.json
  • npm test: run tests
  • npm run eslint: check coding style with eslint
    • setup with npm install required

The package version is based on the Unicode "Version" of UnicodeData.txt.

  • e.g. 9.0.0-alpha.2: the Unicode version is 9.0.0

License

ISC License

References

Keywords

unicodedata

FAQs

Package last updated on 23 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.