Skip to content

Commit

Permalink
Bump minimum Node.js version to 10
Browse files Browse the repository at this point in the history
Ensure lack of pinyin fails gracefully
  • Loading branch information
lovell committed Jan 26, 2021
1 parent bf5e3de commit 11326d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/limax.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use strict';

const speakingurl = require('speakingurl');
const { pinyin, PINYIN_STYLE } = require('@napi-rs/pinyin');
const hepburn = require('hepburn');
let pinyin, PINYIN_STYLE;
try {
({ pinyin, PINYIN_STYLE } = require('@napi-rs/pinyin'));
} catch (err) {}

function customCharsAsArray (custom) {
custom = custom || [];
Expand Down Expand Up @@ -34,7 +37,7 @@ module.exports = function (text, opt) {
text = hepburn.fromKana(text);
// Remove any remaining non-Kana, e.g. Kanji
text = text.replace(/([^A-Za-z0-9\- ]+)/g, '');
} else if (lang.toLowerCase().startsWith('zh') || /[\u4e00-\u9fa5]+/.test(text)) {
} else if (pinyin && (lang.toLowerCase().startsWith('zh') || /[\u4e00-\u9fa5]+/.test(text))) {
// Should we use tone numbers? (default is true)
const tone = (typeof options.tone === 'boolean') ? options.tone : true;
mergeDigitSuffixes = tone;
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"url": "git://github.com/lovell/limax"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "semistandard && nyc --reporter=html ava"
Expand Down Expand Up @@ -45,8 +45,8 @@
"speakingurl": "^14.0.1"
},
"devDependencies": {
"ava": "^3.13.0",
"ava": "^3.15.0",
"nyc": "^15.1.0",
"semistandard": "^16.0.0"
}
}
}

0 comments on commit 11326d1

Please sign in to comment.