{"_id":"@beppobert/ts-utils","_rev":"1-09a994c8d0e3f263efc9db6af7a268c6","name":"@beppobert/ts-utils","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@beppobert/ts-utils","version":"0.0.1","description":"A collection of TypeScript utilities. I will never want to re-write these again.","author":{"name":"Philipp Dehler"},"repository":{"type":"git","url":"git+https://github.com/Beppobert/ts-utils.git"},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./dist/src/index.js","require":"./dist/src/index.js"}},"type":"module","main":"./dist/src/main.js","types":"./dist/src/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"license":"ISC","devDependencies":{"typescript":"^5.3.3"},"_id":"@beppobert/ts-utils@0.0.1","gitHead":"e4515c07969ce850b4809c0322a5444e7d54bbd0","bugs":{"url":"https://github.com/Beppobert/ts-utils/issues"},"homepage":"https://github.com/Beppobert/ts-utils#readme","_nodeVersion":"18.14.0","_npmVersion":"9.8.0","dist":{"integrity":"sha512-whwiDnRr7Tq4sdfIML/scqGJnvtqXeIy6fD0nVu7UM690pCdbWu/+aG3w35cZcYAwmLSnH8+FvMkFvv25xI0pQ==","shasum":"0459e3c96e8740d00257c9295640e8fcdca15451","tarball":"https://registry.npmjs.org/@beppobert/ts-utils/-/ts-utils-0.0.1.tgz","fileCount":59,"unpackedSize":17539,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC0Nn5cU679WOhbeLMC2W+mLJLW2gTNCpsf4vuN7NRKjgIhAL0nxb6jXkie2PZJqrRZBZ9YXFtzZBzxNnug3EfBPYoO"}]},"_npmUser":{"name":"beppobert","email":"philipp.dehler@googlemail.com"},"directories":{},"maintainers":[{"name":"beppobert","email":"philipp.dehler@googlemail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-utils_0.0.1_1707144356646_0.1468982321166581"},"_hasShrinkwrap":false},"0.0.2":{"name":"@beppobert/ts-utils","version":"0.0.2","description":"A collection of TypeScript utilities. I will never want to re-write these again.","author":{"name":"Philipp Dehler"},"repository":{"type":"git","url":"git+https://github.com/Beppobert/ts-utils.git"},"exports":{".":{"types":"./dist/src/index.d.ts","import":"./dist/src/index.js","require":"./dist/src/index.js"}},"type":"module","main":"./dist/src/main.js","types":"./dist/src/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"license":"ISC","devDependencies":{"typescript":"^5.3.3"},"keywords":["typescript","utils","type","guard","Object.keys"],"_id":"@beppobert/ts-utils@0.0.2","gitHead":"bc16548da496eb56682969e1e39c120e47e8390d","bugs":{"url":"https://github.com/Beppobert/ts-utils/issues"},"homepage":"https://github.com/Beppobert/ts-utils#readme","_nodeVersion":"18.14.0","_npmVersion":"9.8.0","dist":{"integrity":"sha512-NhZIar8nKT+0NgUqG0BZkh2KV7cMbpwC5rdEg/hTBLaUUkcJVkxK/gF00EP7piC/Sf14pxT1xpGEzlHC3yLJ+A==","shasum":"c9835129a13607a5e501573ca6bc39a734f9353b","tarball":"https://registry.npmjs.org/@beppobert/ts-utils/-/ts-utils-0.0.2.tgz","fileCount":59,"unpackedSize":17634,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDZpBlHTWEltbIzIOwxshcx6FhSyrdXYfG5OhTv2eQckQIgMsDfTuv3sWviYfWgXM70lyafWEZPOoPSeLQtLFlPilo="}]},"_npmUser":{"name":"beppobert","email":"philipp.dehler@googlemail.com"},"directories":{},"maintainers":[{"name":"beppobert","email":"philipp.dehler@googlemail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-utils_0.0.2_1707144458133_0.8870266305739638"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-05T14:45:56.550Z","0.0.1":"2024-02-05T14:45:56.808Z","modified":"2024-02-05T14:47:38.438Z","0.0.2":"2024-02-05T14:47:38.281Z"},"maintainers":[{"name":"beppobert","email":"philipp.dehler@googlemail.com"}],"description":"A collection of TypeScript utilities. I will never want to re-write these again.","homepage":"https://github.com/Beppobert/ts-utils#readme","repository":{"type":"git","url":"git+https://github.com/Beppobert/ts-utils.git"},"author":{"name":"Philipp Dehler"},"bugs":{"url":"https://github.com/Beppobert/ts-utils/issues"},"license":"ISC","readme":"# ts-utils\n\nA collection of TypeScript utilities. I will never want to re-write these again.\n\n## Installation\n\n```bash\nnpm install @beppobert/ts-utils\n```\n\n## Typeguards\n\n### `isDefined`\n\n```typescript\nimport { isDefined } from \"@beppobert/ts-utils\";\n\nconst value: string | undefined = \"Hello, World!\";\nif (isDefined(value)) {\n  // value is string here\n  console.log(value);\n} else {\n  // value is undefined here\n  console.log(\"value is undefined\");\n}\n\n[1, 2, null, undefined].filter(isNil); // number[]\n```\n\n### `isNull`\n\n```typescript\nimport { isNull } from \"@beppobert/ts-utils\";\n\nconst value: string | null = \"Hello, World!\";\n\nif (isNull(value)) {\n  // value is null here\n  console.log(\"value is null\");\n} else {\n  // value is string here\n  console.log(value);\n}\n```\n\n### `isUndefined`\n\n```typescript\nimport { isUndefined } from \"@beppobert/ts-utils\";\n\ndeclare const value: string | undefined;\n\nif (isUndefined(value)) {\n  // value is undefined here\n  console.log(\"value is undefined\");\n} else {\n  // value is string here\n  console.log(value);\n}\n```\n\n### `isNil`\n\n```typescript\nimport { isNil } from \"@beppobert/ts-utils\";\n\ndeclare const value: string | null | undefined;\nif (isNil(value)) {\n  // value is null or undefined here\n  console.log(\"value is null or undefined\");\n} else {\n  // value is string here\n  console.log(value);\n}\n\n[1, 2, null, undefined].filter(isNil); // (null| undefined)[]\n```\n\n### `isTruthy`\n\n```typescript\nimport { isTruthy } from \"@beppobert/ts-utils\";\n\ndeclare const value: string | null | undefined;\n\nif (isTruthy(value)) {\n  // value is string here\n  console.log(value);\n} else {\n  // value is null or undefined here\n  console.log(\"value is null or undefined\");\n}\n```\n\n### `isFalsy`\n\n```typescript\nimport { isFalsy } from \"@beppobert/ts-utils\";\n\ndeclare const value: string | null | undefined;\n\nif (isFalsy(value)) {\n  // value is null or undefined or \"\" here\n  console.log(\"value is null or undefined\");\n} else {\n  // value is string here\n  console.log(value);\n}\n```\n\n### `isKeyOf`\n\n```typescript\nimport { isKeyOf } from \"@beppobert/ts-utils\";\n\ntype MyType = {\n  a: string;\n  b: number;\n  c: boolean;\n};\n\ndeclare const obj: MyType;\n\nif (isKeyOf(obj, \"a\")) {\n  // obj.a is string here\n  console.log(obj.a);\n} else if (isKeyOf(obj, \"d\")) {\n  const v: unknown = obj.d; // no error; obj.d is unknown\n}\n```\n\n### `isTypeOf`\n\n```typescript\nimport { isTypeOf } from \"@beppobert/ts-utils\";\n\ndeclare const value: unknown;\n\nif (isTypeOf(value, \"string\")) {\n  // value is string here\n  console.log(value);\n} else if (isTypeOf(value, \"number\")) {\n  // value is number here\n  console.log(value);\n} else if (isTypeOf(value, \"boolean\")) {\n  // value is boolean here\n  console.log(value);\n} else if (isTypeOf(value, \"object\", \"undefined\")) {\n  // value is object/unknown here\n  console.log(value);\n}\n```\n\n### `hasPath`\n\n```typescript\nimport { hasPath } from \"@beppobert/ts-utils\";\n\ndeclare const obj: { a: { b: { c: string } } };\n\nif (hasPath(obj, \"a\", \"b\", \"c\")) {\n  // obj.a.b.c is string here\n  console.log(obj.a.b.c);\n}\nif (hasPath(obj, \"a.b.d\")) {\n  // obj.a.b.d is unknown here\n  console.log(obj.a.b.d);\n}\n```\n\n## Flow\n\n### `assertNever`\n\n```typescript\nimport { assertNever } from \"@beppobert/ts-utils\";\n\ntype MyType = \"a\" | \"b\" | \"c\";\n\ndeclare const value: MyType;\n\nswitch (value) {\n  case \"a\":\n    console.log(\"a\");\n    break;\n  case \"b\":\n    console.log(\"b\");\n    break;\n  case \"c\":\n    console.log(\"c\");\n    break;\n  default:\n    assertNever(value);\n}\n\nswitch (value) {\n  case \"a\":\n    console.log(\"a\");\n    break;\n  case \"b\":\n    console.log(\"b\");\n    break;\n  default:\n    assertNever(value); // error; value is \"c\"\n}\n```\n\n## Object-Helper\n\n### `entries`\n\n```typescript\nimport { entries } from \"@beppobert/ts-utils\";\n\nconst obj = { a: 1, b: 2, c: 3 };\nconst objectEntries = entries(obj); // ([\"a\",1]|[\"b\",2]|[\"c\",3])[]\nfor (const [key, value] of entries(obj)) {\n  console.log(key, value);\n}\n```\n\n### `fromEntries`\n\n```typescript\nimport { fromEntries } from \"@beppobert/ts-utils\";\n\nconst objectEntries = [\n  [\"a\", 1],\n  [\"b\", 2],\n  [\"c\", 3],\n] as const;\n\nconst obj = fromEntries(objectEntries); // { a: 1, b: 2, c: 3 }\n```\n\n### `keys`\n\n```typescript\nimport { keys } from \"@beppobert/ts-utils\";\n\nconst obj = { a: 1, b: 2, c: 3 };\nconst objectKeys = keys(obj); // (\"a\"|\"b\"|\"c\")[]\nfor (const key of keys(obj)) {\n  console.log(key);\n}\n```\n\n### omit\n\n```typescript\nimport { omit } from \"@beppobert/ts-utils\";\n\nconst obj = { a: 1, b: 2, c: 3 };\nconst newObj = omit(obj, \"a\", \"b\"); // { c: 3 }\n```\n\n### `pick`\n\n```typescript\nimport { pick } from \"@beppobert/ts-utils\";\n\nconst obj = { a: 1, b: 2, c: 3 };\nconst newObj = pick(obj, \"a\", \"b\"); // { a: 1, b: 2 }\n```\n\n## Common Types\n\n### `Maybe`\n\n```typescript\nimport { Maybe } from \"@beppobert/ts-utils\";\n\nconst value: Maybe<string> = \"Hello, World!\";\nvalue = undefined;\nvalue = null;\n```\n\n### `Unknown`\n\n```typescript\nimport { Unknown } from \"@beppobert/ts-utils\";\n\nconst value: Unknown = \"Hello, World!\";\n\nvalue = 42;\nvalue = true;\nvalue = {};\nvalue = [];\nvalue = undefined;\n//.../\n```\n\n### `fn`\n\n```typescript\nimport { Fn } from \"@beppobert/ts-utils\";\n\nconst fn: Fn = (...args) => 0;\nconst fn2: Fn<[string], null> = (arg) => null;\nconst fn3: Fn<[string, number], boolean> = (arg1, arg2) => true;\n```\n","readmeFilename":"ReadMe.md","keywords":["typescript","utils","type","guard","Object.keys"]}