/
javascript.json
254 lines (248 loc) · 8.19 KB
/
javascript.json
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
{
// 用户片段文档:https://code.visualstudio.com/docs/editor/userdefinedsnippets
// 红色警戒示例注释
"Print to js api": {
"prefix": "hongsejingjie",
"body": [
"/***************************************************************************************************",
" * AircraftClass :: $0 *",
" * @Description: $0 *",
" * @Description: $0 *",
" * @Description: $0 *",
" * *",
" * INPUT:$0 *",
" * *",
" * OUTPUT:$0 *",
" * *",
" * WARNINGS:$0 *",
" * HISTORY: *",
" * @MethodAuthor: HeLihui *",
" * @Date: ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_HOUR} *",
"*==================================================================================================*/"
]
},
// ********** console打印片段 **********
"Print to consoleLog": {
"prefix": "log",
"body": ["console.log('$1');", "$2"],
"description": "console.log快捷键"
},
// ********** 页面顶部说明注释片段 **********
"Print to topNote": {
"prefix": "topNote",
"body": [
"/**",
" * @Copyright(c) 2022 rights reserved",
" * @Description: $0",
" * @Author: your name",
" * @Date: $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE",
" * @LastEditTime: ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_DAY_NAME} ${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}",
" * @LastEditors: $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE $CURRENT_DAY_NAME $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
" */"
],
"description": "页面顶部开头说明注释模板"
},
// ********** 方法注释片段 **********
"Print to method": {
"prefix": "noteMethod",
"body": [
"/**",
" * @description:$0",
" * @functionAuthor:$1",
" * @param:{$2} $3 $4",
" * @return:{$5} $6",
" */"
],
"description": "方法注释模板"
},
// ********** 方法注释片段(中文) **********
"Print to methodChinese": {
"prefix": "noteMethodChinese",
"body": [
"/**",
" * @描述:$0",
" * @方法作者:$1",
" * @参数:{$2} $3 $4",
" * @返回:{$5} $6",
" */"
],
"description": "方法注释模板中文版"
},
// ********** 类注释片段 **********
"Print to class": {
"prefix": "noteClass",
"body": [
"/**",
" * @description:$0",
" * @classAuthor:$1",
" * @param:{$2} $3 $4",
" * @return:{$5} $6",
" */"
],
"description": "类注释模板"
},
// ********** 类注释片段(中文) **********
"Print to classChinese": {
"prefix": "noteClassChinese",
"body": [
"/**",
" * @描述:$0",
" * @类作者:$1",
" * @参数:{$2} $3 $4",
" * @返回:{$5} $6",
" */"
],
"description": "类注释模板中文版"
},
// ********** 框架提示片段 **********
"success msg": {
"prefix": "success",
"body": [
"this.\\$message.success($1)",
],
"description": "成功提示"
},
"info msg": {
"prefix": "info",
"body": [
"this.\\$message.info($1)",
],
"description": "提示信息"
},
"error msg": {
"prefix": "error",
"body": [
"this.\\$message.error('$1')",
],
"description": "错误信息"
},
// ********** JS常用代码片段 **********
// 1.合并参数
"js1": {
"prefix": "hbcs",
"body": [
"const arrayConcat = (arr, ...args) => arr.concat(...args);",
"// arrayConcat([1], 2, [3], [[4]]) -> [1,2,3,[4]]",
"$1"
],
"description": "合并参数"
},
// 2.取数组不同项
"js2": {
"prefix": "qbtx",
"body": [
"const difference = (a, b) => { const s = new Set(b); return a.filter(x => !s.has(x)); };",
"// difference([1,2,3], [1,2]) -> [3]",
"$1"
],
"description": "取数组不同项"
},
// 3.取数组相同项
"js3": {
"prefix": "qtx",
"body": [
"const intersection = (a, b) => { const s = new Set(b); return a.filter(x => s.has(x)); };",
"// intersection([1,2,3], [4,3,2]) -> [2,3]",
"$1"
],
"description": "取数组相同项"
},
// 4.合并数组去重
"js4": {
"prefix": "hbqc",
"body": [
"const union = (a, b) => Array.from(new Set([...a, ...b]));",
"// union([1,2,3], [4,3,2]) -> [1,2,3,4]",
"$1"
],
"description": "合并数组去重"
},
// 5.数组取平均值
"js5": {
"prefix": "qpjz",
"body": [
"const average = arr => arr.reduce((acc, val) => acc + val, 0) / arr.length;",
"// average([1,2,3]) -> 2",
"$1"
],
"description": "数组取平均值"
},
// 6.过滤掉假值
"js6": {
"prefix": "gljz",
"body": [
"const compact = (arr) => arr.filter(v => v);",
"// compact([0, 1, false, 2, '', 3, 'a', 'e'*23, NaN, 's', 34]) -> [ 1, 2, 3, 'a', 's', 34 ]",
"$1"
],
"description": "过滤掉假值(false, null, 0, '', undefined 和 NaN)"
},
// 7.过滤掉数组中重复的值
"js7": {
"prefix": "glcfz",
"body": [
"const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));",
// filterNonUnique([1,2,2,3,4,4,5]) -> [1,3,5]",
"$1"
],
"description": "过滤掉数组中重复的值"
},
// 8.计算数组中重复值出现的次数
"js8": {
"prefix": "jscfz",
"body": [
"const countOccurrences = (arr, value) => arr.reduce((a, v) => v === value ? a + 1 : a + 0, 0);",
"// countOccurrences([1,1,2,1,2,3], 1) -> 3",
"$1"
],
"description": "计算数组中重复值出现的次数"
},
// 9.滚动至顶部
"scroll to top": {
"prefix": "gotop",
"body": [
"const scrollToTop = _ => {",
" const c = document.documentElement.scrollTop || document.body.scrollTop;",
" if (c > 0) {",
" window.requestAnimationFrame(scrollToTop);",
" window.scrollTo(0, c - c / 8);",
" }",
"};",
"// scrollToTop()"
],
"description": "滚动至顶部"
},
// 10.获取两个日期间的差距
"Get days difference between dates": {
"prefix": "datecj",
"body": [
"const getDaysDiffBetweenDates = (dateInitial, dateFinal) => (dateFinal - dateInitial) / (1000 * 3600 * 24);",
"// getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')) -> 9",
"$1"
],
"description": "获取两个日期间的差距"
},
// 11.指定范围内的随机整数
"Random integer in range": {
"prefix": "sjzs",
"body": [
"const randomIntegerInRange = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;",
"// randomIntegerInRange(0, 5) -> 2",
"$1"
],
"description": "指定范围内的随机整数"
},
// 12.URL参数
"URL parameters": {
"prefix": "urlcs",
"body": [
"const getUrlParameters = url =>",
" url.match(/([^?=&]+)(=([^&]*))/g).reduce(",
" (a, v) => (a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1), a), {}",
");",
"// getUrlParameters('http://url.com/page?name=Adam&surname=Smith') -> {name: 'Adam', surname: 'Smith'}",
"$1"
],
"description": "URL参数"
}
}