-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstring.es
More file actions
95 lines (70 loc) · 2.06 KB
/
string.es
File metadata and controls
95 lines (70 loc) · 2.06 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { logStyle } from '../helper/logger.es';
console.log('%cstring.es', 'background-color: #4CAF50; padding: 0 100px; font-size: 32px; color: white;');
if (true) {
logStyle('针对四个字节的字符提取 API');
let result = [];
for (let c of '𠮷a') {
result.push({
'char': c,
'codePointAt': `${c.codePointAt(0)}, ${c.codePointAt(0).toString(16)}`,
'charCodeAt': `${c.charCodeAt(0)}, ${c.charCodeAt(0).toString(16)}`,
'fromCodePoint': String.fromCodePoint(c.codePointAt(0)),
'fromCharCode': String.fromCharCode(c.codePointAt(0))
});
}
console.table(result);
}
if (true) {
function is32Bit(c) {
return c.codePointAt(0) > 0xFFFF;
}
logStyle(is32Bit);
console.log(is32Bit('𠮷'), is32Bit('a'));
}
if (true) {
logStyle('for...of 可以识别大于 0xFFFF 的码点');
}
if (true) {
logStyle("'\\u01D1'.normalize() === ");
console.log('\u01D1'.normalize());
}
if (true) {
logStyle("'abcd'.includes(待搜索的字符串, 搜索的起始位置)");
console.log('abcd'.includes('bc'));
}
if (true) {
logStyle("'abcd'.startsWith(待匹配的字符串, 匹配的起始位置)");
console.log('abcd'.startsWith('bc', 1));
}
if (true) {
logStyle("'abcd'.endsWith(待匹配的字符串, 匹配的截止位置)");
console.log('abcd'.endsWith('bc', 3));
}
if (true) {
logStyle("'abc'.repeat(3)");
console.log('abc'.repeat(3));
}
if (true) {
// console.log("[ES7] 'abc'.padStart(10, '-')", 'abc'.padStart(10, '-'));
// console.log("[ES7] 'abc'.padEnd(10, '-')", 'abc'.padEnd(10, '-'));
}
if (true) {
logStyle("模板字符串");
console.log(`
<h1>
${[location.href, location.pathname].map(function(t) {
return `<a href="${t}">${t}</a>`
}).join('\n')}
</h1>
`);
}
if (true) {
logStyle('标签模板');
function f1(str) {
console.log(str, arguments);
}
f1`hello ${Date.now()} world`
}
if (true) {
logStyle('String.raw()');
}