Comparing version 1.1.1 to 1.1.2
'use strict'; | ||
var speakingurl = require('speakingurl'); | ||
var cld = require('cld'); | ||
var pinyin = require('pinyin2'); | ||
var hepburn = require('hepburn'); | ||
var deferred = require('deferred'); | ||
@@ -14,15 +12,3 @@ module.exports = function(text, opt) { | ||
} | ||
var lang = options.lang; | ||
if (typeof lang === 'undefined') { | ||
var deferredLang = deferred(); | ||
cld.detect(text, function(err, data) { | ||
if (err) { | ||
// Default to English | ||
deferredLang.resolve('en'); | ||
} else { | ||
deferredLang.resolve(data.languages[0].code.substr(0, 2)); | ||
} | ||
}); | ||
lang = deferredLang.promise; | ||
} | ||
// Remove apostrophes contained within a word | ||
@@ -34,23 +20,25 @@ text = text.replace(/(\S)['\u2018\u2019\u201A\u201B\u2032\u2035](\S)/g, '$1$2'); | ||
var mergeDigitSuffixes = false; | ||
// Convert Mandarin Chinese to Pinyin with numeric tones | ||
if (lang == 'zh') { | ||
// Should we use tone numbers? (default is true) | ||
var tone = (typeof options.tone === 'boolean') ? options.tone : true; | ||
text = pinyin(text, { | ||
'style': tone ? pinyin.STYLE_TONE2 : pinyin.STYLE_NORMAL | ||
}).join(' '); | ||
// Remove punctuation symbols | ||
text = text.replace(/([^0-9A-Za-z ]+)/g, ''); | ||
// Remove space around single character words, caused by non-Mandarin symbols in otherwise Mandarin text | ||
text = text.replace(/([^1-4]) ([A-Za-z]) /g, '$1$2'); | ||
lang = 'en'; | ||
mergeDigitSuffixes = true; | ||
// Language-specific behaviour | ||
var lang = options.lang; | ||
if (typeof lang === 'undefined') { | ||
if (hepburn.containsKana(text)) { | ||
// Convert from Japanese Kana using Hepburn romanisation | ||
text = hepburn.fromKana(text); | ||
// Remove any remaining non-Kana, e.g. Kanji | ||
text = text.replace(/([^A-Za-z0-9\- ]+)/g, ''); | ||
} else if (/[\u4e00-\u9fa5]+/.test(text)) { | ||
// Convert Mandarin Chinese to Pinyin with numeric tones | ||
mergeDigitSuffixes = true; | ||
// Should we use tone numbers? (default is true) | ||
var tone = (typeof options.tone === 'boolean') ? options.tone : true; | ||
text = pinyin(text, { | ||
'style': tone ? pinyin.STYLE_TONE2 : pinyin.STYLE_NORMAL | ||
}).join(' '); | ||
// Remove punctuation symbols | ||
text = text.replace(/([^0-9A-Za-z ]+)/g, ''); | ||
// Remove space around single character words, caused by non-Mandarin symbols in otherwise Mandarin text | ||
text = text.replace(/([^1-4]) ([A-Za-z]) /g, '$1$2'); | ||
} | ||
} | ||
// Convert Japanese Kana to Romaji | ||
if (lang == 'ja') { | ||
text = hepburn.fromKana(text); | ||
// Remove any non-Kana, e.g. Kanji | ||
text = text.replace(/([^A-Za-z0-9\- ]+)/g, ''); | ||
lang = 'en'; | ||
} | ||
// Convert to slug using speakingurl | ||
@@ -62,3 +50,3 @@ var separator = options.replacement || options.separator; | ||
var slug = speakingurl(text, { | ||
lang: lang, | ||
lang: lang || 'en', | ||
separator: separator | ||
@@ -65,0 +53,0 @@ }); |
{ | ||
"name": "limax", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"main": "./lib/limax", | ||
@@ -31,6 +31,4 @@ "description": "Node.js module to generate URL slugs. Another one? This one cares about i18n and transliterates non-Latin scripts to conform to the RFC3986 standard. Mostly API-compatible with similar modules.", | ||
"author": "Lovell Fuller <npm@lovell.info>", | ||
"license": "Apache 2.0", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"cld": "^2.4.3", | ||
"deferred": "^0.7.2", | ||
"hepburn": "^0.6.0", | ||
@@ -37,0 +35,0 @@ "pinyin2": "^2.0.8", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
6344
52
- Removedcld@^2.4.3
- Removeddeferred@^0.7.2
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcld@2.10.0(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedd@1.0.2(transitive)
- Removeddeferred@0.7.11(transitive)
- Removedes5-ext@0.10.64(transitive)
- Removedes6-iterator@2.0.3(transitive)
- Removedes6-symbol@3.1.4(transitive)
- Removedesniff@2.0.1(transitive)
- Removedevent-emitter@0.3.5(transitive)
- Removedext@1.7.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedminimatch@3.1.2(transitive)
- Removednext-tick@1.1.0(transitive)
- Removednode-addon-api@8.2.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedtimers-ext@0.1.8(transitive)
- Removedtype@2.7.3(transitive)
- Removedunderscore@1.13.7(transitive)
- Removedwrappy@1.0.2(transitive)