feat: add common-utils (#2374)

This commit is contained in:
Henry Wang
2019-06-12 04:09:27 +01:00
committed by DIYgod
parent 07ce725bf4
commit 4531de80f9
4 changed files with 35 additions and 16 deletions

View File

@@ -1,4 +1,5 @@
const got = require('@/utils/got');
const { toTitleCase } = require('@/utils/common-utils');
const dayjs = require('dayjs');
module.exports = async (ctx) => {
@@ -13,7 +14,7 @@ module.exports = async (ctx) => {
locations.split(',').forEach(function(pair) {
const country = pair.split('+')[0];
const city = titleCase(pair.split('+')[1]);
const city = toTitleCase(pair.split('+')[1]);
url += `{"country":"${country}","city":"${city}"},`;
host += `/${country}/${city.replace(' ', '_')}`;
@@ -43,12 +44,3 @@ module.exports = async (ctx) => {
})),
};
};
const titleCase = (str) =>
str
.toLowerCase()
.split(' ')
.map(function(word) {
return word.replace(word[0], word[0].toUpperCase());
})
.join(' ');