deno.land / x / simple_utility@v0.0.9 / src / text.ts

نووسراو ببینە
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
/*** Convert from unicode string to UTF-8 byte array.* @param data unicode string.* @return byte array in UTF-8 format.*/export function ucEncode(data:string){ return new TextEncoder().encode(data);}
/*** Convert from UTF-8 byte array to unicode string.* @param data byte array in UTF-8 format.* @return unicode string.*/export function ucDecode(data:Uint8Array){ return new TextDecoder().decode(data);}
/*** Convert from byte array to HEX string.* @param data byte array.* @return HEX string.*/export function hexEncode(data:Uint8Array){ return [...data].map(n => n.toString(16).toUpperCase().padStart(2, "0")).join("");}
/*** In addition to leading and trailing spaces, tabs, carriage returns, and two or more consecutive spaces are converted to a single space.* @param data messy string.* @return formatted string.*/export function trimExtend(data:string){ return data.trim().replace(/\r/g, "").replace(/\t/g, " ").replace(/ +/g, " ").replace(/ +$/mg, "");}
simple_utility

Version Info

Tagged at
a year ago