Skip to content

Hopding/unicode-properties

 
 

Repository files navigation

Purpose of this Fork

This project is a fork of https://github.com/foliojs/unicode-properties created for use in https://github.com/Hopding/pdf-lib.

Listed below are changes that have been made in this fork:

  • Store binary data as compressed base64 JSON so the fs module isn't needed to read it back:
  • Update to Babel 7, replace Browserify with Rollup, and build UMDs
  • Build non-rolled-up ES6 and CommonJS in es/ and lib/ directories:
  • Released to NPM as @pdf-lib/unicode-properties

Also see

unicode-properties

Provides fast access to unicode character properties. Uses unicode-trie to compress the properties for all code points into just 12KB.

Usage

import unicode from '@pdf-lib/unicode-properties';

unicode.getCategory('2'.charCodeAt()) //=> 'Nd'
unicode.getNumericValue('2'.charCodeAt()) //=> 2

Installation

NPM Module

To install the latest stable version:

# With npm
npm install --save @pdf-lib/unicode-properties

# With yarn
yarn add  @pdf-lib/unicode-properties

This assumes you're using npm or yarn as your package manager.

UMD Module

You can also download @pdf-lib/unicode-properties as a UMD module from unpkg. The UMD builds have been compiled to ES5, so they should work in any modern browser. UMD builds are useful if you aren't using a package manager or module bundler. For example, you can use them directly in the <script> tag of an HTML page.

The following builds are available:

When using a UMD build, you will have access to a global window.UnicodeProperties variable. This variable contains the object exported by @pdf-lib/unicode-properties. For example:

// NPM module
import unicode from '@pdf-lib/unicode-properties';

// UMD module
var unicode = window.UnicodeProperties;

API

getCategory(codePoint)

Returns the unicode general category for the given code point.

getScript(codePoint)

Returns the script for the given code point.

getCombiningClass(codePoint)

Returns the canonical combining class for the given code point.

getEastAsianWidth(codePoint)

Returns the East Asian width for the given code point.

getNumericValue(codePoint)

Returns the numeric value for the given code point, or null if there is no numeric value for that code point.

isAlphabetic(codePoint)

Returns whether the code point is an alphabetic character.

isDigit(codePoint)

Returns whether the code point is a digit.

isPunctuation(codePoint)

Returns whether the code point is a punctuation character.

isLowerCase(codePoint)

Returns whether the code point is lower case.

isUpperCase(codePoint)

Returns whether the code point is upper case.

isTitleCase(codePoint)

Returns whether the code point is title case.

isWhiteSpace(codePoint)

Returns whether the code point is whitespace: specifically, whether the category is one of Zs, Zl, or Zp.

isBaseForm(codePoint)

Returns whether the code point is a base form. A code point of base form does not graphically combine with preceding characters.

isMark(codePoint)

Returns whether the code point is a mark character (e.g. accent).

License

MIT

About

Provides fast access to unicode character properties

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%