-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathunicode-mapper.js
More file actions
50 lines (43 loc) · 1.01 KB
/
Copy pathunicode-mapper.js
File metadata and controls
50 lines (43 loc) · 1.01 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function toUnicode (word) {
return new Promise((resolve, reject) => {
setTimeout(() => {
try {
const unicode = word.split("").map((value) => {
let temp = value.charCodeAt(0).toString(16).toUpperCase();
if (temp.length > 2) {
return `\\u${temp}`;
}
return value;
}).join("");
resolve(unicode);
} catch (error) {
reject(error);
}
}, 1000);
});
}
const words = [
"コード",
"コンピューター",
"ロボット",
"エラー",
"キーボード",
"コンソール"
];
const promises = words.map(toUnicode);
Promise.all(promises)
.then((results) => {
console.log(results);
})
.catch((error) => {
console.error(error);
});
// Async output:
// [
// '\\u30B3\\u30FC\\u30C9',
// '\\u30B3\\u30F3\\u30D4\\u30E5\\u30FC\\u30BF\\u30FC',
// '\\u30ED\\u30DC\\u30C3\\u30C8',
// '\\u30A8\\u30E9\\u30FC',
// '\\u30AD\\u30FC\\u30DC\\u30FC\\u30C9',
// '\\u30B3\\u30F3\\u30BD\\u30FC\\u30EB'
// ]