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

limax

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

limax - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

60

lib/limax.js
'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 @@ });

6

package.json
{
"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

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