|
42 | 42 | "description": "You can use `arr.at(-1)` if supported or `arr[arr.length - 1]` to get the last element of an array.", |
43 | 43 | "example": "const last = (arr) => arr.at(-1);\n// or in older environments\nconst lastLegacy = (arr) => arr[arr.length - 1]" |
44 | 44 | }, |
| 45 | + "snippet::array-shallow-equal": { |
| 46 | + "id": "snippet::array-shallow-equal", |
| 47 | + "type": "simple", |
| 48 | + "description": "You can compare the lengths and then use `Array.prototype.every` to check two arrays hold the same items in the same order.", |
| 49 | + "example": "const arraysEqual = (a, b) => a === b || (a.length === b.length && a.every((value, i) => value === b[i]))" |
| 50 | + }, |
45 | 51 | "snippet::array-slice-exclude-last-n": { |
46 | 52 | "id": "snippet::array-slice-exclude-last-n", |
47 | 53 | "type": "simple", |
|
72 | 78 | "description": "You can use `Promise.all` with `Array.prototype.map` to do an async action with an array of items.", |
73 | 79 | "example": "Promise.all(items.map(asyncFn))" |
74 | 80 | }, |
| 81 | + "snippet::async-each-series": { |
| 82 | + "id": "snippet::async-each-series", |
| 83 | + "type": "simple", |
| 84 | + "description": "You can use a `for await...of` loop to run an async function on each item one at a time, in order. Use `break` to stop early.", |
| 85 | + "example": "for await (const item of items) {\n await fn(item);\n}" |
| 86 | + }, |
75 | 87 | "snippet::async-function-constructor": { |
76 | 88 | "id": "snippet::async-function-constructor", |
77 | 89 | "type": "simple", |
78 | 90 | "description": "You can get the `AsyncFunction` using `async function`.", |
79 | 91 | "example": "const AsyncFunction = (async () => {}).constructor" |
80 | 92 | }, |
| 93 | + "snippet::async-pipe": { |
| 94 | + "id": "snippet::async-pipe", |
| 95 | + "type": "simple", |
| 96 | + "description": "You can use a `for...of` loop to pass a value through async functions one after another, awaiting each result.", |
| 97 | + "example": "const pipe = (...fns) => async (input) => {\n let value = input;\n for (const fn of fns) {\n value = await fn(value);\n }\n return value;\n};" |
| 98 | + }, |
81 | 99 | "snippet::bail": { |
82 | 100 | "id": "snippet::bail", |
83 | 101 | "type": "simple", |
|
324 | 342 | "description": "You can check if the current environment is SSH by checking if the `SSH_CONNECTION` environment variable is set.", |
325 | 343 | "example": "Boolean(process.env.SSH_CONNECTION)" |
326 | 344 | }, |
| 345 | + "snippet::is-integer-array": { |
| 346 | + "id": "snippet::is-integer-array", |
| 347 | + "type": "simple", |
| 348 | + "description": "You can use `Array.isArray` and `Number.isInteger` to check that a value is a non-empty array of integers. `findIndex` treats empty slots as `undefined`, so arrays with holes are rejected.", |
| 349 | + "example": "const isIntegerArray = (value) =>\n Array.isArray(value) &&\n value.length > 0 &&\n value.findIndex((v) => !Number.isInteger(v)) === -1" |
| 350 | + }, |
327 | 351 | "snippet::is-interactive": { |
328 | 352 | "id": "snippet::is-interactive", |
329 | 353 | "type": "simple", |
|
432 | 456 | "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.", |
433 | 457 | "example": "const isPrimitive = (value) => value === null || (typeof value !== \"function\" && typeof value !== \"object\");" |
434 | 458 | }, |
| 459 | + "snippet::is-promise": { |
| 460 | + "id": "snippet::is-promise", |
| 461 | + "type": "simple", |
| 462 | + "description": "You can use `instanceof Promise` to check for a promise. If you also need to accept other thenables, wrap the value with `Promise.resolve()` instead of checking it.", |
| 463 | + "example": "value instanceof Promise" |
| 464 | + }, |
435 | 465 | "snippet::is-redirect": { |
436 | 466 | "id": "snippet::is-redirect", |
437 | 467 | "type": "simple", |
|
450 | 480 | "description": "You can use `process.getuid?.()` to check if a user is a root user.", |
451 | 481 | "example": "const isRootUser = process.getuid?.() === 0" |
452 | 482 | }, |
| 483 | + "snippet::is-scoped": { |
| 484 | + "id": "snippet::is-scoped", |
| 485 | + "type": "simple", |
| 486 | + "description": "You can use a regular expression to check whether a string is a scoped npm package name.", |
| 487 | + "example": "const isScoped = (string) => /^@[a-z\\d][\\w-.]+\\/[a-z\\d][\\w-.]*$/i.test(string)" |
| 488 | + }, |
453 | 489 | "snippet::is-set": { |
454 | 490 | "id": "snippet::is-set", |
455 | 491 | "type": "simple", |
|
696 | 732 | "description": "You can use `/^#!(.+)/` regex.", |
697 | 733 | "example": "const shebangRegex = /^#!(.+)/;" |
698 | 734 | }, |
| 735 | + "snippet::shorten-home-path": { |
| 736 | + "id": "snippet::shorten-home-path", |
| 737 | + "type": "simple", |
| 738 | + "description": "You can use `os.homedir()` with `path.normalize` to replace the home directory at the start of a path with `~`.", |
| 739 | + "example": "import { homedir } from 'node:os'\nimport { normalize, sep } from 'node:path'\n\nconst home = homedir()\nconst shortenHomePath = (path) => {\n const normalized = normalize(path)\n return normalized === home || normalized.startsWith(home + sep) ? '~' + normalized.slice(home.length) : normalized\n}" |
| 740 | + }, |
699 | 741 | "snippet::split-lines": { |
700 | 742 | "id": "snippet::split-lines", |
701 | 743 | "type": "simple", |
|
714 | 756 | "description": "You can check if the first character of the string is the BOM and strip it using `String.prototype.slice` if it is.", |
715 | 757 | "example": "str.charCodeAt(0) === 0xFEFF ? str.slice(1) : str;" |
716 | 758 | }, |
| 759 | + "snippet::strip-bom-buffer": { |
| 760 | + "id": "snippet::strip-bom-buffer", |
| 761 | + "type": "simple", |
| 762 | + "description": "You can check the first three bytes for the UTF-8 byte order mark (`EF BB BF`) and remove them with `slice`.", |
| 763 | + "example": "const stripBomBuffer = (bytes) =>\n bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf ? bytes.slice(3) : bytes" |
| 764 | + }, |
| 765 | + "snippet::strip-surrounding-substring": { |
| 766 | + "id": "snippet::strip-surrounding-substring", |
| 767 | + "type": "simple", |
| 768 | + "description": "You can use `String.prototype.replace` with a RegExp anchored to the start and end of the string to remove a substring from both ends.", |
| 769 | + "example": "str.replace(/^foo|foo$/g, '')" |
| 770 | + }, |
717 | 771 | "snippet::title-case": { |
718 | 772 | "id": "snippet::title-case", |
719 | 773 | "type": "simple", |
|
789 | 843 | "moduleName": "array-differ", |
790 | 844 | "replacements": ["snippet::array-difference"] |
791 | 845 | }, |
| 846 | + "array-equal": { |
| 847 | + "type": "module", |
| 848 | + "moduleName": "array-equal", |
| 849 | + "replacements": ["snippet::array-shallow-equal"] |
| 850 | + }, |
| 851 | + "array-flatten": { |
| 852 | + "type": "module", |
| 853 | + "moduleName": "array-flatten", |
| 854 | + "replacements": ["snippet::array-flatten"] |
| 855 | + }, |
792 | 856 | "array-ify": { |
793 | 857 | "type": "module", |
794 | 858 | "moduleName": "array-ify", |
|
1214 | 1278 | "moduleName": "is-root", |
1215 | 1279 | "replacements": ["snippet::is-root-user"] |
1216 | 1280 | }, |
| 1281 | + "is-scoped": { |
| 1282 | + "type": "module", |
| 1283 | + "moduleName": "is-scoped", |
| 1284 | + "replacements": ["snippet::is-scoped"] |
| 1285 | + }, |
1217 | 1286 | "is-set": { |
1218 | 1287 | "type": "module", |
1219 | 1288 | "moduleName": "is-set", |
|
1489 | 1558 | "moduleName": "object.reduce", |
1490 | 1559 | "replacements": ["snippet::object-reduce"] |
1491 | 1560 | }, |
| 1561 | + "p-each-series": { |
| 1562 | + "type": "module", |
| 1563 | + "moduleName": "p-each-series", |
| 1564 | + "replacements": ["snippet::async-each-series"] |
| 1565 | + }, |
| 1566 | + "p-is-promise": { |
| 1567 | + "type": "module", |
| 1568 | + "moduleName": "p-is-promise", |
| 1569 | + "replacements": ["snippet::is-promise"] |
| 1570 | + }, |
| 1571 | + "p-pipe": { |
| 1572 | + "type": "module", |
| 1573 | + "moduleName": "p-pipe", |
| 1574 | + "replacements": ["snippet::async-pipe"] |
| 1575 | + }, |
1492 | 1576 | "path-key": { |
1493 | 1577 | "type": "module", |
1494 | 1578 | "moduleName": "path-key", |
|
1536 | 1620 | "moduleName": "repeat-element", |
1537 | 1621 | "replacements": ["snippet::array-filled-with"] |
1538 | 1622 | }, |
| 1623 | + "scoped-regex": { |
| 1624 | + "type": "module", |
| 1625 | + "moduleName": "scoped-regex", |
| 1626 | + "replacements": ["snippet::is-scoped"] |
| 1627 | + }, |
1539 | 1628 | "set-function-length": { |
1540 | 1629 | "type": "module", |
1541 | 1630 | "moduleName": "set-function-length", |
|
1571 | 1660 | "moduleName": "strip-bom", |
1572 | 1661 | "replacements": ["snippet::strip-bom"] |
1573 | 1662 | }, |
| 1663 | + "strip-bom-buf": { |
| 1664 | + "type": "module", |
| 1665 | + "moduleName": "strip-bom-buf", |
| 1666 | + "replacements": ["snippet::strip-bom-buffer"] |
| 1667 | + }, |
1574 | 1668 | "strip-bom-string": { |
1575 | 1669 | "type": "module", |
1576 | 1670 | "moduleName": "strip-bom-string", |
1577 | 1671 | "replacements": ["snippet::strip-bom"] |
1578 | 1672 | }, |
| 1673 | + "strip-outer": { |
| 1674 | + "type": "module", |
| 1675 | + "moduleName": "strip-outer", |
| 1676 | + "replacements": ["snippet::strip-surrounding-substring"] |
| 1677 | + }, |
| 1678 | + "tildify": { |
| 1679 | + "type": "module", |
| 1680 | + "moduleName": "tildify", |
| 1681 | + "replacements": ["snippet::shorten-home-path"] |
| 1682 | + }, |
1579 | 1683 | "titleize": { |
1580 | 1684 | "type": "module", |
1581 | 1685 | "moduleName": "titleize", |
|
1626 | 1730 | "moduleName": "validate.io-function", |
1627 | 1731 | "replacements": ["snippet::is-function"] |
1628 | 1732 | }, |
| 1733 | + "validate.io-integer-array": { |
| 1734 | + "type": "module", |
| 1735 | + "moduleName": "validate.io-integer-array", |
| 1736 | + "replacements": ["snippet::is-integer-array"] |
| 1737 | + }, |
| 1738 | + "validate.io-number": { |
| 1739 | + "type": "module", |
| 1740 | + "moduleName": "validate.io-number", |
| 1741 | + "replacements": ["snippet::is-number"] |
| 1742 | + }, |
1629 | 1743 | "year": { |
1630 | 1744 | "type": "module", |
1631 | 1745 | "moduleName": "year", |
|
0 commit comments