{"id":16792556,"url":"https://github.com/ivanhofer/typesafe-utils","last_synced_at":"2025-04-30T08:24:19.708Z","repository":{"id":42674255,"uuid":"323253251","full_name":"ivanhofer/typesafe-utils","owner":"ivanhofer","description":"A collection of a few small lightweight typesafe utilities.","archived":false,"fork":false,"pushed_at":"2023-03-05T18:13:38.000Z","size":527,"stargazers_count":88,"open_issues_count":5,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T14:22:25.014Z","etag":null,"topics":["typescript","utils"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ivanhofer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-21T06:43:52.000Z","updated_at":"2025-01-03T10:24:47.000Z","dependencies_parsed_at":"2024-06-18T20:04:56.003Z","dependency_job_id":"89dd2e57-5e43-471a-91ae-64d97c91529a","html_url":"https://github.com/ivanhofer/typesafe-utils","commit_stats":{"total_commits":84,"total_committers":3,"mean_commits":28.0,"dds":"0.38095238095238093","last_synced_commit":"0ecf602c7471d286ee1a9d15182ad1c61157cfb7"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanhofer%2Ftypesafe-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanhofer%2Ftypesafe-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanhofer%2Ftypesafe-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanhofer%2Ftypesafe-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivanhofer","download_url":"https://codeload.github.com/ivanhofer/typesafe-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251438915,"owners_count":21589540,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["typescript","utils"],"created_at":"2024-10-13T08:46:14.167Z","updated_at":"2025-04-30T08:24:19.681Z","avatar_url":"https://github.com/ivanhofer.png","language":"TypeScript","readme":"A collection of a few small lightweight typesafe utilities.\n\n## Motivation\n\nSometimes you will encounter situations were the types will **not** match what you expect from a function. This means you need to explicitly specify a type by yourself to gain the full power of TypeScript.\n\nIn this collection you will find some useful functions that are fully typed.\n\n## Install\n\n```\n$ npm install --save-dev typesafe-utils\n```\n\n## Overview\n - [filter functions](#filter\u0026#32;functions)\n    - is\n      - [is](#is)\n      - [isNot](#isNot)\n      - [isProperty](#isProperty)\n      - [isPropertyNot](#isPropertyNot)\n    - isTruthy\n      - [isTruthy](#isTruthy)\n      - [isFalsy](#isFalsy)\n      - [isPropertyTruthy](#isPropertyTruthy)\n      - [isPropertyFalsy](#isPropertyFalsy)\n      - [arePropertiesTruthy](#arePropertiesTruthy)\n      - [arePropertiesFalsy](#arePropertiesFalsy)\n    - isUndefined\n      - [isUndefined](#isUndefined)\n      - [isNotUndefined](#isNotUndefined)\n      - [isPropertyUndefined](#isPropertyUndefined)\n      - [isPropertyNotUndefined](#isPropertyNotUndefined)\n      - [arePropertiesUndefined](#arePropertiesUndefined)\n      - [arePropertiesNotUndefined](#arePropertiesNotUndefined)\n    - isNull\n      - [isNull](#isNull)\n      - [isNotNull](#isNotNull)\n      - [isPropertyNull](#isPropertyNull)\n      - [isPropertyNotNull](#isPropertyNotNull)\n      - [arePropertiesNull](#arePropertiesNull)\n      - [arePropertiesNotNull](#arePropertiesNotNull)\n    - boolean\n      - [isBoolean](#isBoolean)\n      - isTrue\n        - [isTrue](#isTrue)\n        - [isNotTrue](#isNotTrue)*\n        - [isPropertyTrue](#isPropertyTrue)\n        - [isPropertyNotTrue](#isPropertyNotTrue)*\n        - [arePropertiesTrue](#arePropertiesTrue)\n        - [arePropertiesNotTrue](#arePropertiesNotTrue)*\n      - isFalse\n        - [isFalse](#isFalse)\n        - [isNotFalse](#isNotFalse)*\n        - [isPropertyFalse](#isPropertyFalse)\n        - [isPropertyNotFalse](#isPropertyNotFalse)*\n        - [arePropertiesFalse](#arePropertiesFalse)\n        - [arePropertiesNotFalse](#arePropertiesNotFalse)*\n    - number\n      - [isNumber](#isNumber)\n      - isZero\n        - [isZero](#isZero)\n        - [isNotZero](#isNotZero)*\n        - [isPropertyZero](#isPropertyZero)\n        - [isPropertyNotZero](#isPropertyNotZero)*\n        - [arePropertiesZero](#arePropertiesZero)\n        - [arePropertiesNotZero](#arePropertiesNotZero)*\n    - string\n      - [isString](#isString)\n      - isEmpty\n        - [isEmpty](#isEmpty)\n        - [isNotEmpty](#isNotEmpty)\n        - [isPropertyEmpty](#isPropertyEmpty)\n        - [isPropertyNotEmpty](#isPropertyNotEmpty)\n        - [arePropertiesEmpty](#arePropertiesEmpty)\n        - [arePropertiesNotEmpty](#arePropertiesNotEmpty)\n    - array\n      - [isArray](#isArray)\n      - [isArrayNotEmpty](#isArrayNotEmpty)\n      - [isArrayEmpty](#isArrayEmpty)\n    - object\n      - [isObject](#isObject)\n      - [isPrimitiveObject](#isPrimitiveObject)\n    - duplicates\n      - [filterDuplicates](#filterDuplicates)\n      - [filterDuplicatesByKey](#filterDuplicatesByKey)\n    - logical operators\n      - [and](#and)*\n      - [or](#or)*\n      - [not](#not)*\n    - typeguards\n      - [createFilter](#TypeGuardInverted)*\n\n - [sorting functions](#sorting\u0026#32;functions)\n    - number\n      - [sortNumberASC](#sortNumberASC)\n      - [sortNumberDESC](#sortNumberDESC)\n      - [sortNumberPropertyASC](#sortNumberPropertyASC)\n      - [sortNumberPropertyDESC](#sortNumberPropertyDESC)\n    - string\n      - [sortStringASC](#sortStringASC)\n      - [sortStringDESC](#sortStringDESC)\n      - [sortStringPropertyASC](#sortStringPropertyASC)\n      - [sortStringPropertyDESC](#sortStringPropertyDESC)\n    - date\n      - [sortDateASC](#sortDateASC)\n      - [sortDateDESC](#sortDateDESC)\n      - [sortDatePropertyASC](#sortDatePropertyASC)\n      - [sortDatePropertyDESC](#sortDatePropertyDESC)\n\n - [mapping functions](#mapping\u0026#32;functions)\n   - [pick](#pick)\n\n - [other](#other)\n   - [deepClone](#deepClone)\n   - [uniqueArray](#uniqueArray)\n\n - [types](#types)\n   - [Truthy](#truthy)\n   - [Falsy](#falsy)\n   - [TypeGuard](#typeguard)\n   - [TypeGuardWithReturnType](#typeguardwithreturntype)\n   - [TypeGuardInverted](#typeguardinverted)\n   - [TypeGuardInvertedWithReturnType](#typeguardinvertedwithreturntype)\n\n| * not automatically 100% typesafe. It's better than nothing but to be 100% typesafe you need to pass generics yourself.\n\n## filter functions\n\nA bunch of utilities that return true or false. Useful for array filter functions.\n\n\u003e Motivation: When you filter an Array, the return type is **not** always what you expect. Typescript will tell you the result of a filter function is the exact type you pass to the filter function. But that is **not** always true. If you filter out falsy values, the return type should should **not** contain.\n\n```TypeScript\n// BASIC example --------------------------------------------------------------\n\nconst result = [true, false].filter(bool =\u003e !!bool)\n// =\u003e result: boolean[] =\u003e [true]\n\n\nimport { isTruthy } from 'typesafe-utils'\nconst typesafeResult = [true, false].filter(isTruthy)\n// =\u003e typesafeResult: true[] =\u003e [true]\n\n\n// ADVANCED example -----------------------------------------------------------\n\nconst result = ['text', null, 'another text', undefined].filter(value =\u003e value !== '')\n// =\u003e result: (string | null | undefined)[] =\u003e ['text', 'another text']\n\n\nimport { isNotEmpty } from 'typesafe-utils'\nconst typesafeResult = ['text', null, 'another text', undefined].filter(isNotEmpty)\n// =\u003e typesafeResult: string[] =\u003e ['text', 'another text']\n```\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n### is\n\nreturns `true` iff value is equals to the property you pass to the function\n\n#### Usage\n```TypeScript\nimport { is } from 'typesafe-utils'\n\nconst result = [1, 15, 10, 43].filter(is(10))\n// result: number[] =\u003e [10]\n```\n\n### isNot\n\nreturns `true` iff value is **not** equal to the property you pass to the function\n\n#### Usage\n```TypeScript\nimport { isNot } from 'typesafe-utils'\n\nconst result = ['text', 'forbidden', 'blabla'].filter(isNot('forbidden'))\n// result: string[] =\u003e ['text', 'blabla']\n```\n\n### isProperty\n\nreturns `true` iff the attribute of the object equals the property you pass to the function\n\n#### Usage\n```TypeScript\nimport { isProperty } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n}\n\nconst items: Product[] = [\n   { id: 1 },\n   { id: 3 }\n]\nconst result = items.filter(isProperty('id', 3))\n// result: Product[] =\u003e [{ id: 3 }]\n```\n\n### isPropertyNot\n\nreturns `true` iff the attribute of the object is **not** equal to the property you pass to the function\n\n#### Usage\n```TypeScript\nimport { isPropertyNot } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n}\n\nconst items: Product[] = [\n   { id: 156 },\n   { id: 123 }\n]\nconst result = items.filter(isPropertyNot('id', 123))\n// result: Product[] =\u003e [{ id: 156 }]\n```\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n### isTruthy\n\nreturns `true` iff value is **not** `false | '' | 0 | null | undefined`\n\n#### Usage\n```TypeScript\nimport { isTruthy } from 'typesafe-utils'\n\nconst result = [true, false, undefined, null].filter(isTruthy)\n// result: true[] =\u003e [true]\n```\n\n### isFalsy\n\nreturns `true` iff value is `false | '' | 0 | null | undefined`\n\n#### Usage\n```TypeScript\nimport { isFalsy } from 'typesafe-utils'\n\nconst result = [true, false, 'text', 123, null].filter(isFalsy)\n// result: (false | null)[] =\u003e [false, null]\n```\n\n### isPropertyTruthy\n\nreturns `true` iff the attribute of the object is truthy\n\n#### Usage\n```TypeScript\nimport { isPropertyTruthy } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n}\n\nconst items: Product[] = [\n   { id: 1 },\n   { id: null },\n   { id: undefined }\n]\nconst result = items.filter(isPropertyTruthy('id'))\n// result: Product[] =\u003e [{ id: 1 }]\n```\n\n### isPropertyFalsy\n\nreturns `true` iff the attribute of the object is falsy\n\n#### Usage\n```TypeScript\nimport { isPropertyFalsy } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n}\n\nconst items: Product[] = [\n   { id: 5 },\n   { id: null }\n]\nconst result = items.filter(isPropertyFalsy('id'))\n// result: Product[] =\u003e [{ id: null }]\n```\n\n### arePropertiesTruthy\n\nreturns `true` iff all attributes of the object are truthy\n\n#### Usage\n```TypeScript\nimport { arePropertiesTruthy } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n   name: string\n}\n\nconst items: Product[] = [ ... ]\n\nconst result = items.filter(arePropertiesTruthy('id', 'name'))\n```\n\n### arePropertiesFalsy\n\nreturns `true` iff all attributes of the object are falsy\n\n#### Usage\n```TypeScript\nimport { arePropertiesFalsy } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n   name: string\n}\n\nconst items: Product[] = [ ... ]\n\nconst result = items.filter(arePropertiesFalsy('id', 'name'))\n```\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n### isUndefined\n\nreturns `true` iff value is `undefined`\n\n#### Usage\n```TypeScript\nimport { isUndefined } from 'typesafe-utils'\n\nconst result = [undefined, null, true].filter(isUndefined)\n// result: undefined[] =\u003e [undefined]\n```\n\n### isNotUndefined\n\nreturns `true` iff value is **not** `undefined`\n\n#### Usage\n```TypeScript\nimport { isNotUndefined } from 'typesafe-utils'\n\nconst result = [null, undefined].filter(isNotUndefined)\n// result: null[] =\u003e [null]\n```\n\n### isPropertyUndefined\n\nreturns `true` iff the attribute of the object is `undefined`\n\n#### Usage\n```TypeScript\nimport { isPropertyUndefined } from 'typesafe-utils'\n\ntype Product = {\n   id: number | undefined\n}\n\nconst items: Product[] = [\n   { id: 1 },\n   { id: undefined }\n]\nconst result = items.filter(isPropertyUndefined('id'))\n// result: Product[] =\u003e [{ id: undefined }]\n```\n\n### isPropertyNotUndefined\n\nreturns `true` iff the attribute of the object is **not** `undefined`\n\n#### Usage\n```TypeScript\nimport { isPropertyNotUndefined } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n}\n\nconst items: Product[] = [\n   { id: 5 },\n   { id: undefined }\n]\nconst result = items.filter(isPropertyNotUndefined('id'))\n// result: Product[] =\u003e [{ id: 5 }]\n```\n\n### arePropertiesUndefined\n\nreturns `true` iff all attributes of the object are `undefined`\n\n#### Usage\n```TypeScript\nimport { arePropertiesUndefined } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n   name: string\n}\n\nconst items: Product[] = [ ... ]\n\nconst result = items.filter(arePropertiesUndefined('id', 'name'))\n```\n\n### arePropertiesNotUndefined\n\nreturns `true` iff all attributes of the object are **not** `undefined`\n\n#### Usage\n```TypeScript\nimport { arePropertiesNotUndefined } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n   name: string\n}\n\nconst items: Product[] = [ ... ]\n\nconst result = items.filter(arePropertiesNotUndefined('id', 'name'))\n```\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n### isNull\n\nreturns `true` iff value is `null`\n\n#### Usage\n```TypeScript\nimport { isNull } from 'typesafe-utils'\n\nconst result = [null, undefined].filter(isNull)\n// result: null[] =\u003e [null]\n```\n\n### isNotNull\n\nreturns `true` iff value is **not** `null`\n\n#### Usage\n```TypeScript\nimport { isNotNull } from 'typesafe-utils'\n\nconst result = [false, null].filter(isNotNull)\n// result: boolean[] =\u003e [false]\n```\n\n### isPropertyNull\n\nreturns `true` iff the attribute of the object is `null`\n\n#### Usage\n```TypeScript\nimport { isPropertyNull } from 'typesafe-utils'\n\ntype Product = {\n   id: number | null\n}\n\nconst items: Product[] = [\n   { id: 0 },\n   { id: null }\n]\nconst result = items.filter(isPropertyNull('id'))\n// result: Product[] =\u003e [{ id: null }]\n```\n\n### isPropertyNotNull\n\nreturns `true` iff the attribute of the object is **not** `null`\n\n#### Usage\n```TypeScript\nimport { isPropertyNotNull } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n}\n\nconst items: Product[] = [\n   { id: 5 },\n   { id: null }\n]\nconst result = items.filter(isPropertyNotNull('id'))\n// result: Product[] =\u003e [{ id: 5 }]\n```\n\n### arePropertiesNull\n\nreturns `true` iff all attributes of the object are `null`\n\n#### Usage\n```TypeScript\nimport { arePropertiesNull } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n   name: string\n}\n\nconst items: Product[] = [ ... ]\n\nconst result = items.filter(arePropertiesNull('id', 'name'))\n```\n\n### arePropertiesNotNull\n\nreturns `true` iff all attributes of the object are **not** `null`\n\n#### Usage\n```TypeScript\nimport { arePropertiesNotNull } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n   name: string\n}\n\nconst items: Product[] = [ ... ]\n\nconst result = items.filter(arePropertiesNotNull('id', 'name'))\n```\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n### isBoolean\n\nreturns `true` iff value is of type `boolean`\n\n#### Usage\n```TypeScript\nimport { isBoolean } from 'typesafe-utils'\n\nconst result = [true, 'some text', 1, false].filter(isBoolean)\n// result: boolean[] =\u003e [true, false]\n```\n\n### isTrue\n\nreturns `true` iff value is `true`\n\n#### Usage\n```TypeScript\nimport { isTrue } from 'typesafe-utils'\n\nconst result = [true, 'some text', 1].filter(isTrue)\n// result: true[] =\u003e [true]\n```\n\n### isNotTrue\n\nreturns `true` iff value is **not** `true`\n\n \u003e Note: it is currently **not** possible to make this function fully typesafe.\\\n \u003e `[true, 123].filter(isNotTrue)` will have the type `(false | number)[]`\n\n#### Usage\n```TypeScript\nimport { isNotTrue } from 'typesafe-utils'\n\nconst result = [true, false].filter(isNotTrue)\n// result: false[] =\u003e [false]\n```\n\n### isPropertyTrue\n\nreturns `true` iff the attribute of the object is `true`\n\n#### Usage\n```TypeScript\nimport { isPropertyTrue } from 'typesafe-utils'\n\ntype Product = {\n   available: boolean | null\n}\n\nconst items: Product[] = [\n   { available: true },\n   { available: null }\n]\nconst result = items.filter(isPropertyTrue('available'))\n// result: Product[] =\u003e [{ available: true }]\n```\n\n### isPropertyNotTrue\n\nreturns `true` iff the attribute of the object is **not** `true`\n\n#### Usage\n```TypeScript\nimport { isPropertyNotTrue } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n}\n\nconst items: Product[] = [\n   { available: true },\n   { available: false }\n]\nconst result = items.filter(isPropertyNotTrue('available'))\n// result: Product[] =\u003e [{ available: false }]\n```\n\n### arePropertiesTrue\n\nreturns `true` iff all attributes of the object are `true`\n\n#### Usage\n```TypeScript\nimport { arePropertiesTrue } from 'typesafe-utils'\n\ntype Product = {\n   count: number\n   available: string\n}\n\nconst items: Product[] = [ ... ]\n\nconst result = items.filter(arePropertiesTrue('count', 'available'))\n```\n\n### arePropertiesNotTrue\n\nreturns `true` iff all attributes of the object are **not** `true`\n\n#### Usage\n```TypeScript\nimport { arePropertiesNotTrue } from 'typesafe-utils'\n\ntype Product = {\n   count: number\n   available: string\n}\n\nconst items: Product[] = [ ... ]\n\nconst result = items.filter(arePropertiesNotTrue('count', 'available'))\n```\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n### isFalse\n\nreturns `true` iff value is `false`\n\n#### Usage\n```TypeScript\nimport { isFalse } from 'typesafe-utils'\n\nconst result = [0, false, undefined].filter(isFalse)\n// result: false[] =\u003e [false]\n```\n\n### isNotFalse\n\nreturns `true` iff value is **not** `false`\n\n \u003e Note: it is currently **not** possible to make this function fully typesafe.\\\n \u003e `[false, 123].filter(isNotFalse)` will have the type `(true | number)[]`\n\n#### Usage\n```TypeScript\nimport { isNotFalse } from 'typesafe-utils'\n\nconst result = [false, null].filter(isNotFalse)\n// result: null[] =\u003e [null]\n```\n\n### isPropertyFalse\n\nreturns `true` iff the attribute of the object is `false`\n\n#### Usage\n```TypeScript\nimport { isPropertyFalse } from 'typesafe-utils'\n\ntype Product = {\n   available: boolean | null\n}\n\nconst items: Product[] = [\n   { available: false },\n   { available: true },\n   { available: null }\n]\nconst result = items.filter(isPropertyFalse('available'))\n// result: Product[] =\u003e [{ available: false }]\n```\n\n### isPropertyNotFalse\n\nreturns `true` iff the attribute of the object is **not** `false`\n\n#### Usage\n```TypeScript\nimport { isPropertyNotFalse } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n}\n\nconst items: Product[] = [\n   { available: true },\n   { available: false }\n]\nconst result = items.filter(isPropertyNotFalse('available'))\n// result: Product[] =\u003e [{ available: true }]\n```\n\n### arePropertiesFalse\n\nreturns `true` iff all attributes of the object are `false`\n\n#### Usage\n```TypeScript\nimport { arePropertiesFalse } from 'typesafe-utils'\n\ntype Product = {\n   count: number\n   available: string\n}\n\nconst items: Product[] = [ ... ]\n\nconst result = items.filter(arePropertiesFalse('count', 'available'))\n```\n\n### arePropertiesNotFalse\n\nreturns `true` iff all attributes of the object are **not** `false`\n\n#### Usage\n```TypeScript\nimport { arePropertiesNotFalse } from 'typesafe-utils'\n\ntype Product = {\n   count: number\n   available: string\n}\n\nconst items: Product[] = [ ... ]\n\nconst result = items.filter(arePropertiesNotFalse('count', 'available'))\n```\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n### isNumber\n\nreturns `true` iff value is of type `number`\n\n#### Usage\n```TypeScript\nimport { isNumber } from 'typesafe-utils'\n\nconst result = [0, false, undefined, 5].filter(isNumber)\n// result: number[] =\u003e [0, 5]\n```\n\n### isZero\n\nreturns `true` iff value is `0`\n\n#### Usage\n```TypeScript\nimport { isZero } from 'typesafe-utils'\n\nconst result = [0, false, undefined, 5].filter(isZero)\n// result: 0[] =\u003e [0]\n```\n\n### isNotZero\n\nreturns `true` iff value is **not** `0`\n\n \u003e Note: it is currently **not** possible to make this function fully typesafe.\\\n \u003e `[0, null].filter(isNotTrue)` will have the type `(number | null)[]`\n\n#### Usage\n```TypeScript\nimport { isNotZero } from 'typesafe-utils'\n\nconst result = [0, 123].filter(isNotZero)\n// result: number[] =\u003e [123]\n```\n\n### isPropertyZero\n\nreturns `true` iff the attribute of the object is `0`\n\n#### Usage\n```TypeScript\nimport { isPropertyZero } from 'typesafe-utils'\n\ntype Product = {\n   price: number\n}\n\nconst items: Product[] = [\n   { price: 0 },\n   { price: 4 },\n   { price: 15 }\n]\nconst result = items.filter(isPropertyZero('price'))\n// result: Product[] =\u003e [{ price: 0 }]\n```\n\n### isPropertyNotZero\n\nreturns `true` iff the attribute of the object is **not** `0`\n\n#### Usage\n```TypeScript\nimport { isPropertyNotZero } from 'typesafe-utils'\n\ntype Product = {\n   price: number\n}\n\nconst items: Product[] = [\n   { price: 0 },\n   { price: 12 }\n]\nconst result = items.filter(isPropertyNotZero('price'))\n// result: Product[] =\u003e [{ price: 23 }]\n```\n\n### arePropertiesZero\n\nreturns `true` iff all attributes of the object are `0`\n\n#### Usage\n```TypeScript\nimport { arePropertiesZero } from 'typesafe-utils'\n\ntype Product = {\n   count: number\n   speed: string\n}\n\nconst items: Product[] = [ ... ]\n\nconst result = items.filter(arePropertiesZero('count', 'speed'))\n```\n\n### arePropertiesNotZero\n\nreturns `true` iff all attributes of the object are **not** `0`\n\n#### Usage\n```TypeScript\nimport { arePropertiesNotZero } from 'typesafe-utils'\n\ntype Product = {\n   count: number\n   speed: string\n}\n\nconst items: Product[] = [ ... ]\n\nconst result = items.filter(arePropertiesNotZero('count', 'speed'))\n```\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n### isString\n\nreturns `true` iff value is of type `string`\n\n#### Usage\n```TypeScript\nimport { isString } from 'typesafe-utils'\n\nconst result = ['', false, null, 'text'].filter(isString)\n// result: string[] =\u003e ['', 'text]\n```\n\n### isEmpty\n\nreturns `true` iff value is `''`\n\n#### Usage\n```TypeScript\nimport { isEmpty } from 'typesafe-utils'\n\nconst result = ['', false, null, 'text'].filter(isEmpty)\n// result: ''[] =\u003e ['']\n```\n\n### isNotEmpty\n\nreturns `true` iff value is **not** `''`\n\n#### Usage\n```TypeScript\nimport { isNotEmpty } from 'typesafe-utils'\n\nconst result = ['', 5].filter(isNotEmpty)\n// result: number[] =\u003e [5]\n```\n\n### isPropertyEmpty\n\nreturns `true` iff the attribute of the object is `''`\n\n#### Usage\n```TypeScript\nimport { isPropertyEmpty } from 'typesafe-utils'\n\ntype Product = {\n   label: string\n}\n\nconst items: Product[] = [\n   { label: '' },\n   { label: 'label-1' }\n]\nconst result = items.filter(isPropertyEmpty('label'))\n// result: Product[] =\u003e [{ label: '' }]\n```\n\n### isPropertyNotEmpty\n\nreturns `true` iff the attribute of the object is **not** `''`\n\n#### Usage\n```TypeScript\nimport { isPropertyNotEmpty } from 'typesafe-utils'\n\ntype Product = {\n   label: string\n}\n\nconst items: Product[] = [\n   { label: 'label-123' },\n   { label: '' }\n]\nconst result = items.filter(isPropertyNotEmpty('label'))\n// result: Product[] =\u003e [{ label: 'label-123' }]\n```\n\n\n### arePropertiesEmpty\n\nreturns `true` iff all attributes of the object are `''`\n\n#### Usage\n```TypeScript\nimport { arePropertiesEmpty } from 'typesafe-utils'\n\ntype Person = {\n   name: number\n   firstName: string\n}\n\nconst items: Person[] = [ ... ]\n\nconst result = items.filter(arePropertiesEmpty('name', 'firstName'))\n```\n\n### arePropertiesNotEmpty\n\nreturns `true` iff all attributes of the object are **not** `''`\n\n#### Usage\n```TypeScript\nimport { arePropertiesNotEmpty } from 'typesafe-utils'\n\ntype Person = {\n   name: number\n   firstName: string\n}\n\nconst items: Person[] = [ ... ]\n\nconst result = items.filter(arePropertiesNotEmpty('name', 'firstName'))\n```\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n### isArray\n\nreturns `true` iff value is of type `Array`\n\n#### Usage\n```TypeScript\nimport { isArray } from 'typesafe-utils'\n\nconst result = [[], null, 123, [0, 1]].filter(isArray)\n// result: number[][] =\u003e [[], [0, 1]]\n```\n\n### isArrayNotEmpty\n\nreturns `true` iff an array contains at least one item\n\n#### Usage\n```TypeScript\nimport { isArrayNotEmpty } from 'typesafe-utils'\n\nconst nonEmptyArray = ['hi']\n\nif (!!nonEmptyArray.length) {\n\tnonEmptyArray[0].toUpperCase() // ERROR: Object is possibly 'undefined'\n}\n\nif (isArrayNotEmpty(nonEmptyArray)) {\n   // TypeScript will know that the array contains at least 1 item, so it will not complain\n\tnonEmptyArray[0].toUpperCase()\n}\n```\n\n### isArrayEmpty\n\nreturns `true` iff an array contains no items\n\n#### Usage\n```TypeScript\nimport { isArrayEmpty } from 'typesafe-utils'\n\nconst emptyArray: string[] = []\nif (isArrayEmpty(emptyArray)) {\n\t// emptyArray does not contain any items\n}\n```\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n### isObject\n\nreturns `true` iff value is of type `object`\n\n#### Usage\n```TypeScript\nimport { isObject } from 'typesafe-utils'\n\ntype SomeType = {\n   prop?: number\n}\n\nconst now = new Date()\nconst result = [{}, now, null, { prop: 123 }].filter(isObject)\n// result: (SomeType | Date)[] =\u003e [{}, now, { prop: 123 }]\n```\n\n### isPrimitiveObject\n\nreturns `true` iff value is of the primitive type `object` and not derived from a `class` like `Date` or else.\n\n#### Usage\n```TypeScript\nimport { isPrimitiveObject } from 'typesafe-utils'\n\ntype SomeType = {\n   prop?: number\n}\n\nconst now = new Date()\nconst result = [{}, now, null, { prop: 123 }].filter(isPrimitiveObject)\n// result: SomeType[] =\u003e [{}, { prop: 123 }]\n```\n\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n### filterDuplicates\n\nRemoves duplicates from an array. Only the first occurrence of an item will be kept.\n\n#### Usage\n\n```TypeScript\nimport { filterDuplicates } from 'typesafe-utils'\n\nconst items = [1, 2, 3, 5, 8, 1]\nconst filteredItems = items.filter(filterDuplicates)\n// filteredItems: number[] =\u003e [1, 2, 3, 5, 8]\n```\n\n### filterDuplicatesByKey\n\nRemoves duplicates from an array by its key. Only the first occurrence of an item will be kept.\n\n\u003e Motivation: It is less error-prone if you can only pass the keys an object provides to a filter function. With this function you get full types support.\n\n#### Usage\n\n```TypeScript\nimport { filterDuplicatesByKey } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n   name: string\n}\n\nconst items: Product[] = [\n   { id: 1, name: 'name-1' },\n   { id: 2, name: 'name-2' },\n   { id: 3, name: 'name-1' },\n   { id: 4, name: 'name-2' }\n]\nconst filteredItems = items.filter(filterDuplicatesByKey('name'))\n// filteredItems: Product[] =\u003e [{ id: 1, name: 'name-1' }, { id: 2, name: 'name-2' }]\n\n\nconst willThrowAnError = items.filter(filterDuplicatesByKey('price'))\n// throws: Argument of type '\"price\"' is **not** assignable to parameter of type '\"id\" | \"name\"'\n```\n\n### and\n\nCombines (`\u0026\u0026`) multiple filter functions.\n\n#### Usage\n\n```TypeScript\nimport { and, isString } from 'typesafe-utils'\n\nconst items = [null, \"test\", undefined, \"hi\"]\nconst isShortString = and\u003cstring, any\u003e(isString, (value) =\u003e value.length \u003c 3)\nconst filteredItems = items.filter(isShortString)\n// filteredItems: string[] =\u003e ['hi']\n```\n\n### or\n\nCombines (`||`) multiple filter functions.\n\n#### Usage\n\n```TypeScript\nimport { or } from 'typesafe-utils'\n\nconst items = [10, 2, 3, 5, 8, 1]\nconst isFiveOrTen = or((value) =\u003e value === 5, (value) =\u003e value === 10)\nconst filteredItems = items.filter(isFiveOrTen)\n// filteredItems: number[] =\u003e [10, 5]\n```\n\n\n### not\n\nInverts a filter function.\n\n#### Usage\n\n```TypeScript\nimport { not, filterDuplicates } from 'typesafe-utils'\n\ntype Product = {\n   id: number\n   name: string\n}\n\nconst items: Product[] = [\n   { id: 1, name: 'name-1' },\n   { id: 2, name: 'name-2' },\n   { id: 3, name: 'name-1' },\n   { id: 4, name: 'name-2' }\n]\nconst filteredItems = items.filter(not\u003cProduct\u003e(filterDuplicatesByKey('name')))\n// filteredItems: Product[] =\u003e [{ id: 3, name: 'name-1' }, { id: 4, name: 'name-2' }]\n\n\n// The `not` function takes two optional type arguments.\n// The first is the type you expect the filter function to return.\n// The second is the Type of the Array you want to filter.\n// e.g.\nconst notNull = [1, 5, null].filter\u003cnumber, number | null\u003e(not((value =\u003e value === null)))\n// notNull: number[] =\u003e [1, 5]\n\n```\n\n\n\n### createFilter\n\nCreates a typeguard filter.\n\n#### Usage\n\n```TypeScript\nimport { createFilter } from 'typesafe-utils'\n\ninterface Item {\n   id: number\n}\n\ninterface ItemWithName extends Item {\n   name: string\n}\n\nconst items: (Item | ItemWithName | undefined)[] = [\n   { id: 1 },\n   undefined\n   { id: 3, name: 'name-1' },\n   { id: 4 }\n]\n\nconst filterHasName = createFilter\u003cItemWithName\u003e((item) =\u003e !!item?.name)\nconst filteredItems = items.filter(filterHasName)\n// filteredItems: ItemWithName[] =\u003e [{ id: 3, name: 'name-1' }]\n```\n\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n## sorting functions\n\n### sortNumberASC\n\nsort `number` in **ASC** order\n\n#### Usage\n```TypeScript\nimport { sortNumberASC } from 'typesafe-utils'\n\nconst items = [4, -1, 3, 0]\nconst result = items.sort(sortNumberASC)\n// result: number[] =\u003e [-1, 0, 3, 4]\n```\n\n### sortNumberDESC\n\nsort `number` in **DESC** order\n\n#### Usage\n```TypeScript\nimport { sortNumberDESC } from 'typesafe-utils'\n\nconst items = [2, -5, 0]\nconst result = items.sort(sortNumberDESC)\n// result: number[] =\u003e [2, 0, -5]\n```\n\n### sortNumberPropertyASC\n\nsort property of type `number` in **ASC** order\n\n#### Usage\n```TypeScript\nimport { sortNumberPropertyASC } from 'typesafe-utils'\n\ntype Car {\n   speed: number\n}\n\nconst items: Car[] = [\n   { speed: 113 },\n   { speed: 100 },\n   { speed: 95 }\n]\nconst result = items.sort(sortNumberPropertyASC('speed'))\n// result: Car[] =\u003e [{ speed: 95 }, { speed: 100 }, { speed: 113 }}\n```\n\n### sortNumberPropertyDESC\n\nsort property of type `number` in **DESC** order\n\n#### Usage\n```TypeScript\nimport { sortNumberPropertyDESC } from 'typesafe-utils'\n\ntype Car {\n   speed: number\n}\n\nconst items: Car[] = [\n   { speed: 70 }\n   { speed: 87 }\n]\nconst result = items.sort(sortNumberPropertyDESC('speed'))\n// result: Car[] =\u003e [{ speed: 87 }, { speed: 70 }]\n```\n\n### sortStringASC\n\nsort `string` in **ASC** order\n\n#### Usage\n```TypeScript\nimport { sortStringASC } from 'typesafe-utils'\n\nconst items = ['Hi', 'apples']\nconst result = items.sort(sortStringASC)\n// result: string[] =\u003e ['apples', Hi']\n```\n\n### sortStringDESC\n\nsort `string` in **DESC** order\n\n#### Usage\n```TypeScript\nimport { sortStringDESC } from 'typesafe-utils'\n\nconst items = ['apple', 'banana']\nconst result = items.sort(sortStringDESC)\n// result: string[] =\u003e ['banana', 'apple']\n```\n\n### sortStringPropertyASC\n\nsort property of type `string` in **ASC** order\n\n#### Usage\n```TypeScript\nimport { sortStringPropertyASC } from 'typesafe-utils'\n\ntype Car {\n   color: string\n}\n\nconst items: Car[] = [\n   { color: 'green' },\n   { color: 'brown' }\n]\n\nconst result = items.sort(sortStringPropertyASC('color'))\n// result: Car[] =\u003e [{ color: 'brown' }, { color: 'green' }]\n```\n\n### sortStringPropertyDESC\n\nsort property of type `string` in **DESC** order\n\n#### Usage\n```TypeScript\nimport { sortStringPropertyDESC } from 'typesafe-utils'\n\ntype Car {\n   color: string\n}\n\nconst items: Car[] = [\n   { color: 'red' },\n   { color: 'blue' }\n]\nconst result = items.sort(sortStringPropertyDESC('color'))\n// result: Car[] =\u003e [{ color: 'red' }, { color: 'blue' }]\n```\n\n### sortDateASC\n\nsort `Date` in **ASC** order\n\n#### Usage\n```TypeScript\nimport { sortDateASC } from 'typesafe-utils'\n\nconst today = new Date()\nconst tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000)\n\nconst items = [tomorrow, today]\nconst result = items.sort(sortDateASC)\n// result: Date[] =\u003e [today, tomorrow]\n```\n\n### sortDateDESC\n\nsort `Date` in **DESC** order\n\n#### Usage\n```TypeScript\nimport { sortDateDESC } from 'typesafe-utils'\n\nconst today = new Date()\nconst tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000)\n\nconst items = [today, tomorrow]\nconst result = items.sort(sortDateDESC)\n// result: Date[] =\u003e [tomorrow, today]\n```\n\n### sortDatePropertyASC\n\nsort property of type `Date` in **ASC** order\n\n#### Usage\n```TypeScript\nimport { sortDatePropertyASC } from 'typesafe-utils'\n\ntype Smartphone = {\n   releaseDate: Date\n}\n\nconst today = new Date()\nconst tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000)\n\nconst items: Smartphone[] = [\n   { releaseDate: tomorrow },\n   { releaseDate: today }\n]\n\nconst items: Smartphone[] = []\nconst result = items.sort(sortDatePropertyASC('releaseDate'))\n// result: Smartphone[]=\u003e [{ releaseDate: today }, { releaseDate: tomorrow }]\n```\n\n### sortDatePropertyDESC\n\nsort property of type `Date` in **DESC** order\n\n#### Usage\n```TypeScript\nimport { sortDatePropertyDESC } from 'typesafe-utils'\n\ntype Smartphone = {\n   releaseDate: Date\n}\n\nconst today = new Date()\nconst tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000)\n\nconst items: Smartphone[] = [\n   { releaseDate: today },\n   { releaseDate: tomorrow }\n]\nconst result = items.sort(sortDatePropertyDESC('releaseDate'))\n// result: Smartphone[] =\u003e [{ releaseDate: tomorrow }, { releaseDate: today }]\n```\n\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n## mapping functions\n\n### pick\n\nPicks an attribute from an Object.\n\n#### Usage\n\n```TypeScript\nimport { pick } from 'typesafe-utils'\n\ninterface Item {\n   id: number\n   name: string\n   price: number\n}\n\nconst items: Item[] = [\n   { id: 1, name: '', price: 123 },\n   { id: 3, name: '', price: 0 },\n   { id: 7, name: '', price: 12 },\n]\n\nconst ids = items.map(pick('id'))\n// ids: number[] =\u003e [ 1, 3, 7 ]\n```\n\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n## other\n\n### deepClone\n\nCreates a deep copy of an object containing primitive values.\n\n\u003e Motivation: I have seen a variety of clone-functions that return any. There you would need to always specify the type by ourself. Using this function, you will get a correctly typed object back.\n\n#### Usage\n\n```TypeScript\nimport { deepClone } from 'typesafe-utils'\n\nconst objectToClone: MyTypedObject = { ... }\nconst clonedObject = deepClone(objectToClone)\n// =\u003e clonedObject: MyTypedObject =\u003e { ... }\n```\n\n\n### uniqueArray\n\nRemoves duplicates from an array.\n\n#### Usage\n\n```TypeScript\nimport { uniqueArray } from 'typesafe-utils'\n\nconst unique = uniqueArray('John', 'Max', 'John')\n// =\u003e unique: string[] =\u003e ['John', 'Max']\n```\n\n\n\u003c!----------------------------------------------------------------------------\u003e\n\n## Types\n\n### Truthy\n\nContains all `Truthy` values (everything excluding [Falsy](#falsy) values)\n\n#### Usage\n\n```TypeScript\nimport { Truthy } from 'typesafe-utils'\n\nexport const isTruthy = \u003cT\u003e(value: T): value is Truthy\u003cT\u003e =\u003e !!value\n\nconst truthy = [123, undefined].filter(isTruthy) // =\u003e number[]\nconst notTruthy = [false, true].filter(isTruthy) // =\u003e never[]\n```\n\n\n### Falsy\n\nContains all `Falsy` values (false | '' | 0 | null | undefined)\n\n#### Usage\n\n```TypeScript\nimport { Falsy } from 'typesafe-utils'\n\nexport const isFalsy = \u003cT\u003e(value: T): value is Falsy\u003cT\u003e =\u003e !value\n\nconst falsy = [undefined, ''].filter(isFalsy) // =\u003e undefined[]\nconst notFalsy = [0, ''].filter(isFalsy) // =\u003e never[]\n```\n\n\n### TypeGuard\n### TypeGuardWithReturnType\n\nAllows you to write custom `TypeGuard` functions.\n\n#### Usage\n\n```TypeScript\nimport { TypeGuard } from 'typesafe-utils'\n\ntype Project {\n   id: number\n   // ...\n}\n\nconst isProject = \u003cT\u003e(value: T): value is TypeGuard\u003cProject, T\u003e =\u003e value?.hasOwnProperty('id')\n\nconst p1 = isProject({ id: 1 }) // =\u003e true\nconst p2 = isProject(true) // =\u003e false\n```\n\n\n### TypeGuardInverted\n### TypeGuardInvertedWithReturnType\n\nAllows you to write custom inverted `TypeGuard` functions.\n\n#### Usage\n\n```TypeScript\nimport { TypeGuardInverted } from 'typesafe-utils'\n\ntype Project {\n   id: number\n   // ...\n}\n\nconst isNotProject = \u003cT\u003e(value: T): value is TypeGuardInverted\u003cProject, T\u003e =\u003e !value?.hasOwnProperty('id')\n\nconst p1 = isNotProject({ id: 1 }) // =\u003e false\nconst p2 = isNotProject(null) // =\u003e true\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanhofer%2Ftypesafe-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivanhofer%2Ftypesafe-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanhofer%2Ftypesafe-utils/lists"}