Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Should we remove the separator before a digit where previous word does not end in a digit?
let mergeDigitSuffixes = false;
// Language-specific behaviour
const lang = options.lang || '';
if (lang.toLowerCase().startsWith('ja') || 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 (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;
text = pinyin(text, {
style: tone ? pinyin.STYLE_TONE2 : pinyin.STYLE_NORMAL
}).join(' ');
// Remove punctuation symbols
const customNonPunctuation = customCharsAsArray(options.custom).map(function (c) { return `\\${c}`; }).join('');
const nonPunctuationMatcher = new RegExp(`([^0-9A-Za-z ${customNonPunctuation}]+)`, 'g');
text = text.replace(nonPunctuationMatcher, '');
// 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 to slug using speakingurl
const separator = options.replacement || options.separator;
const slug = speakingurl(text, {
lang: lang || 'en',
separator: typeof separator === 'string' ? separator : '-',
maintainCase: options.maintainCase || false,
custom: options.custom || {}
});
function getYunMu(word) {
/**
* 声母数组
*/
var shenMu = pinyin(word, {
style: pinyin.STYLE_FIRST_LETTER, // 设置拼音风格
segment: true,
heteronym: true
})
/**
* 单词全拼数组
*/
var wholePinyinArray = pinyin(word, {
style: pinyin.STYLE_NORMAL, // 设置拼音风格
segment: true,
heteronym: true
})
// console.log(shenMu);
// console.log(wholePinyinArray);
// 全拼 减去 声母 得到韵语 用逗号分隔
var yunMu = wholePinyinArray.map((fullPinyin, index) => {
return fullPinyin[0].replace(shenMu[index][0], '')
}
//找出每行从行尾开始第一个汉字
if(flag == 1) {
for(var i=line.length-1;i>=0;i--) {
var lastChar = line.charAt(i);
if(lastChar.isCN()) {
words.push(lastChar);
chars += lastChar;
break;
}
}
}
}
var finalRes = pinyin(chars, {style: pinyin.STYLE_FINALS});
for(var i in finalRes) {
finals.push(finalRes[i][0]);
}
// console.log(finals);
return {words:words,finals:finals};
}
return dataProvider.Author.findOne({ name: authorName }).exec().then(async doc => {
if (doc) {
return doc._id
} else {
const slug = pinyin(
authorName, {
style: pinyin.STYLE_NORMAL
})
.map(seg => seg[0])
// isAlphanumeric checks args lenght to determine locale
// if more than one there will be a problem, and an error
// will be thrown
.filter(str => validator.isAlphanumeric(str))
.join('')
const result = await dataProvider.Author.utils.save({
name: authorName,
slug,
description
})
return result._id
}
})
var geoJson = {
type: 'FeatureCollection',
features: provinceDetail.districts[0].districts.map(function (city) {
var cityCode = city.citycode;
var cityDetail = readCity(provinceName, city.name);
return makeFeature(cityDetail.districts.filter(function (distrct) {
return distrct.citycode === cityCode;
})[0], 0, 0.0005);
})
};
var jsonStr = JSON.stringify(compress(geoJson));
var pinyinName = pinyin(provinceFullShortMap[provinceName], {
// heteronym: true,
style: pinyin.STYLE_NORMAL
}).join('');
fs.writeFileSync(
'../json/province/' + pinyinName + '.json',
jsonStr,
'utf-8'
);
fs.writeFileSync(
'../js/province/' + pinyinName + '.js',
jsTplStr.replace('{{name}}', provinceFullShortMap[provinceName])
.replace('{{data}}', jsonStr),
'utf-8'
);
}
set.colors = set.colors.map(c => {
let heteronymIdx = c.name.indexOf('藏') > -1 ? 1 : 0;
return {
...c,
RGB: convert.hex.rgb(c.hex),
CMYK: convert.hex.cmyk(c.hex),
pinyin: pinyin(c.name, {
heteronym: true, // 启用多音字模式
segment: true // 启用分词,以解决多音字问题。
})
.map(item => {
return item.length > 1 ? item[heteronymIdx] : item;
})
.join(' ')
};
});
return set;
function getShenMu(word) {
/**
* 声母数组
*/
var shenMu = pinyin(word, {
style: pinyin.STYLE_INITIALS, // 设置拼音风格
segment: true,
heteronym: true
})
return shenMu
}
/**
mds.forEach(function(item){
var title = item.substr(0,item.length-3);
var py = pinyin(title,{
style: pinyin.STYLE_NORMAL,
heteronym: false
}).reduce(function(prev,next){
return prev.concat(next)
},[]).join("_");
var html = markdown.toHTML(fs.readFileSync("newfile/"+item).toString());
fs.writeFileSync("archives/"+py+".html",compiled({
raw: encodeURIComponent(py),
title: title,
html: html
}));
})
console.log("done!");
return name.split('-').map(item => pinyin(item, {
style: pinyin.STYLE_NORMAL,
segment: true
}).join('-')).join('-') + ext;
};
static isValidNameHint(nameHint, userName) {
const pinyinRaw = pinyin(userName, {
style: pinyin.STYLE_FIRST_LETTER,
});
let pinyinName = '';
for (const py of pinyinRaw) {
if (py[0] && py[0] !== ' ') {
pinyinName += py[0];
}
}
const nameRe = new RegExp(nameHint[1], 'ig');
return nameRe.test(userName) || nameRe.test(pinyinName);
}