forked from aszx87410/medium-user-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
28 lines (24 loc) · 753 Bytes
/
utils.js
File metadata and controls
28 lines (24 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module.exports = {
// @see: https://stackoverflow.com/questions/44669073/regular-expression-to-match-and-split-on-chinese-comma-in-javascript/51941287#51941287
isChinese: (text = '') => {
const regex = /(\p{Script=Hani})+/gu;
return text.match(regex)
},
// @see: https://gist.github.com/ryanmcgrath/982242
isJapanese: (text = '') => {
const regexJP = /[\u3040-\u309F]|[\u30A0-\u30FF]/g;
const jp = text.match(regexJP)
// more than 2 japanese char
if (jp && jp.length >= 2) {
return true
}
return false
},
sleep: ms => new Promise(resolve => {
setTimeout(resolve, ms)
}),
log: function () {
const args = Array.prototype.slice.call(arguments);
console.log.apply(console, args)
}
}