From 11326d1e6f6db224a9d9b389246d3f23a326c368 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 26 Jan 2021 11:23:19 +0000 Subject: [PATCH] Bump minimum Node.js version to 10 Ensure lack of pinyin fails gracefully --- lib/limax.js | 7 +++++-- package.json | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/limax.js b/lib/limax.js index 576ed92..0a7da5d 100644 --- a/lib/limax.js +++ b/lib/limax.js @@ -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 || []; @@ -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; diff --git a/package.json b/package.json index cb86488..519d4b0 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "url": "git://github.com/lovell/limax" }, "engines": { - "node": ">=8" + "node": ">=10" }, "scripts": { "test": "semistandard && nyc --reporter=html ava" @@ -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" } -} \ No newline at end of file +}