Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

transliteration

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

transliteration - npm Package Compare versions

Comparing version 1.6.6 to 2.0.0

dist/bin/slugify

91

package.json
{
"name": "transliteration",
"version": "1.6.6",
"version": "2.0.0",
"description": "Unicode to ACSII transliteration / slugify module for node.js, browser, Web Worker, ReactNative and CLI.",
"main": "lib/node/index.js",
"main": "dist/node/src/node/index.js",
"module": "dist/browser/bundle.esm.min.js",
"jsnext": "dist/browser/bundle.esm.min.js",
"browser": "dist/browser/bundle.umd.min.js",
"bin": {
"transliterate": "dist/bin/transliterate",
"slugify": "dist/bin/slugify"
},
"types": "dist/node/src/node/index.d.ts",
"scripts": {
"lint": "eslint src/**/*.js test/**/*.js gulpfile.babel.js",
"generate:data": "node scripts/generate_data.js",
"lint": "tslint -c tslint.json src/**/*.ts test/**/*.ts",
"pretest": "npm run lint",
"test": "npm run test:node",
"test:node": "tape -r babel-core/register test/node/*.js | tap-spec",
"pretest:browser": "npm run build",
"test:browser": "zuul --no-coverage -- test/browser/*.js",
"prebuild": "npm run test",
"build": "gulp",
"test": "npm run test:node && npm run test:cli",
"test:node": "ts-node node_modules/tape/bin/tape test/common/*.ts | tap-spec",
"test:cli": "ts-node node_modules/tape/bin/tape test/cli/*.ts | tap-spec",
"prebuild": "npm run generate:data && rimraf dist",
"build": "rollup -c rollup.config.js && rimraf .rpt2_cache && tsc",
"coverage": "nyc npm test",
"postcoverage": "rimraf .nyc_output",
"coveralls": "nyc npm test && nyc report -r=text-lcov | coveralls",
"postcoveralls": "rimraf .nyc_output",
"prepublish": "npm run build"
"prepublish": "npm run lint && npm test && npm run build"
},
"types": "types/index.d.ts",
"bin": {
"transliterate": "lib/bin/transliterate",
"slugify": "lib/bin/slugify"
"nyc": {
"extension": [
".ts"
]
},
"repository": {
"type": "git",
"url": "https://github.com/andyhu/transliteration.git"
"url": "https://github.com/dzcpy/transliteration.git"
},

@@ -43,3 +49,3 @@ "keywords": [

"bugs": {
"url": "https://github.com/andyhu/transliteration/issues"
"url": "https://github.com/dzcpy/transliteration/issues"
},

@@ -50,27 +56,30 @@ "engines": {

"devDependencies": {
"babel-core": "^6.25.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
"babel-preset-es2015-ie": "^6.7.0",
"babelify": "^8.0.0",
"browserify": "^16.2.2",
"coveralls": "^3.0.0",
"es5-shim": "^4.5.9",
"eslint": "^5.1.0",
"eslint-config-airbnb-base": "^13.0.0",
"eslint-plugin-import": "^2.3.0",
"gulp": "^3.9.1",
"gulp-babel": "^7.0.0",
"gulp-es3ify": "^0.0.1",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^2.6.0",
"gulp-uglify": "^3.0.0",
"gulp-util": "^3.0.8",
"nyc": "^12.0.2",
"@babel/core": "^7.2.0",
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/plugin-proposal-object-rest-spread": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"@babel/preset-typescript": "^7.1.0",
"@types/execa": "^0.9.0",
"@types/tape": "^4.2.33",
"@types/yargs": "^12.0.4",
"codecov": "^3.1.0",
"coveralls": "^3.0.2",
"execa": "^1.0.0",
"json5": "^2.1.0",
"nyc": "^13.1.0",
"rimraf": "^2.6.1",
"rollup": "^1.0.0",
"rollup-plugin-babel": "^4.3.0",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-hashbang": "^1.0.1",
"rollup-plugin-terser": "^4.0.2",
"rollup-plugin-typescript2": "^0.18.1",
"rollup-plugin-uglify": "^6.0.0",
"tap-spec": "^5.0.0",
"tape": "^4.6.3",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^2.0.0",
"zuul": "^3.11.1"
"tape": "^4.9.1",
"ts-loader": "^5.3.3",
"ts-node": "^7.0.1",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0",
"typescript": "^3.2.2"
},

@@ -77,0 +86,0 @@ "dependencies": {

# Transliteration
[![Build Status](https://travis-ci.org/andyhu/transliteration.svg)](https://travis-ci.org/andyhu/transliteration)
[![Dependencies](https://img.shields.io/david/andyhu/transliteration.svg)](https://github.com/andyhu/transliteration/blob/master/package.json)
[![Dev Dependencies](https://img.shields.io/david/dev/andyhu/transliteration.svg)](https://github.com/andyhu/transliteration/blob/master/package.json)
[![Coverage Status](https://coveralls.io/repos/github/andyhu/node-transliteration/badge.svg?branch=master)](https://coveralls.io/github/andyhu/transliteration?branch=master)
[![Build Status]( https://img.shields.io/circleci/project/github/dzcpy/transliteration.svg)](https://circleci.com/gh/dzcpy/transliteration)
[![Dependencies](https://img.shields.io/david/dzcpy/transliteration.svg)](https://github.com/dzcpy/transliteration/blob/master/package.json)
[![Dev Dependencies](https://img.shields.io/david/dev/dzcpy/transliteration.svg)](https://github.com/dzcpy/transliteration/blob/master/package.json)
[![Coverage Status](https://img.shields.io/codecov/c/github/dzcpy/transliteration.svg)](https://coveralls.io/github/dzcpy/transliteration?branch=master)
[![NPM Version](https://img.shields.io/npm/v/transliteration.svg)](https://www.npmjs.com/package/transliteration)
[![NPM Download](https://img.shields.io/npm/dm/transliteration.svg)](https://www.npmjs.com/package/transliteration)
[![License](https://img.shields.io/npm/l/transliteration.svg)](https://github.com/andyhu/transliteration/blob/master/LICENSE.txt)
[![PRs](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/andyhu/transliteration)
[![License](https://img.shields.io/npm/l/transliteration.svg)](https://github.com/dzcpy/transliteration/blob/master/LICENSE.txt)
[![Sauce Test Status](https://saucelabs.com/browser-matrix/node-transliteration.svg)](https://saucelabs.com/u/node-transliteration)
Universal unicode -> latin transliteration / slugify module. Works with all major languages and on all platforms.
Transliteration / slugify module for node.js, browser, Web Worker, ReactNative and CLI. It provides the ability to transliterate UTF-8 characters into corresponding pure ASCII; so they can be safely displayed, used as URL slugs or file names.
## Demo
[example.html](http://andyhu.github.io/transliteration)
[Try it out](http://dzcpy.github.io/transliteration)
### Compatibility / Browser support
IE 10+ and all modern browsers.
Node.js, in the browser, Web Worker, ReactNative and CLI
## Installation
### Node.js
### Node.js / React Native

@@ -40,32 +43,22 @@ ```bash

```html
<script src="https://unpkg.com/transliteration/lib/browser/transliteration.min.js"></script>
<!-- UMD build -->
<script async defer src="https://cdn.jsdelivr.net/npm/transliteration@2.0.0-alpha1/dist/browser/bundle.umd.min.js"></script>
<!-- ESM build -->
<script async defer src="https://cdn.jsdelivr.net/npm/transliteration@2.0.0-alpha1/dist/browser/bundle.esm.min.js" type="module"></script>
<script type="module">
import { transl } from './bundle.esm.min.js';
console.log(transl('你好'));
</script>
```
__Bower:__
`transliteration` can be loaded as an AMD / CommonJS module, or as global variables (UMD).
```bash
# Install bower if not already installed
# npm install bower -g
bower install transliteration
```
When using it in the browser, by default it will create global variables under `window` object:
```html
<html>
<head>
<script src="bower_components/transliteration/transliteration.min.js"></script>
</head>
<body>
<script>
transl('你好, world!'); // Ni Hao , world!
slugify('你好, world!'); // ni-hao-world
</script>
</body>
</html>
```javascript
transl('你好, World'); // window.transl
// or
slugify('Hello, 世界'); // window.slugify
```
### Browser support
`transliteration` has a good browser compatibility with all major browsers (including IE 6-8 if used with `es5-shim`).
### CLI

@@ -81,33 +74,2 @@

### ReactNative
```javascript
import { transliterate, slugify } from 'transliteration/src/main/browser';
```
## Change log
### 1.7.0 (breaking)
`bower` support is dropped. Please use CDN or a js bundler like `webpack`.
### 1.6.6
Added support for `TypeScript`. #77
### 1.5.0 (breaking)
Since version 1.5.0, `transliteration` module requires minimum node version v6.0.
### 1.0.0 (breaking)
Please note that the code has been entirely refactored since version 1.0.0. Be careful when you plan to upgrade from v0.1.x or v0.2.x to v1.0.x
__Changes:__
* The `options` parameter of `transliterate` now is an `Object` (In 0.1.x it's a string `unknown`).
* Added `transliterate.config` and `slugify.config`.
* Unknown string will be transliterated as `[?]` instead of `?`.
* In the browser, global variables have been changed to `window.transl` and `windnow.slugify`. Other global variables are removed.
## Usage

@@ -123,13 +85,33 @@

{
/* Unicode characters that are not in the database will be replaced with `unknown` */
unknown: '[?]', // default: [?]
/* Custom replacement of the strings before transliteration */
replace: { source1: target1, source2: target2, ... }, // Object form of argument
replace: [[source1, target1], [source2, target2], ... ], // Array form of argument
/* Strings in the ignore list will be bypassed from transliteration */
ignore: [str1, str2] // default: []
/**
* Ignore a list of strings untouched
* @example tr('你好,世界', { ignore: ['你'] }) // 你 Hao , Shi Jie
*/
ignore?: string[];
/**
* Replace a list of string / regex in the source string into the provided target string before transliteration
* The option can either be an array or an object
* @example tr('你好,世界', { replace: {你: 'You'} }) // You Hao , Shi Jie
* @example tr('你好,世界', { replace: [['你', 'You']] }) // You Hao , Shi Jie
* @example tr('你好,世界', { replace: [[/你/g, 'You']] }) // You Hao , Shi Jie
*/
replace?: OptionReplaceCombined;
/**
* Same as `replace` but after transliteration
*/
replaceAfter?: OptionReplaceCombined;
/**
* Decides whether or not to trim the result string after transliteration
* @default false
*/
trim?: boolean;
/**
* Any characters not known by this library will be replaced by a specific string `unknown`
* @default ''
*/
unknown?: string;
}
```
__transliterate.config([optionsObj])__
### transliterate.config([optionsObj])__

@@ -143,3 +125,3 @@ Bind options globally so any following calls will be using `optoinsObj` by default. If `optionsObj` argument is omitted, it will return current default option object.

__Example__
__Examples:__

@@ -167,13 +149,51 @@ ```javascript

```javascript
{
/* Whether to force slags to be lowercased */
lowercase: false, // default: true
/* Separator of the slug */
separator: '-', // default: '-'
/* Custom replacement of the strings before transliteration */
replace: { source1: target1, source2: target2, ... },
replace: [[source1, target1], [source2, target2], ... ], // default: []
/* Strings in the ignore list will be bypassed from transliteration */
ignore: [str1, str2] // default: []
}
/**
* Ignore a list of strings untouched
* @example tr('你好,世界', { ignore: ['你'] }) // 你 Hao , Shi Jie
*/
ignore?: string[];
/**
* Replace a list of string / regex in the source string into the provided target string before transliteration
* The option can either be an array or an object
* @example tr('你好,世界', { replace: {你: 'You'} }) // You Hao , Shi Jie
* @example tr('你好,世界', { replace: [['你', 'You']] }) // You Hao , Shi Jie
* @example tr('你好,世界', { replace: [[/你/g, 'You']] }) // You Hao , Shi Jie
*/
replace?: OptionReplaceCombined;
/**
* Same as `replace` but after transliteration
*/
replaceAfter?: OptionReplaceCombined;
/**
* Decides whether or not to trim the result string after transliteration
* @default false
*/
trim?: boolean;
/**
* Any characters not known by this library will be replaced by a specific string `unknown`
* @default ''
*/
unknown?: string;
/**
* Whether the result need to be converted into lowercase
* @default true
*/
lowercase?: boolean;
/**
* Whether the result need to be converted into uppercase
* @default false
*/
uppercase?: boolean;
/**
* Custom separator string
* @default '-'
*/
separator?: string;
/**
* Allowed characters.
* When `allowedChars` is set to `'abc'`, then only characters match `/[abc]/g` will be preserved.
* Other characters will all be converted to `separator`
* @default 'a-zA-Z0-9-_.~''
*/
allowedChars?: string;
```

@@ -183,3 +203,3 @@

__slugify.config([optionsObj])__
### slugify.config([optionsObj])

@@ -195,2 +215,4 @@ Bind options globally so any following calls will be using `optoinsObj` by default. If `optionsObj` argument is omitted, it will return current default option object.

### Node.js / webpack
```javascript

@@ -210,30 +232,7 @@ import { slugify } from 'transliteration';

### Usage in browser
`transliteration` can be loaded as an AMD / CommonJS module, or as global variables (UMD).
When using it in the browser, by default it will create global variables under `window` object:
```javascript
transl('你好, World'); // window.transl
// or
slugify('Hello, 世界'); // window.slugify
```
If the variable names conflict with other libraries in your project or you prefer not to use global variables, use noConfilict() before loading libraries which contain the conflicting variables.:
__Load the library globally__
### CLI
```javascript
var tr = transl.noConflict();
console.log(transl); // undefined
tr('你好, World'); // Ni Hao , World
var slug = slugify.noConfilict();
slug('你好, World'); // ni-hao-world
console.log(slugify); // undefined
```
### Usage in command line
```
➜ ~ transliterate --help

@@ -244,15 +243,13 @@ Usage: transliterate <unicode> [options]

--version Show version number [boolean]
-u, --unknown Placeholder for unknown characters [string] [default: "[?]"]
-u, --unknown Placeholder for unknown characters [string] [default: ""]
-r, --replace Custom string replacement [array] [default: []]
-i, --ignore String list to ignore [array] [default: []]
-S, --stdin Use stdin as input [boolean] [default: false]
-h, --help Show help [boolean]
-S, --stdin Use stdin as input [boolean] [default: false]
-h, --help [boolean]
Examples:
transliterate "你好, world!" -r 好=good -r Replace `,` into `!` and `world` into
"world=Shi Jie" `shijie`.
Result: Ni good, Shi Jie!
transliterate "你好, world!" -r 好=good -r Replace `,` into `!`, `world` into `shijie`.
"world=Shi Jie" Result: Ni good, Shi Jie!
transliterate "你好,世界!" -i 你好 -i , Ignore `你好` and `,`.
Result: 你好,Shi Jie !
Result: 你好,world!
```

@@ -266,3 +263,5 @@

--version Show version number [boolean]
-l, --lowercase Use lowercase [boolean] [default: true]
-U, --unknown Placeholder for unknown characters [string] [default: ""]
-l, --lowercase Peturns result in lowercase [boolean] [default: true]
-u, --uppercase Returns result in uppercase [boolean] [default: false]
-s, --separator Separator of the slug [string] [default: "-"]

@@ -272,3 +271,3 @@ -r, --replace Custom string replacement [array] [default: []]

-S, --stdin Use stdin as input [boolean] [default: false]
-h, --help Show help [boolean]
-h, --help [boolean]

@@ -284,23 +283,49 @@ Examples:

### Caveats
Currently, `transliteration` uses 1 to 1 character map (from Unicode to Latin) under the hood. It is the simplest way to implement, but it has some limitations when dealing with polyphonic characters and languages which share overlapped character sets. It does not work well in some specific languages when the same characters can be transliterated differently when they are placed at different places. Some of the issues are listed below:
## Change log
* _Chinese:_ Polyphonic characters are not always transliterated correctly. Alternative: `pinyinlite`.
### 2.0.0
* _Japanese:_ With `transliteration`, most Japanese Kanji characters are transliterated to Chinese Pinyin because of their overlapping of characters in Unicode. Also there are many polyphonic characters. without doing a word splitting or word mapping, it's impossible to transliterate Kanji accurately. Alternative: `kuroshiro`.
* **CDN file path changes**
* The entire module was refactored in Typescript, with a big performance improvement as well as a reduced package size.
* Better code quality. 100% unit tested.
* `bower` support was dropped. Please use CDN or together with a js bundler like `webpack` or `rollup`.
* As according to RFC 3986, more characters(`/a-zA-Z0-9-_.~/`) are kept as result for `slugify`
* _Thai:_ Currently it is not working. There seems no working open source project I can directly copy code from. I found some articles explaining the how to transliterate Thai though. I would appreciate if anyone who is interested implementing it can lend a hand. See: [#67](https://github.com/andyhu/transliteration/issues/67).
### 1.6.6
* _Cylic_ Cylic characters are overlapped between a few languages. The result might be inaccurate in some specific languages, for example Bulgarian.
* Added support for `TypeScript`. #77
If you there's any other issues, please raise a ticket.
### 1.5.0
### Powered by BrowserStack
* Minimum node requirement: 6.0+
[![BrowserStack](https://raw.githubusercontent.com/andyhu/transliteration/gh-pages/browserstack-logo-600x315.png)](http://browserstack.com/)
BrowserStack is a fantastic service for testing your web applications in tons of different real browsers and mobile devices. `transliteration` uses BrowserStack to do unit test in different browsers.
### 1.0.0
* Code had been entirely refactored since version 1.0.0. Be careful when you plan to upgrade from v0.1.x or v0.2.x to v1.0.x
__Changes:__
* The `options` parameter of `transliterate` now is an `Object` (In 0.1.x it's a string `unknown`).
* Added `transliterate.config` and `slugify.config`.
* Unknown string will be transliterated as `[?]` instead of `?`.
* In the browser, global variables have been changed to `window.transl` and `windnow.slugify`. Other global variables are removed.
## Caveats
Currently, `transliteration` only supports 1 to 1 code map (from Unicode to Latin). It is the simplest way to implement, but there are some limitations when dealing with polyphonic characters. It does not work well with all languages, please test all possible situations before using it. Some known issues are:
* __Chinese:__ Polyphonic characters are not always transliterated correctly. Alternative: `pinyin`.
* __Japanese:__ Most Japanese Kanji characters are transliterated into Chinese Pinyin because of the overlapped code map in Unicode. Also there are many polyphonic characters in Japanese which makes it impossible to transliterate Japanese Kanji correctly without tokenizing the sentence. Consider using `kuroshiro` for a better Kanji -> Romaji conversion.
* __Thai:__ Currently it is not working. If you know how to make it work, please contact me.
* __Cylic:__ Cylic characters are overlapped between a few languages. The result might be inaccurate in some specific languages, for example Bulgarian.
If you there's any other issues, please raise a ticket.
### License
MIT
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