• Stars
    star
    376
  • Rank 113,493 (Top 3 %)
  • Language
    JavaScript
  • License
    Other
  • Created almost 13 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript Unicode 8.0 Normalization - NFC, NFD, NFKC, NFKD.

This is Unicode Normalizer in a Common JS module. I'm not affiliated with Matsuza, the original author of Unicode Normalizer.

Build Status

Installation

npm install unorm

Polyfill

You can use this module as a polyfill for String.prototype.normalize, for example:

console.log('æøåäüö'.normalize('NFKD'));

The module uses some EcmaScript 5 features. Other browsers should use a compability shim, e.g. es5-shim.

Functions

This module exports four functions: nfc, nfd, nfkc, and nfkd; one for each Unicode normalization. In the browser the functions are exported in the unorm global. In CommonJS environments you just require the module. Functions:

  • unorm.nfd(str) – Canonical Decomposition
  • unorm.nfc(str) – Canonical Decomposition, followed by Canonical Composition
  • unorm.nfkd(str) – Compatibility Decomposition
  • unorm.nfkc(str) – Compatibility Decomposition, followed by Canonical Composition

Node.JS example

For a longer example, see examples directory.

var unorm = require('unorm');

var text =
  'The \u212B symbol invented by A. J. \u00C5ngstr\u00F6m ' +
  '(1814, L\u00F6gd\u00F6, \u2013 1874) denotes the length ' +
  '10\u207B\u00B9\u2070 m.';

var combining = /[\u0300-\u036F]/g; // Use XRegExp('\\p{M}', 'g'); see example.js.

console.log('Regular:  ' + text);
console.log('NFC:      ' + unorm.nfc(text));
console.log('NFD:      ' + unorm.nfd(text));
console.log('NFKC:     ' + unorm.nfkc(text));
console.log('NFKD: *   ' + unorm.nfkd(text).replace(combining, ''));
console.log(' * = Combining characters removed from decomposed form.');

Road map

As of November 2013. Longer term:

  • Look at possible optimizations (speed primarely, module size secondarily)
  • Adding functions to quick check normalizations: is_nfc, is_nfd, etc.

Contributers

  • Oleg Grenrus is helping to maintain this library. He cleaned up the code base, fixed JSHint errors, created a test suite and updated the normalization data to Unicode 6.3.

Development notes

To generate new unicode data, run:

cd src/data/src
javac UnormNormalizerBuilder.java
java UnormNormalizerBuilder

produced unormdata.js contains needed table

Execute node benchmark/benchmark.js to run simple benchmarks, if you do any changes which may affect performance.

License

This project includes the software package Unicode Normalizer 1.0.0. The software dual licensed under the MIT and GPL licenses. Here is the MIT license:

Copyright (c) 2008-2013 Matsuza <[email protected]>, Bjarke Walling <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

More Repositories

1

node-rsvg

Parse SVG files and render them as PNG, PDF, SVG, or raw memory buffer images.
C++
96
star
2

geo-distance

Common JS module for calculating and converting Earth distances using correct great-circle distance formula.
CoffeeScript
42
star
3

gulp-raml2html

A simple RAML to HTML documentation generator, wrapped for Gulp.
HTML
21
star
4

node-unrtf

Converts RTF documents to HTML.
Python
13
star
5

sfid

Work easily with Salesforce Ids in Node.js
JavaScript
11
star
6

Function.create.js

Create named functions easily in JavaScript.
JavaScript
7
star
7

xregexp

This repository is deprecated, use this instead:
JavaScript
7
star
8

stack-json

Stack traces in JSON format.
JavaScript
7
star
9

JS-Term

A fully functional pty in the browser
JavaScript
7
star
10

nodeclub-2013-10-03

Node.JS meetup in Copenhagen on Thursday, 13 October 2013
JavaScript
4
star
11

stack-formatted

Beautifully formatted stack traces.
JavaScript
4
star
12

bowling-score

JavaScript
3
star
13

nodeclub-crypto

Code snippets for nodeclub.dk talk on 3rd August 2011: Crypto and Session Management.
JavaScript
2
star
14

super-simple-jsonp

Super simple implementation of JSONP in client-side JavaScript that also does error handling.
JavaScript
2
star
15

anymot.es

The last remote control in your life!
C
2
star
16

miniwatch

Simple file/directory watcher library with a simple API.
JavaScript
2
star
17

logentries-query-stream

Query and stream logs from Logentries.
JavaScript
1
star
18

trading

Python
1
star
19

conllu-stream

Parse CoNLL-U files from Universal Dependencies project as a stream (http://universaldependencies.org/format.html)
JavaScript
1
star
20

logentries-query-cli

Command-line tool to stream logs from Logentries
JavaScript
1
star