{"id":17148443,"url":"https://github.com/aholstenson/numeric-types","last_synced_at":"2026-01-31T23:39:54.492Z","repository":{"id":55854446,"uuid":"180646883","full_name":"aholstenson/numeric-types","owner":"aholstenson","description":"Numeric types for JavaScript and TypeScript","archived":false,"fork":false,"pushed_at":"2020-12-11T06:44:30.000Z","size":426,"stargazers_count":1,"open_issues_count":13,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-23T15:55:03.564Z","etag":null,"topics":["numeric","numeric-types"],"latest_commit_sha":null,"homepage":null,"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/aholstenson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-10T19:07:58.000Z","updated_at":"2020-01-16T22:14:26.000Z","dependencies_parsed_at":"2022-08-15T07:51:05.166Z","dependency_job_id":null,"html_url":"https://github.com/aholstenson/numeric-types","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/aholstenson/numeric-types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aholstenson%2Fnumeric-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aholstenson%2Fnumeric-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aholstenson%2Fnumeric-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aholstenson%2Fnumeric-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aholstenson","download_url":"https://codeload.github.com/aholstenson/numeric-types/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aholstenson%2Fnumeric-types/sbom","scorecard":{"id":172338,"data":{"date":"2025-08-11","repo":{"name":"github.com/aholstenson/numeric-types","commit":"b4a69c7b2c5d7bdc93918bb4a66954b5c0de5b93"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"50 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-6chw-6frg-f759","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f","Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p","Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv","Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8","Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65","Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh","Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44","Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-16T16:54:40.952Z","repository_id":55854446,"created_at":"2025-08-16T16:54:40.952Z","updated_at":"2025-08-16T16:54:40.952Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28960537,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T23:03:11.038Z","status":"ssl_error","status_checked_at":"2026-01-31T22:56:44.691Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["numeric","numeric-types"],"created_at":"2024-10-14T21:28:36.969Z","updated_at":"2026-01-31T23:39:54.449Z","avatar_url":"https://github.com/aholstenson.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Numeric types for JavaScript\n\n[![npm version](https://badge.fury.io/js/numeric-types.svg)](https://badge.fury.io/js/numeric-types)\n[![Build Status](https://travis-ci.org/aholstenson/numeric-types.svg?branch=master)](https://travis-ci.org/aholstenson/numeric-types)\n[![Coverage Status](https://coveralls.io/repos/aholstenson/numeric-types/badge.svg)](https://coveralls.io/github/aholstenson/numeric-types)\n[![Dependencies](https://david-dm.org/aholstenson/numeric-types.svg)](https://david-dm.org/aholstenson/numeric-types)\n\nThis library contains implementations of useful numeric types for JavaScript\nand TypeScript.\n\n```\nnpm install numeric-types\n```\n\n## Features and status\n\nThis is currently an early release.\n\n* Rounding modes: up, down, half down, half even, half up, floor and ceiling\n* Decimal number representation\n  * `Decimal` on top of `number` with limited precision of 15 digits\n  * `BigDecimal` for more precise numbers, with up to `Number.MAX_SAFE_INTEGER` digits\n  * Basic math operations: add, subtract, multiply, divide\n* Integer representation\n  * `Integer` for integers between `Number.MIN_SAFE_INTEGER` and `Number.MAX_SAFE_INTEGER`\n  * `BigInteger` for large integers\n\n## API\n\nIn this library all numeric types are immutable, so functions always return a \nnew instance. Each numeric type provides a limited API to support their\ncreation and basic use.\n\nOperations on the number types is provided as separate functions that can be \nimported. This design is to allow the library to take advantage of tree-shaking.\n\n* `static NumericType.fromNumber(value: number): NumericType`\n\n  Create an instance of the numeric type from a regular JavaScript number.\n\n* `static NumericType.parse(value: string): NumericType`\n\n  Create an instance of the numeric type from a string.\n\n* `numericType.toString(): string`\n\n  Turn the numeric type into a string representation supported by `fromString`.\n\n## `MathContext` and rounding\n\nThis library uses a class named `MathContext` to support operations such as\nsetting the scale or precision and rounding a number.\n\n```javascript\nimport { MathContext, RoundingMode } from 'numeric-types';\n\n// Create a context that requests 2 digits after the decimal using Half Up rounding\nconst contextWithScale = MathContext.ofScale(2, RoundingMode.HalfUp);\n\n// Context that requests at max 10 digits of precision\nconst contextWithPrecision = MathContext.ofPrecision(10, RoundingMode.Ceiling);\n```\n\n### Rounding modes\n\n* `RoundingMode.Down` - Round towards zero.\n* `RoundingMode.Up` - Round away from zero.\n* `RoundingMode.HalfDown` - Round towards the nearest neighbor, but if in the middle round towards zero.\n* `RoundingMode.HalfEven` - Round towards the nearest neighbor, but if in the middle round towards the even neighbor.\n* `RoundingMode.HalfUp` - Round towards the nearest neighbor, but if in the middle round away from zero.\n* `RoundingMode.Floor` - Round towards negative infinity.\n* `RoundingMode.Ceiling` - Round towards positive infinity.\n* `RoundingMode.Unnecessary` - Do not round, instead throw an error if rounding is required.\n\n## Type: Decimal\n\nDecimal is an implementation of a numeric type that avoids the rounding\nerrors common with floating point numbers. There are two versions, `Decimal`\nand `BigDecimal` where `Decimal` is limited to safely handling 15 digits and\n`BigDecimal` can handle up to `Number.MAX_SAFE_INTEGER` digits:\n\n```javascript\nimport { Decimal, multiply } from 'numeric-types/decimal';\n\nconst a = Decimal.fromNumber(0.1);\nconst b = Decimal.parse('12');\n\nconst ab = multiply(a, b);\nconsole.log(ab.toString());\n```\n\nTypes are available for TypeScript:\n\n```typescript\nimport { AbstractDecimal, Decimal } from 'numeric-types/decimal';\n\nconst decimal: AbstractDecimal\u003cany\u003e = Decimal.fromNumber(0.1);\n```\n\n### Operations\n\nThese operations are available from `numeric-types/decimal`. Import them\nseparately like:\n\n```javascript\nimport { operationHere, anotherOperation } from 'numeric-types/decimal';\n\nconst { operationHere, anotherOperation } = require('numeric-types/decimal');\n```\n\n* `compare(a: DecimalType, b: DecimalType): -1 | 0 | 1`\n\n  Compare two decimal numbers. This method will return `0` if the numbers are\n  the same, `-1` if `a` is less than `b` and `1` if `a` is greater than `b`.\n\n* `isEqual(a: DecimalType, b: DecimalType): boolean`\n\n  Get if two decimal numbers are equal.\n\n* `isLessThan(a: DecimalType, b: DecimalType): boolean`\n\n  Get if the decimal number `a` is less than the number `b`.\n\n* `isLessThanOrEqual(a: DecimalType, b: DecimalType): boolean`\n\n  Get if the decimal number `a` is less than or equal to the number `b`.\n\n* `isGreaterThan(a: DecimalType, b: DecimalType): boolean`\n\n  Get if the decimal number `a` is greater than the number `b`.\n\n* `isGreaterThanOrEqual(a: DecimalType, b: DecimalType): boolean`\n\n  Get if the decimal number `a` is greater than or equal to the number `b`.\n\n* `toString(a: DecimalType): string`\n\n  Turn a decimal numbers into its string representation.\n\n* `scale(a: DecimalType, context: MathContext): DecimalType`\n\n  Scale the given decimal number according to the specified context.\n\n* `round(a: DecimalType, roundingMode?: RoundingMode): DecimalType`\n\n  Round the given decimal number. If the rounding mode is not specified\n  `RoundingMode.HalfUp` is used. This is equivalent to calling `scale` with\n  `MathContext.ofScale(0, roundingMode)`.\n\n* `add(a: DecimalType, b: DecimalType, context?: MathContext): DecimalType`\n\n  Add two decimal numbers together, optionally specifying a context to be used\n  to adjust the scale of the result.\n\n* `subtract(a: DecimalType, b: DecimalType, context?: MathContext): DecimalType`\n  \n  Subtract a decimal number `b` from the number `a`. Optionally specify a\n  context to be used to adjust the scale of the result.\n\n* `multiply(a: DecimalType, b: DecimalType, context?: MathContext): DecimalType`\n\n  Multiply two decimal numbers together. Optionally specify a context to be\n  used to adjust the scale of the result.\n\n* `divide(a: DecimalType, b: DecimalType, context: MathContext): DecimalType`\n\n  Divide a decimal number `b` from the number `a`. A context is required to\n  determine the scale and how to round things.\n\n## Type: Integer\n\nInteger is an implementation of a whole number. There are currently two versions\navailable, `Integer` which is limited to the range of `number` and `BigInteger`\nwhich is can represent larger numbers.\n\n```javascript\nimport { Integer, multiply } from 'numeric-types/integer';\n\nconst a = Integer.fromNumber(20);\nconst b = Integer.parse('40');\n\nconst ab = multiply(a, b);\nconsole.log(ab.toString());\n```\n\nTypes are available for TypeScript:\n\n```typescript\nimport { AbstractInteger, Integer } from 'numeric-types/integer';\n\nconst integer: AbstractInteger\u003cany\u003e = Integer.fromNumber(1);\n```\n\n### Operations\n\nThese operations are available from `numeric-types/integer`. Import them\nseparately like:\n\n```javascript\nimport { operationHere, anotherOperation } from 'numeric-types/integer';\n\nconst { operationHere, anotherOperation } = require('numeric-types/integer');\n```\n\n* `compare(a: IntegerType, b: IntegerType): -1 | 0 | 1`\n\n  Compare two integers. This method will return `0` if the numbers are\n  the same, `-1` if `a` is less than `b` and `1` if `a` is greater than `b`.\n\n* `isEqual(a: IntegerType, b: IntegerType): boolean`\n\n  Get if two integers are equal.\n\n* `isLessThan(a: IntegerType, b: IntegerType): boolean`\n\n  Get if the integer `a` is less than the number `b`.\n\n* `isLessThanOrEqual(a: IntegerType, b: IntegerType): boolean`\n\n  Get if the integer `a` is less than or equal to the number `b`.\n\n* `isGreaterThan(a: IntegerType, b: IntegerType): boolean`\n\n  Get if the integer `a` is greater than the number `b`.\n\n* `isGreaterThanOrEqual(a: IntegerType, b: IntegerType): boolean`\n\n  Get if the integer `a` is greater than or equal to the number `b`.\n\n* `toString(a: IntegerType): string`\n\n  Turn a integers into its string representation.\n\n* `add(a: IntegerType, b: IntegerType): IntegerType`\n\n  Add two integers together.\n\n* `subtract(a: IntegerType, b: IntegerType): IntegerType`\n\n  Subtract `b` from `a`\n\n* `multiply(a: IntegerType, b: IntegerType): IntegerType`\n\n  Multiply two integers together.\n\n* `divide(a: IntegerType, b: IntegerType): IntegerType`\n\n  Divide `a` by the divisor `b`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faholstenson%2Fnumeric-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faholstenson%2Fnumeric-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faholstenson%2Fnumeric-types/lists"}