{"id":19064106,"url":"https://github.com/florianwendelborn/nullish-math","last_synced_at":"2026-02-08T21:04:46.622Z","repository":{"id":152242242,"uuid":"625569088","full_name":"FlorianWendelborn/nullish-math","owner":"FlorianWendelborn","description":"TypeScript Library for Basic Math Operations with Support for Null","archived":false,"fork":false,"pushed_at":"2024-11-24T06:29:05.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-28T22:36:38.832Z","etag":null,"topics":["javascript","library","math","null-safety","nullish","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nullish-math","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FlorianWendelborn.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","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":"2023-04-09T14:19:35.000Z","updated_at":"2024-11-24T06:28:38.000Z","dependencies_parsed_at":"2024-10-03T13:58:59.797Z","dependency_job_id":"548a2f55-9627-4a57-bf0d-3d8ba1376bc4","html_url":"https://github.com/FlorianWendelborn/nullish-math","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"59fb267d9b0c6d658864060ad825ac0ab4bae4a8"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/FlorianWendelborn/nullish-math","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorianWendelborn%2Fnullish-math","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorianWendelborn%2Fnullish-math/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorianWendelborn%2Fnullish-math/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorianWendelborn%2Fnullish-math/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FlorianWendelborn","download_url":"https://codeload.github.com/FlorianWendelborn/nullish-math/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlorianWendelborn%2Fnullish-math/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270466382,"owners_count":24588791,"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","status":"online","status_checked_at":"2025-08-14T02:00:10.309Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["javascript","library","math","null-safety","nullish","typescript"],"created_at":"2024-11-09T00:41:19.585Z","updated_at":"2026-02-08T21:04:46.591Z","avatar_url":"https://github.com/FlorianWendelborn.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nullish-math\n\n`nullish-math` is a lightweight TypeScript package that provides basic math operations with support for `null` and `undefined` values and an immutable, chainable API. It is useful when working with numeric data that may contain nullish values, as it ensures that any calculations involving nullish values result in `null` values.\n\n## Installation\n\nTo install `nullish-math`, use one of the following commands:\n\n```sh\nbun add nullish-math\nnpm install nullish-math\npnpm add nullish-math\nyarn add nullish-math\n```\n\n## Usage\n\nTo use `nullish-math`, simply import the `nm()` function from the package:\n\n```ts\nimport { nm } from 'nullish-math'\n```\n\nYou can then use the `nm()` function to create a new `NullishMath` object with an initial value:\n\n```ts\nconst value = nm(42)\n```\n\nYou can chain together multiple math operations using the `add()`, `subtract()`, `multiply()`, and `divide()` methods:\n\n```ts\nconst result = nm(42).add(21).multiply(2).subtract(10).end() // 116\n\n// null results in null\nconst result = nm(42).add(null).multiply(2).subtract(10).end() // null\n\n// undefined results in null\nconst result = nm(undefined).add(21).multiply(2).subtract(10).end() // null\n```\n\nIf any of the values passed to the math operation methods (`add()`, `subtract()`, `multiply()`, `divide()`) are nullish, the final value will be `null`.\n\n## API\n\n### `nm(value: number | null | undefined): NullishMath`\n\nThe `nm()` function creates a new `NullishMath` object with an initial value.\n\n#### `add(number: NullishMath | number | null | undefined): NullishMath`\n\nReturns a new instance of `NullishMath` with the sum of the current value and the given number.\n\n#### `addMany(...nums: Array\u003cNullishMath | number | null | undefined\u003e): NullishMath`\n\nReturns a new instance of `NullishMath` with the sum of the current value and the given numbers.\n\n#### `eq(toCompare: NullishMath | number | null | undefined): boolean`\n\nReturns `true` if the result equals `toCompare`, treats null and undefined as equals.\n\n#### `lt(toCompare: NullishMath | number | null | undefined): boolean | null`\n\nReturns `true` if the result is strictly less than `toCompare`, returns `null` if either number is nullish.\n\n#### `lte(toCompare: NullishMath | number | null | undefined): boolean | null`\n\nReturns `true` if the result is less than or equal to `toCompare`, returns `null` if either number is nullish.\n\n#### `gt(toCompare: NullishMath | number | null | undefined): boolean | null`\n\nReturns `true` if the result is strictly greater than `toCompare`, returns `null` if either number is nullish.\n\n#### `gte(toCompare: NullishMath | number | null | undefined): boolean | null`\n\nReturns `true` if the result is greater than or equal to `toCompare`, returns `null` if either number is nullish.\n\n#### `neq(toCompare: NullishMath | number | null | undefined): boolean`\n\nReturns `true` if the result doesn’t equal `toCompare`, treats null and undefined as equals.\n\n#### `subtract(number: NullishMath | number | null | undefined): NullishMath`\n\nReturns a new instance of `NullishMath` with the difference of the current value and the given number.\n\n#### `subtractMany(...nums: Array\u003cNullishMath | number | null | undefined\u003e): NullishMath`\n\nReturns a new instance of `NullishMath` with the difference of the current value and the given numbers.\n\n#### `multiply(number: NullishMath | number | null | undefined): NullishMath`\n\nReturns a new instance of `NullishMath` with the product of the current value and the given number.\n\n#### `multiplyMany(...nums: Array\u003cNullishMath | number | null | undefined\u003e): NullishMath`\n\nReturns a new instance of `NullishMath` with the product of the current value and the given numbers.\n\n#### `divide(number: NullishMath | number | null | undefined): NullishMath`\n\nReturns a new instance of `NullishMath` with the quotient of the current value and the given number.\n\n#### `divideMany(...nums: Array\u003cNullishMath | number | null | undefined\u003e): NullishMath`\n\nReturns a new instance of `NullishMath` with the quotient of the current value and the given numbers.\n\n#### `end(): number | null`\n\nReturns the final value of the `NullishMath` instance. If any of the values passed to the math operation methods are `null` or `undefined`, the final value will be `null`.\n\n### `NullishMath.average(Array\u003cNullishMath | number | null | undefined\u003e, options?: { treatNullishAsZero?: boolean }): NullishMath`\n\nCalculates the average of the provided numbers. By default, `null`s are excluded from the average. This can be changed by setting the `treatNullishAsZero` option. With this flag, nullish numbers get counted as a `0` and thus impact the average.\n\n### `NullishMath.max(Array\u003cNullishMath | number | null | undefined\u003e): NullishMath`\n\nCalculates the maximum of the provided numbers. Ignores `null` and `undefined`. Returns `null` if no proper number was provided\n\n### `NullishMath.min(Array\u003cNullishMath | number | null | undefined\u003e): NullishMath`\n\nCalculates the minimum of the provided numbers. Ignores `null` and `undefined`. Returns `null` if no proper number was provided\n\n### `NullishMath.unwrap(NullishMath | number | null | undefined): number | null`\n\nConverts the input to either `number | null`. General-purpose equivalent of `nm.end()`\n\n## Development\n\n`nullish-math` uses [`bun`](https://bun.sh)\n\n```sh\nbun install\n# bun run test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflorianwendelborn%2Fnullish-math","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflorianwendelborn%2Fnullish-math","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflorianwendelborn%2Fnullish-math/lists"}