deno.land / x / deno_utils@v0.0.3 / mod.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
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
96
97
98
99
/** * @param arr * @param key */export const extractObjectValue = <T>(arr: T[], key: keyof T) => arr.map(item => item[key])
/** * @param array * @param target * @param keyword */export const narrowdownArrayObject = <T>(array: T[], target: keyof T, keyword: T[keyof T]) => array.filter(object => object[target] === keyword)
/** * @param file */export const isExistFile = async (file: string) => { try { await Deno.stat(file) return true } catch (err) { if (err) return false }}
/** * @param file */export const isExistFileSync = (file: string) => { try { Deno.statSync(file) return true } catch (err) { if (err) return false }}
/** * @param rawdata * @param file */export const writeFile = async (rawdata: string, file: string) => { const encoder = new TextEncoder() const data = encoder.encode(rawdata) await Deno.writeFile(file, data)}
/** * @param rawdata * @param file */export const writeFileSync = (rawdata: string, file: string) => { const encoder = new TextEncoder() const data = encoder.encode(rawdata) Deno.writeFileSync(file, data)}
/** * @param file */export const readFile = async (file: string) => { const decoder = new TextDecoder('utf-8') const data = await Deno.readFile(file) return decoder.decode(data)}
/** * @param file */export const readFileSync = (file: string) => { const decoder = new TextDecoder('utf-8') const data = Deno.readFileSync(file) return decoder.decode(data)}
/** * @param date */export const readDate = (date: string) => { const getDate = date ? new Date(date) : new Date() const daysList: ('Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday')[] = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] return { year: getDate.getFullYear(), month: getDate.getMonth() + 1, date: getDate.getDate(), days: daysList[getDate.getDay()], hour: getDate.getHours(), minute: getDate.getMinutes(), second: getDate.getSeconds(), }}
/** * * @param num */export const zeroPadding = (num: number) => String(num).padStart(2, '0')
deno_utils

Version Info

Tagged at
3 years ago

External Dependencies

No external dependencies 🎉