-
Notifications
You must be signed in to change notification settings - Fork 0
/
common-js-snippets.code-snippets
254 lines (254 loc) · 9.43 KB
/
common-js-snippets.code-snippets
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
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and description.
"Show console logs in development mode": {
"prefix": "sidlog",
"body": [
" if (process.env.NODE_ENV === 'development') {",
" console.log($TM_SELECTED_TEXT, '$TM_FILENAME', ':$TM_LINE_NUMBER');",
" }"
],
"description": "Show console logs in development mode"
},
"Show console logs in development mode With chalk": {
"prefix": "sidcha",
"body": [
" if (process.env.NODE_ENV === 'development') {",
" console.log(chalk.blue($TM_SELECTED_TEXT, '$TM_FILENAME', ':$TM_LINE_NUMBER'));",
" }"
],
"description": "Show console logs in development mode With chalk"
},
"Console log": {
"prefix": "log",
"body": [
" console.log($TM_SELECTED_TEXT, '$TM_FILENAME', ':$TM_LINE_NUMBER');"
],
"description": "Console log"
},
"Show in development mode": {
"prefix": "sid",
"body": [
" if (process.env.NODE_ENV === 'development') {",
" $TM_SELECTED_TEXT",
"}"
],
"description": "Show in development mode"
},
"useState": {
"prefix": "useState",
"body": [
"const[$TM_SELECTED_TEXT, set${TM_SELECTED_TEXT/^(.)/${1:/upcase}/}] = useState('');"
],
"description": "useState"
},
"React Fragment Component": {
"prefix": "rfc",
"body": ["<>", " $TM_SELECTED_TEXT", "</>"],
"description": "React Fragment Component"
},
"Error Location": {
"prefix": "errloc",
"body": ["err.errLocation = '$TM_FILENAME:$TM_LINE_NUMBER';"],
"description": "Error Location"
},
"Error Location Variable": {
"prefix": "errLOC",
"body": ["const errLocation = '$TM_FILENAME:$TM_LINE_NUMBER';"],
"description": "Error Location Variable"
},
"Error Body Full": {
"prefix": "errbd",
"body": [
"const message = '';",
"const errLocation = '$TM_FILENAME:$TM_LINE_NUMBER';",
"const errBody = { message, errLocation };"
],
"description": "Error Body Full"
},
"React Functional Component": {
"prefix": "rfccc",
"body": [
"/* Classes */",
"import classes from './${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}.module.css';",
"",
"/* Main Component */",
"const ${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g} = (props) => {",
" return <div className={classes.main}>${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}</div>;",
"};",
"",
"/* Export Main Component */",
"export default ${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g};",
""
],
"description": "React Functional Component"
},
"Pretty Log": {
"prefix": "plog",
"body": [
"prettyLog('error', $TM_SELECTED_TEXT, ' $TM_FILENAME:$TM_LINE_NUMBER');"
],
"description": "Pretty Log"
},
"Pretty Log File Name": {
"prefix": "plf",
"body": [
"fileNameLog($TM_SELECTED_TEXT, ' $TM_FILENAME:$TM_LINE_NUMBER');"
],
"description": "Pretty Log File Name"
},
"Pretty Log Informative": {
"prefix": "plf",
"body": [
"informativeLog($TM_SELECTED_TEXT, ' $TM_FILENAME:$TM_LINE_NUMBER');"
],
"description": "Pretty Log Informative"
},
"React Props": {
"prefix": "=P",
"body": ["$TM_SELECTED_TEXT={$TM_SELECTED_TEXT}"],
"description": "React Props"
},
"NextJs Export Default": {
"prefix": "nfc",
"body": [
"export default function ${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}() {",
"",
"}"
],
"description": "NextJs Export Default"
},
"Element Creating Skeleton": {
"prefix": "ecs",
"body": [
"import { useId } from \"react\";",
"",
"import classNames from \"classnames\";",
"import { PropTypes } from \"prop-types\";",
"",
"const COMPONENT_NAME = \"${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}\";",
"const ${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g} = (props) => {",
" const id = useId() + '-' + COMPONENT_NAME;",
"",
" const { className = '', ...rest } = props;",
"",
" return (",
" <div id={id} {...rest} className={classNames(className, COMPONENT_NAME)}>",
" {COMPONENT_NAME}",
" </div>",
" );",
"};",
"",
"${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}.propTypes = {",
" className: PropTypes.string,",
"};",
"",
"${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}.displayName = COMPONENT_NAME;",
"",
"export { ${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g} };",
""
],
"description": "Element Creating Skeleton"
},
"Old Element Creating Skeleton": {
"prefix": "oEcs",
"body": [
"import React from \"react\";",
"",
"import classNames from \"classnames\";",
"import { PropTypes } from \"prop-types\";",
"",
"const COMPONENT_NAME = \"${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}\";",
"const ${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g} = (props) => {",
" const id = Math.floor(Math.random() * 9999) + 1 + \"-\" + COMPONENT_NAME;",
"",
" const { className = '', ...rest } = props;",
"",
" return (",
" <div id={id} {...rest} className={classNames(className, COMPONENT_NAME)}>",
" {COMPONENT_NAME}",
" </div>",
" );",
"};",
"",
"${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}.propTypes = {",
" className: PropTypes.string,",
"};",
"",
"${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}.displayName = COMPONENT_NAME;",
"",
"export { ${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g} };",
""
],
"description": "Old Element Creating Skeleton (kebab-case to PascalCase)"
},
"Nextjs Typescript Element Creating Skeleton": {
"prefix": "necs",
"body": [
"import { useId } from \"react\";",
"import classNames from \"classnames\";",
"",
"const COMPONENT_NAME = \"${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}\";",
"const ${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g} = (props: { className?: string }) => {",
" const id = useId() + \"-\" + COMPONENT_NAME;",
"",
" const { className, ...rest } = props;",
"",
" return (",
" <div id={id} {...rest} className={classNames(className, COMPONENT_NAME)}>",
" {COMPONENT_NAME}",
" </div>",
" );",
"};",
"",
"${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}.displayName = COMPONENT_NAME;",
"",
"export { ${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g} };",
""
],
"description": "Element Creating Skeleton"
},
"Query Page Creating Skeleton": {
"prefix": "qpcs",
"body": [
"import classNames from 'classnames';",
"import { PropTypes } from 'prop-types';",
"import { useRouter } from 'next/router';",
"import { serverSideTranslations } from 'next-i18next/serverSideTranslations';",
"import { useTranslation } from 'next-i18next';",
"",
"export default function ${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}(props) {",
" const router = useRouter();",
" const { searchFor } = router.query;",
" return (",
" <>",
" <HeadSeo",
" title={t('Main.Title')}",
" description={`Your description goes here on every page. ",
" Keep character count between 140 to 160 characters`}",
" canonicalUrl={siteMetadata.siteUrl}",
" ogTwitterImage={siteMetadata.siteLogoSquare}",
" ogType={'website'}",
" />",
" <div className={classNames(props.className, '${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}')}>",
" Are you looking for {searchFor}?",
" </div>",
" </>",
" );",
"}",
"",
"${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}.propTypes = {",
" className: PropTypes.string,",
"};",
"",
"${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}.displayName = '${TM_FILENAME_BASE/^([a-z])|([a-z]*)[-@_.*0-9]+([a-z]*)/${1:/capitalize}${2}${3:/capitalize}/g}';",
"",
"export const getServerSideProps = async ({ locale }) => ({",
" props: {",
" ...(await serverSideTranslations(locale, ['common'])),",
" },",
"});",
""
],
"description": "Query Page Creating Skeleton"
}
}