Socket
Socket
Sign inDemoInstall

unicode-trie

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unicode-trie

Unicode Trie data structure for fast character metadata lookup, ported from ICU


Version published
Weekly downloads
2.3M
decreased by-20.62%
Maintainers
1
Weekly downloads
 
Created

What is unicode-trie?

The unicode-trie npm package provides a compact and efficient way to store and retrieve Unicode character data using a trie data structure. This is particularly useful for applications that need to handle large sets of Unicode data, such as text processing, font rendering, and internationalization.

What are unicode-trie's main functionalities?

Creating a Unicode Trie

This feature allows you to create a Unicode trie by setting values for specific Unicode code points. The `UnicodeTrieBuilder` is used to build the trie, and the `freeze` method finalizes it.

const UnicodeTrieBuilder = require('unicode-trie/builder');
const builder = new UnicodeTrieBuilder();
builder.set(0x61, 1); // Set value 1 for character 'a'
builder.set(0x62, 2); // Set value 2 for character 'b'
const trie = builder.freeze();

Querying a Unicode Trie

This feature allows you to query a Unicode trie for the value associated with a specific Unicode code point. The `get` method retrieves the value for the given code point.

const UnicodeTrie = require('unicode-trie');
const trie = new UnicodeTrie(buffer); // buffer is the serialized trie data
console.log(trie.get(0x61)); // Get value for character 'a', should output 1
console.log(trie.get(0x62)); // Get value for character 'b', should output 2

Serializing and Deserializing a Unicode Trie

This feature allows you to serialize a Unicode trie to a buffer and then deserialize it back. This is useful for saving the trie to a file or sending it over a network.

const buffer = trie.toBuffer(); // Serialize the trie to a buffer
const deserializedTrie = new UnicodeTrie(buffer); // Deserialize the trie from the buffer

Other packages similar to unicode-trie

FAQs

Package last updated on 11 Nov 2015

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc