forked from mxx1111/mdlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicHelpers.ts
More file actions
34 lines (31 loc) · 799 Bytes
/
Copy pathbasicHelpers.ts
File metadata and controls
34 lines (31 loc) · 799 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
29
30
31
32
33
34
/**
* 首字母大写
*/
export function ucfirst(str: string) {
return str.slice(0, 1).toUpperCase() + str.slice(1).toLowerCase()
}
export function escapeHtml(text: string): string {
return text
.replace(/&/g, `&`)
.replace(/</g, `<`)
.replace(/>/g, `>`)
.replace(/"/g, `"`)
.replace(/'/g, `'`)
}
export function unescapeHtml(text: string): string {
return text
.replace(/"/g, `"`)
.replace(/'/g, `'`)
.replace(/</g, `<`)
.replace(/>/g, `>`)
.replace(/&/g, `&`)
}
export function simpleHash(str: string): string {
let hash = 0
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i)
hash = ((hash << 5) - hash) + char
hash = hash & hash
}
return Math.abs(hash).toString(36)
}