|
72 | 72 | "description": "You can use `Promise.all` with `Array.prototype.map` to do an async action with an array of items.", |
73 | 73 | "example": "Promise.all(items.map(asyncFn))" |
74 | 74 | }, |
| 75 | + "snippet::async-each-series": { |
| 76 | + "id": "snippet::async-each-series", |
| 77 | + "type": "simple", |
| 78 | + "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.", |
| 79 | + "example": "for await (const item of items) {\n await fn(item);\n}" |
| 80 | + }, |
75 | 81 | "snippet::async-function-constructor": { |
76 | 82 | "id": "snippet::async-function-constructor", |
77 | 83 | "type": "simple", |
78 | 84 | "description": "You can get the `AsyncFunction` using `async function`.", |
79 | 85 | "example": "const AsyncFunction = (async () => {}).constructor" |
80 | 86 | }, |
| 87 | + "snippet::async-pipe": { |
| 88 | + "id": "snippet::async-pipe", |
| 89 | + "type": "simple", |
| 90 | + "description": "You can use a `for...of` loop to pass a value through async functions one after another, awaiting each result.", |
| 91 | + "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};" |
| 92 | + }, |
81 | 93 | "snippet::bail": { |
82 | 94 | "id": "snippet::bail", |
83 | 95 | "type": "simple", |
|
324 | 336 | "description": "You can check if the current environment is SSH by checking if the `SSH_CONNECTION` environment variable is set.", |
325 | 337 | "example": "Boolean(process.env.SSH_CONNECTION)" |
326 | 338 | }, |
| 339 | + "snippet::is-integer-array": { |
| 340 | + "id": "snippet::is-integer-array", |
| 341 | + "type": "simple", |
| 342 | + "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.", |
| 343 | + "example": "const isIntegerArray = (value) =>\n Array.isArray(value) &&\n value.length > 0 &&\n value.findIndex((v) => !Number.isInteger(v)) === -1" |
| 344 | + }, |
327 | 345 | "snippet::is-interactive": { |
328 | 346 | "id": "snippet::is-interactive", |
329 | 347 | "type": "simple", |
|
432 | 450 | "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 | 451 | "example": "const isPrimitive = (value) => value === null || (typeof value !== \"function\" && typeof value !== \"object\");" |
434 | 452 | }, |
| 453 | + "snippet::is-promise": { |
| 454 | + "id": "snippet::is-promise", |
| 455 | + "type": "simple", |
| 456 | + "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.", |
| 457 | + "example": "value instanceof Promise" |
| 458 | + }, |
435 | 459 | "snippet::is-redirect": { |
436 | 460 | "id": "snippet::is-redirect", |
437 | 461 | "type": "simple", |
|
450 | 474 | "description": "You can use `process.getuid?.()` to check if a user is a root user.", |
451 | 475 | "example": "const isRootUser = process.getuid?.() === 0" |
452 | 476 | }, |
| 477 | + "snippet::is-scoped": { |
| 478 | + "id": "snippet::is-scoped", |
| 479 | + "type": "simple", |
| 480 | + "description": "You can use a regular expression to check whether a string is a scoped npm package name.", |
| 481 | + "example": "const isScoped = (string) => /^@[a-z\\d][\\w-.]+\\/[a-z\\d][\\w-.]*$/i.test(string)" |
| 482 | + }, |
453 | 483 | "snippet::is-set": { |
454 | 484 | "id": "snippet::is-set", |
455 | 485 | "type": "simple", |
|
696 | 726 | "description": "You can use `/^#!(.+)/` regex.", |
697 | 727 | "example": "const shebangRegex = /^#!(.+)/;" |
698 | 728 | }, |
| 729 | + "snippet::shorten-home-path": { |
| 730 | + "id": "snippet::shorten-home-path", |
| 731 | + "type": "simple", |
| 732 | + "description": "You can use `os.homedir()` with `path.normalize` to replace the home directory at the start of a path with `~`.", |
| 733 | + "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}" |
| 734 | + }, |
699 | 735 | "snippet::split-lines": { |
700 | 736 | "id": "snippet::split-lines", |
701 | 737 | "type": "simple", |
|
714 | 750 | "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 | 751 | "example": "str.charCodeAt(0) === 0xFEFF ? str.slice(1) : str;" |
716 | 752 | }, |
| 753 | + "snippet::strip-bom-buffer": { |
| 754 | + "id": "snippet::strip-bom-buffer", |
| 755 | + "type": "simple", |
| 756 | + "description": "You can check the first three bytes for the UTF-8 byte order mark (`EF BB BF`) and remove them with `slice`.", |
| 757 | + "example": "const stripBomBuffer = (bytes) =>\n bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf ? bytes.slice(3) : bytes" |
| 758 | + }, |
717 | 759 | "snippet::strip-surrounding-substring": { |
718 | 760 | "id": "snippet::strip-surrounding-substring", |
719 | 761 | "type": "simple", |
|
789 | 831 | "moduleName": "array-differ", |
790 | 832 | "replacements": ["snippet::array-difference"] |
791 | 833 | }, |
| 834 | + "array-flatten": { |
| 835 | + "type": "module", |
| 836 | + "moduleName": "array-flatten", |
| 837 | + "replacements": ["snippet::array-flatten"] |
| 838 | + }, |
792 | 839 | "array-ify": { |
793 | 840 | "type": "module", |
794 | 841 | "moduleName": "array-ify", |
|
1214 | 1261 | "moduleName": "is-root", |
1215 | 1262 | "replacements": ["snippet::is-root-user"] |
1216 | 1263 | }, |
| 1264 | + "is-scoped": { |
| 1265 | + "type": "module", |
| 1266 | + "moduleName": "is-scoped", |
| 1267 | + "replacements": ["snippet::is-scoped"] |
| 1268 | + }, |
1217 | 1269 | "is-set": { |
1218 | 1270 | "type": "module", |
1219 | 1271 | "moduleName": "is-set", |
|
1489 | 1541 | "moduleName": "object.reduce", |
1490 | 1542 | "replacements": ["snippet::object-reduce"] |
1491 | 1543 | }, |
| 1544 | + "p-each-series": { |
| 1545 | + "type": "module", |
| 1546 | + "moduleName": "p-each-series", |
| 1547 | + "replacements": ["snippet::async-each-series"] |
| 1548 | + }, |
| 1549 | + "p-is-promise": { |
| 1550 | + "type": "module", |
| 1551 | + "moduleName": "p-is-promise", |
| 1552 | + "replacements": ["snippet::is-promise"] |
| 1553 | + }, |
| 1554 | + "p-pipe": { |
| 1555 | + "type": "module", |
| 1556 | + "moduleName": "p-pipe", |
| 1557 | + "replacements": ["snippet::async-pipe"] |
| 1558 | + }, |
1492 | 1559 | "path-key": { |
1493 | 1560 | "type": "module", |
1494 | 1561 | "moduleName": "path-key", |
|
1536 | 1603 | "moduleName": "repeat-element", |
1537 | 1604 | "replacements": ["snippet::array-filled-with"] |
1538 | 1605 | }, |
| 1606 | + "scoped-regex": { |
| 1607 | + "type": "module", |
| 1608 | + "moduleName": "scoped-regex", |
| 1609 | + "replacements": ["snippet::is-scoped"] |
| 1610 | + }, |
1539 | 1611 | "set-function-length": { |
1540 | 1612 | "type": "module", |
1541 | 1613 | "moduleName": "set-function-length", |
|
1571 | 1643 | "moduleName": "strip-bom", |
1572 | 1644 | "replacements": ["snippet::strip-bom"] |
1573 | 1645 | }, |
| 1646 | + "strip-bom-buf": { |
| 1647 | + "type": "module", |
| 1648 | + "moduleName": "strip-bom-buf", |
| 1649 | + "replacements": ["snippet::strip-bom-buffer"] |
| 1650 | + }, |
1574 | 1651 | "strip-bom-string": { |
1575 | 1652 | "type": "module", |
1576 | 1653 | "moduleName": "strip-bom-string", |
|
1581 | 1658 | "moduleName": "strip-outer", |
1582 | 1659 | "replacements": ["snippet::strip-surrounding-substring"] |
1583 | 1660 | }, |
| 1661 | + "tildify": { |
| 1662 | + "type": "module", |
| 1663 | + "moduleName": "tildify", |
| 1664 | + "replacements": ["snippet::shorten-home-path"] |
| 1665 | + }, |
1584 | 1666 | "toarray": { |
1585 | 1667 | "type": "module", |
1586 | 1668 | "moduleName": "toarray", |
|
1626 | 1708 | "moduleName": "validate.io-function", |
1627 | 1709 | "replacements": ["snippet::is-function"] |
1628 | 1710 | }, |
| 1711 | + "validate.io-integer-array": { |
| 1712 | + "type": "module", |
| 1713 | + "moduleName": "validate.io-integer-array", |
| 1714 | + "replacements": ["snippet::is-integer-array"] |
| 1715 | + }, |
| 1716 | + "validate.io-number": { |
| 1717 | + "type": "module", |
| 1718 | + "moduleName": "validate.io-number", |
| 1719 | + "replacements": ["snippet::is-number"] |
| 1720 | + }, |
1629 | 1721 | "year": { |
1630 | 1722 | "type": "module", |
1631 | 1723 | "moduleName": "year", |
|
0 commit comments