|
3 | 3 | "snippet::array-coerce": { |
4 | 4 | "id": "snippet::array-coerce", |
5 | 5 | "type": "simple", |
6 | | - "description": "You can use a combination of a ternary operator and Array.isArray to make sure a value, undefined, null or an array is always returned as an array.", |
| 6 | + "description": "You can use a combination of a ternary operator and `Array.isArray` to make sure a value, `undefined`, `null` or an array is always returned as an array.", |
7 | 7 | "example": "(arr == null ? [] : Array.isArray(arr) ? arr : [arr])" |
8 | 8 | }, |
9 | 9 | "snippet::array-difference": { |
10 | 10 | "id": "snippet::array-difference", |
11 | 11 | "type": "simple", |
12 | | - "description": "You can use a combination of filter and includes to calculate the difference between two arrays.", |
| 12 | + "description": "You can use a combination of `filter` and `includes` to calculate the difference between two arrays.", |
13 | 13 | "example": "const difference = (a, b) => a.filter((item) => !b.includes(item))" |
14 | 14 | }, |
15 | 15 | "snippet::array-from-count": { |
|
33 | 33 | "snippet::array-union": { |
34 | 34 | "id": "snippet::array-union", |
35 | 35 | "type": "simple", |
36 | | - "description": "You can use a combination of the spread operator and Set to create a union of two arrays.", |
| 36 | + "description": "You can use a combination of the spread operator and `Set` to create a union of two arrays.", |
37 | 37 | "example": "const union = (a, b) => [...new Set([...a, ...b])]" |
38 | 38 | }, |
39 | 39 | "snippet::array-unique": { |
40 | 40 | "id": "snippet::array-unique", |
41 | 41 | "type": "simple", |
42 | | - "description": "You can convert to and from a Set to remove duplicates from an array.", |
| 42 | + "description": "You can convert to and from a `Set` to remove duplicates from an array.", |
43 | 43 | "example": "const unique = (arr) => [...new Set(arr)]" |
44 | 44 | }, |
45 | 45 | "snippet::async-function-constructor": { |
|
57 | 57 | "snippet::call-bind": { |
58 | 58 | "id": "snippet::call-bind", |
59 | 59 | "type": "simple", |
60 | | - "description": "Every modern runtime provides a way to bind to the call method of a function.", |
| 60 | + "description": "Every modern runtime provides a way to bind to the `call` method of a function.", |
61 | 61 | "example": "const fnBound = Function.call.bind(fn)" |
62 | 62 | }, |
63 | 63 | "snippet::char-last": { |
|
75 | 75 | "snippet::get-iterator": { |
76 | 76 | "id": "snippet::get-iterator", |
77 | 77 | "type": "simple", |
78 | | - "description": "Every modern runtime provides a way to get the iterator function through the Symbol.iterator symbol.", |
| 78 | + "description": "Every modern runtime provides a way to get the iterator function through the `Symbol.iterator` symbol.", |
79 | 79 | "example": "const iterator = obj[Symbol.iterator]?.()" |
80 | 80 | }, |
81 | 81 | "snippet::has-argv": { |
82 | 82 | "id": "snippet::has-argv", |
83 | 83 | "type": "simple", |
84 | | - "description": "You can use the includes method on the process.argv array to check if a flag is present.", |
| 84 | + "description": "You can use the `includes` method on the `process.argv` array to check if a flag is present.", |
85 | 85 | "example": "process.argv.includes('--flag')" |
86 | 86 | }, |
87 | 87 | "snippet::is-arguments": { |
|
93 | 93 | "snippet::is-arraybuffer": { |
94 | 94 | "id": "snippet::is-arraybuffer", |
95 | 95 | "type": "simple", |
96 | | - "description": "You can use `instanceof ArrayBuffer`, or if cross-realm, use Object.prototype.toString.call(obj) === \"[object ArrayBuffer]\"", |
| 96 | + "description": "You can use `instanceof ArrayBuffer`, or if cross-realm, use `Object.prototype.toString.call(obj) === \"[object ArrayBuffer]\"`", |
97 | 97 | "example": "const isArrayBuffer = obj instanceof ArrayBuffer;\n// for cross-realm\nconst isArrayBufferCrossRealm = Object.prototype.toString.call(obj) === \"[object ArrayBuffer]\"" |
98 | 98 | }, |
99 | 99 | "snippet::is-async-function": { |
|
111 | 111 | "snippet::is-boolean": { |
112 | 112 | "id": "snippet::is-boolean", |
113 | 113 | "type": "simple", |
114 | | - "description": "You can use typeof to check if a value is a boolean primitive, and Object.prototype.toString.call to check if it's a Boolean object.", |
| 114 | + "description": "You can use `typeof` to check if a value is a boolean primitive, and `Object.prototype.toString.call` to check if it's a `Boolean` object.", |
115 | 115 | "example": "Object.prototype.toString.call(v) === \"[object Boolean]\"" |
116 | 116 | }, |
117 | 117 | "snippet::is-ci": { |
118 | 118 | "id": "snippet::is-ci", |
119 | 119 | "type": "simple", |
120 | | - "description": "Every major CI provider sets a CI environment variable that you can use to detect if you're running in a CI environment.", |
| 120 | + "description": "Every major CI provider sets a `CI` environment variable that you can use to detect if you're running in a CI environment.", |
121 | 121 | "example": "Boolean(process.env.CI)" |
122 | 122 | }, |
123 | 123 | "snippet::is-date": { |
124 | 124 | "id": "snippet::is-date", |
125 | 125 | "type": "simple", |
126 | | - "description": "You can use `instanceof Date`, or if cross-realm, use Object.prototype.toString.call(v) === \"[object Date]\"", |
| 126 | + "description": "You can use `instanceof Date`, or if cross-realm, use `Object.prototype.toString.call(v) === \"[object Date]\"`", |
127 | 127 | "example": "const isDate = v instanceof Date;\n// for cross-realm\nconst isDateCrossRealm = Object.prototype.toString.call(v) === \"[object Date]\"" |
128 | 128 | }, |
129 | 129 | "snippet::is-even": { |
|
159 | 159 | "snippet::is-npm": { |
160 | 160 | "id": "snippet::is-npm", |
161 | 161 | "type": "simple", |
162 | | - "description": "If the current environment is npm the `npm_config_user_agent` environment variable will be set and start with \"npm\".", |
| 162 | + "description": "If the current environment is npm the `npm_config_user_agent` environment variable will be set and start with `\"npm\"`.", |
163 | 163 | "example": "const isNpm = process.env.npm_config_user_agent?.startsWith(\"npm\")" |
164 | 164 | }, |
165 | 165 | "snippet::is-object": { |
|
183 | 183 | "snippet::is-primitve": { |
184 | 184 | "id": "snippet::is-primitve", |
185 | 185 | "type": "simple", |
186 | | - "description": "You can check `typeof` of a value to determine if it's a primitive. Note that `typeof null` is \"object\" so you need to check for null separately.", |
| 186 | + "description": "You can check `typeof` of a value to determine if it's a primitive. Note that `typeof null` is `\"object\"` so you need to check for `null` separately.", |
187 | 187 | "example": "const isPrimitive = (value) => value === null || (typeof value !== \"function\" && typeof value !== \"object\");" |
188 | 188 | }, |
189 | 189 | "snippet::is-regexp": { |
|
231 | 231 | "snippet::json-file": { |
232 | 232 | "id": "snippet::json-file", |
233 | 233 | "type": "simple", |
234 | | - "description": "You can use `JSON` and 'node:fs' to read and write json file.", |
| 234 | + "description": "You can use `JSON` and `node:fs` to read and write JSON files.", |
235 | 235 | "example": "import * as fs from 'node:fs/promises'\nfs.readFile(file, 'utf8').then(JSON.parse)\nfs.writeFile(file, JSON.stringify(data, null, 2) + '\\n')" |
236 | 236 | }, |
237 | 237 | "snippet::math-random": { |
|
0 commit comments