Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dzcpy/transliteration
Browse files Browse the repository at this point in the history
  • Loading branch information
User committed Jan 18, 2019
2 parents 724cbeb + 8b17b81 commit 9ee6cab
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
47 changes: 27 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Universal Unicode ➡ Latin transliteration / slugify module. Works with all maj

[Try it out](http://dzcpy.github.io/transliteration)

### Compatibility / Browser support
## Compatibility / Browser support

IE 9+ and all modern browsers.

Expand All @@ -31,38 +31,39 @@ npm install transliteration --save
```javascript
import { transliterate as tr, slugify } from 'transliteration';

tr('你好, world!'); // Ni Hao , world!
slugify('你好, world!'); // ni-hao-world
tr('你好, world!');
// Ni Hao , world!
slugify('你好, world!');
// ni-hao-world
```

### Browser

__CDN:__
### Browser (CDN):

```html
<!-- UMD build -->
<script async defer src="https://cdn.jsdelivr.net/npm/transliteration@2.0.4/dist/browser/bundle.umd.min.js"></script>
<script>
console.log(transl('你好'));
console.log(transliterate('你好'));
</script>
```

```html
<!-- ESM build -->
<script type="module">
import { transl } from 'https://cdn.jsdelivr.net/npm/transliteration@2.0.4/dist/browser/bundle.esm.min.js';
console.log(transl('你好'));
import { transliterate } from 'https://cdn.jsdelivr.net/npm/transliteration@2.0.4/dist/browser/bundle.esm.min.js';
console.log(transliterate('你好'));
</script>
```

`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:
When using it in the browser, by default it creates global variables under `window` object:

```javascript
transl('你好, World'); // window.transl
// or
slugify('Hello, 世界'); // window.slugify
transliterate('你好, World');
// window.transliterate
slugify('Hello, 世界');
// window.slugify
```

### CLI
Expand Down Expand Up @@ -191,7 +192,7 @@ __Options:__ (optional)
separator?: string;
/**
* Allowed characters.
* When `allowedChars` is set to `'abc'`, then only characters match `/[abc]/g` will be preserved.
* When `allowedChars` is set to `'abc'`, then only characters which match `/[abc]/g` will be preserved.
* Other characters will all be converted to `separator`
* @default 'a-zA-Z0-9-_.~''
*/
Expand All @@ -216,12 +217,13 @@ slugify('你好,世界', { ignore: ['你好'] });
// 你好shi-jie

slugify.config({ lowercase: false, separator: '_' });
slugify('你好,世界'); // Ni_Hao_Shi_Jie
// get configurations
slugify('你好,世界');
// Ni_Hao_Shi_Jie
console.log(slugify.config());
// { lowercase: false, separator: "_" }
slugify.config({ replace: [['你好', 'Hello']] });
slugify('你好, world!'); // This equals slugify('你好, world!', { replace: [['你好', 'Hello']] });
// hello-world
slugify('你好, world!');
// This equals slugify('你好, world!', { replace: [['你好', 'Hello']] });
console.log(slugify.config());
// { replace: [['你好', 'Hello']] }
slugify.config(undefined, true);
Expand Down Expand Up @@ -279,16 +281,21 @@ Examples:

## Change log

### 2.1.0

* Added `transliterate` as global variable for browser builds. Keep `transl` for backward compatibility.

### 2.0.0

* **CDN files path changed**
* The entire module had been` refactored in Typescript, with big performance improvements as well as a reduced package size.
* **CDN file structure changed**: [https://www.jsdelivr.com/package/npm/transliteration](https://www.jsdelivr.com/package/npm/transliteration)
* The entire module had been refactored in Typescript, with big performance improvements as well as a reduced package size.
* Better code quality. 100% unit tested.
* `bower` support was dropped. Please use CDN or `webpack`/`rollup`.
* As according to RFC 3986, more characters(`/a-zA-Z0-9-_.~/`) are kept as result for `slugify`, and it is configurable.
* Added `uppercase` as an option for `slugify`, if is set to `true` then the generated slug will be converted to uppercase letters.
* Unknown characters will be transliterated as empty string by default, instead of a meaningless `[?]`.


### 1.6.6

* Added support for `TypeScript`. #77
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "transliteration",
"version": "2.0.4",
"version": "2.1.0",
"description": "Unicode to ACSII transliteration / slugify module for node.js, browser, Web Worker, ReactNative and CLI.",
"main": "dist/node/src/node/index.js",
"module": "dist/browser/bundle.esm.min.js",
Expand Down Expand Up @@ -71,7 +71,7 @@
"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-typescript2": "^0.19.0",
"rollup-plugin-uglify": "^6.0.0",
"tap-spec": "^5.0.0",
"tape": "^4.9.1",
Expand Down
2 changes: 1 addition & 1 deletion src/browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { slugify, transliterate } from '../node';
export { transliterate as transl, slugify };
export { transliterate as transl, transliterate, slugify };
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@ export type SlugifyFunction = TransliterationFunction<OptionsSlugify>;

export interface BrowserGlobalObject {
transl: TransliterateFunction;
transliterate: TransliterateFunction;
slugify: SlugifyFunction;
}

0 comments on commit 9ee6cab

Please sign in to comment.