unicode-block
v1.0.1
Published
[Unicode 16.0.0] Returns which Unicode blocks are used in a string
Downloads
4
Maintainers
Readme
unicode-block.js
Each Unicode character belongs to a block. This JavaScript module returns all blocks associated with the given string.
Unicode version: 16.0.0 (September 2024)
Install
Use npm or your favorite package manager to install this module:
npm install unicode-block
Or use ESM module directly from the browser.
Usage
unicodeBlock(string)
/ unicodeBlocks(char)
// Single character
import { unicodeBlock } from "unicode-block";
unicodeBlock("☼") // "Miscellaneous Symbols"
// All blocks used in the given string
import { unicodeBlocks } from "unicode-block";
unicodeBlocks("Abc") // Set(1) { 'Basic Latin' }
unicodeBlocks("СC") // Set(2) { 'Cyrillic', 'Basic Latin' }
unicodeBlocks("⧉⪥⟤") // Set(3) { 'Miscellaneous Mathematical Symbols-A',
// 'Miscellaneous Mathematical Symbols-B',
// 'Supplemental Mathematical Operators' }
unicodeBlocks("🃉🂹") // Set(1) { 'Playing Cards' }
unicodeBlocks("") // Set(1) { 'No_Block' }
List Names of All Blocks
import { listUnicodeBlocks } from "unicode-block";
listUnicodeBlocks()
// Set(339) {
// 'Basic Latin',
// 'Latin-1 Supplement',
// 'Latin Extended-A',
// 'Latin Extended-B',
// 'IPA Extensions',
// 'Spacing Modifier Letters',
// ...
Get Range Data of a Specific Block
import { unicodeBlockInfo } from "unicode-block";
unicodeBlockInfo("Symbols for Legacy Computing Supplement")
// {
// block: 'Symbols for Legacy Computing Supplement',
// first: 117760, // First codepoint of block
// last: 118463 // Last codepoint of block
// }
Also See
- Get the script of a character: unicode-scripts.js
- Get the name of a character: unicode-name.js
MIT License
- Copyright (C) 2024 Jan Lelis https://janlelis.com. Released under the MIT license.
- Unicode data: https://www.unicode.org/copyright.html#Exhibit1