npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

unicode-script

v1.1.0

Published

[Unicode 16.0.0] Retrieve the Unicode script(s) a string belongs to. Can also return the Script_Extension property which is defined as characters which are 'commonly used with more than one script, but with a limited number of scripts'.

Downloads

142

Readme

unicode-script.js [ci]

Retrieve all Unicode script(s) used in a string.

Includes support for the Script_Extension (scx) property which is defined as characters which are "commonly used with more than one script, but with a limited number of scripts".

Based on the Script_Extension, this library can also return the augmented script set to figure out if a string is mixed-script or single-script.

Unicode version: 16.0.0 (September 2024)

Install

Use npm or your favorite package manager to install this module:

npm install --save unicode-script

Or use the ESM module directly from the browser.

Usage - Script

Each codepoint belongs to one script, which might be one of the three special scripts Common, Inherited, Unknown.

unicodeScript(char) / unicodeScriptCode(char)

// Single character

import { unicodeScript } from "unicode-script";
unicodeScript("ᴦ"); // "Greek"

unicodeScripts(string) / unicodeScriptCodes(string)

import { unicodeScripts, unicodeScriptCodes } from "unicode-script";

// Set of all scripts of a string
unicodeScripts("СC"); // Set(2) { 'Cyrillic', 'Latin' }
unicodeScripts("𐱐"); // Set(1) { 'Unknown' }

// Get all scripts of string in ISO 15924 four-letter codes
unicodeScriptCodes("СC"); // Set(2) { 'Cyrl', 'Latn' }

Usage - Script Extensions

Each codepoint can belong to mutliple script extensions.

unicodeScriptExtensions(string) / unicodeScriptExtensionCodes(string)

import { unicodeScriptExtensions } from "unicode-script";
unicodeScriptExtensions("॥");
// Set(23) {
//   'Bengali',
//   'Devanagari',
//   'Dogra',
//   'Grantha',
//   'Gujarati',
//   'Gunjala_Gondi',
//   'Gurmukhi',
//   'Gurung_Khema',
//   'Kannada',
//   'Khudawadi',
//   'Limbu',
//   'Mahajani',
//   'Malayalam',
//   'Masaram_Gondi',
//   'Nandinagari',
//   'Ol_Onal',
//   'Oriya',
//   'Sinhala',
//   'Syloti_Nagri',
//   'Takri',
//   'Tamil',
//   'Telugu',
//   'Tirhuta'
// }

Usage - Augmented Scripts

Like script extensions, but adds meta scripts for Asian languages and treats Common/Inherited values as ALL scripts.

unicodeAugmentedScriptCodes(char)

import { unicodeAugmentedScriptCodes } from "unicode-script";

unicodeAugmentedScriptCodes("ねガ"); // Set(3) { 'Hira', 'Kana', 'Jpan' }
unicodeAugmentedScriptCodes("1"); // Set(175) { 'Adlm',  'Aghb', , 'Ahom', … }

Usage - Resolved Script

Intersection of all augmented scripts per character.

unicodeResolvedScriptCodes(string)

import { unicodeResolvedScriptCodes } from "unicode-script";

unicodeResolvedScriptCodes("СігсӀе"); // Set(1) { 'Cyrl' }
unicodeResolvedScriptCodes("Сirсlе"); // Set(0) {}
unicodeResolvedScriptCodes("𝖢𝗂𝗋𝖼𝗅𝖾"); // Set(175) { 'Adlm',  'Aghb', , 'Ahom', … }
unicodeResolvedScriptCodes("1"); // Set(175) { 'Adlm',  'Aghb', , 'Ahom', … }
unicodeResolvedScriptCodes("ねガ"); // Set(3) { 'Hira', 'Kana', 'Jpan' }

Please note that the resolved script can contain multiple scripts, as per standard.

Usage - Mixed-Script Detection

Mixed-script if resolved script set is empty, single-script otherwise.

isMixedScript(string) / isSingleScript(string)

import { isMixedScript, isSingleScript } from "unicode-script";

isMixedScript("СігсӀе"); // false
isMixedScript("Сirсlе"); // true
isMixedScript("𝖢𝗂𝗋𝖼𝗅𝖾"); // false
isMixedScript("1"); // false
isMixedScript("ねガ"); // false

isSingleScript("СігсӀе"); // true
isSingleScript("Сirсlе"); // false
isSingleScript("𝖢𝗂𝗋𝖼𝗅𝖾"); // true
isSingleScript("1"); // true
isSingleScript("ねガ"); // true

Please note that a single-script string might actually contain multiple scripts, as per standard (e.g. for Asian languages)

List of All Scripts

Script names and short names can be retrieved like this:

import { listUnicodeScripts } from "unicode-script";
listUnicodeScripts(); // Set(172) { 'Adlam', 'Ahom', 'Anatolian_Hieroglyphs', …

import { listUnicodeScriptCodes } from "unicode-script";
listUnicodeScriptCodes(); // Set(172) { 'Adlm', 'Aghb', 'Ahom', …

import { listUnicodeAugmentedScriptCodes } from "unicode-script";
listUnicodeAugmentedScriptCodes(); // Set(3) { 'Hanb', 'Jpan', 'Kore' }

You can find a list of all scripts in Unicode, with links to Wikipedia on character.construction/scripts

More Examples / JSDoc

See SPECS and DOCS.

Unicode Standards

Also See

MIT License

  • Copyright (C) 2024 Jan Lelis https://janlelis.com. Released under the MIT license.
  • Unicode data: https://www.unicode.org/copyright.html#Exhibit1