Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'
);
}
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;
};
toolName.forEach(name => {
toolPinyin[name] = {
first: group(
pinyin(name.replace(/\s/g, '').toLowerCase(), {
style: pinyin.STYLE_FIRST_LETTER,
heteronym: true
})
),
pinyin: group(
pinyin(name.replace(/\s/g, '').toLowerCase(), {
style: pinyin.STYLE_NORMAL,
heteronym: true
})
)
};
});
var toPinYin = function(text) {
var py1 = mergeString(pinyin(text, {style: pinyin.STYLE_NORMAL}));
if(py1 === '' || py1 === text) return '';
return py1 + ' ' + mergeString(pinyin(text, {style: pinyin.STYLE_FIRST_LETTER}));
};
function getPinyin(name) {
return pinyin(name, {
style: pinyin.STYLE_NORMAL
}).join('');
}
async getCityName(req){
try{
const cityInfo = await this.guessPosition(req);
/*
汉字转换成拼音
*/
const pinyinArr = pinyin(cityInfo.city, {
style: pinyin.STYLE_NORMAL,
});
let cityName = '';
pinyinArr.forEach(item => {
cityName += item[0];
})
return cityName;
}catch(err){
return '北京';
}
}
async getExactAddress(req, res, next){