Comparing version 1.0.1 to 1.0.2
@@ -1,22 +0,16 @@ | ||
/** | ||
* limax | ||
* @author Lovell Fuller | ||
* | ||
* This code is distributed under the Apache License Version 2.0, the terms of | ||
* which may be found at http://www.apache.org/licenses/LICENSE-2.0.html | ||
*/ | ||
'use strict'; | ||
var speakingurl = require("speakingurl"); | ||
var cld = require("cld"); | ||
var pinyin = require("pinyin2"); | ||
var hepburn = require("hepburn"); | ||
var deferred = require("deferred"); | ||
var speakingurl = require('speakingurl'); | ||
var cld = require('cld'); | ||
var pinyin = require('pinyin2'); | ||
var hepburn = require('hepburn'); | ||
var deferred = require('deferred'); | ||
module.exports = function(text, opt) { | ||
var options = opt || {}; | ||
if (typeof options === "string") { | ||
if (typeof options === 'string') { | ||
options = {separator: options}; | ||
} | ||
var lang = options.lang; | ||
if (typeof lang === "undefined") { | ||
if (typeof lang === 'undefined') { | ||
var deferredLang = deferred(); | ||
@@ -26,3 +20,3 @@ cld.detect(text, function(err, data) { | ||
// Default to English | ||
deferredLang.resolve("en"); | ||
deferredLang.resolve('en'); | ||
} else { | ||
@@ -34,22 +28,29 @@ deferredLang.resolve(data.languages[0].code); | ||
} | ||
// Remove apostrophes contained within a word | ||
text = text.replace(/(\S)['\u2018\u2019\u201A\u201B\u2032\u2035](\S)/g, '$1$2'); | ||
// Break out any numbers contained within a word | ||
text = text.replace(/(\S)([0-9]+)(\S)/g, '$1 $2 $3'); | ||
// Should we remove the separator before a digit where previous word does not end in a digit? | ||
var mergeDigitSuffixes = false; | ||
// Convert Mandarin Chinese to Pinyin with numeric tones | ||
if (lang == "zh") { | ||
if (lang == 'zh') { | ||
text = pinyin(text, { | ||
"style": pinyin.STYLE_TONE2 | ||
}).join(" "); | ||
'style': pinyin.STYLE_TONE2 | ||
}).join(' '); | ||
// Remove punctuation symbols | ||
text = text.replace(/([^0-9A-Za-z ]+)/g, ""); | ||
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"; | ||
text = text.replace(/([^1-4]) ([A-Za-z]) /g, '$1$2'); | ||
lang = 'en'; | ||
mergeDigitSuffixes = true; | ||
} | ||
// Convert Japanese Kana to Romaji | ||
if (lang == "ja") { | ||
if (lang == 'ja') { | ||
text = hepburn.fromKana(text); | ||
// Remove any non-Kana, e.g. Kanji | ||
text = text.replace(/([^A-Za-z0-9\- ]+)/g, ""); | ||
lang = "en"; | ||
text = text.replace(/([^A-Za-z0-9\- ]+)/g, ''); | ||
lang = 'en'; | ||
} | ||
// Convert to slug using speakingurl | ||
var separator = options.replacement || options.separator || "-"; | ||
var separator = options.replacement || options.separator || '-'; | ||
var slug = speakingurl(text, { | ||
@@ -60,3 +61,6 @@ lang: lang, | ||
// Remove separator before a digit where previous word does not end in a digit | ||
return slug.replace(/([^0-9])-([0-9])/g, "$1$2"); | ||
if (mergeDigitSuffixes) { | ||
slug = slug.replace(/([^0-9])-([0-9])/g, '$1$2'); | ||
} | ||
return slug; | ||
}; |
{ | ||
"name": "limax", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "./lib/limax", | ||
@@ -5,0 +5,0 @@ "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.", |
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
6162
4
61