{"id":28414812,"url":"https://github.com/eliottvincent/joi-decimal","last_synced_at":"2025-06-25T09:31:26.409Z","repository":{"id":35034782,"uuid":"198501498","full_name":"eliottvincent/joi-decimal","owner":"eliottvincent","description":"🔢 Joi extension for Decimal type","archived":false,"fork":false,"pushed_at":"2022-02-12T10:25:40.000Z","size":232,"stargazers_count":2,"open_issues_count":10,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-03T20:19:26.958Z","etag":null,"topics":["decimal","decimaljs","extension","float","joi","schema","validation"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eliottvincent.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}},"created_at":"2019-07-23T20:13:05.000Z","updated_at":"2023-02-22T15:22:03.000Z","dependencies_parsed_at":"2022-08-08T04:01:01.787Z","dependency_job_id":null,"html_url":"https://github.com/eliottvincent/joi-decimal","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/eliottvincent/joi-decimal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliottvincent%2Fjoi-decimal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliottvincent%2Fjoi-decimal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliottvincent%2Fjoi-decimal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliottvincent%2Fjoi-decimal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eliottvincent","download_url":"https://codeload.github.com/eliottvincent/joi-decimal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliottvincent%2Fjoi-decimal/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261844444,"owners_count":23218350,"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":["decimal","decimaljs","extension","float","joi","schema","validation"],"created_at":"2025-06-03T10:45:08.401Z","updated_at":"2025-06-25T09:31:26.398Z","avatar_url":"https://github.com/eliottvincent.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# joi-decimal\n\nJoi extension for Decimal type.\n\nUseful to validate any scientific / financial number.\n\n⚠️ do not use `.precision()` for now as it doesn't work as expected.\nIt will be fixed in v1.2.0.\n\n[![Build Status](https://travis-ci.com/eliottvincent/joi-decimal.svg?branch=master)](https://travis-ci.com/eliottvincent/joi-decimal)\n[![npm version](https://badge.fury.io/js/joi-decimal.svg)](http://badge.fury.io/js/joi-decimal)\n\n\n## Usage\n\n```js\nconst BaseJoi = require('@hapi/joi');\nconst DecimalExtension = require('joi-decimal');\nconst Joi = BaseJoi.extend(DecimalExtension);\n\nconst schema = Joi.decimal().greater(100.0);\n\nconst result = schema.validate(101.00);\n// result.error === null -\u003e valid\n```\n\n## API\n\n- [`decimal` - inherits from `Any`](#decimal---inherits-from-any)\n    - [`decimal.finite()`](#decimalfinite)\n    - [`decimal.greater(limit)`](#decimalgreaterlimit)\n    - [`decimal.integer()`](#decimalinteger)\n    - [`decimal.less(limit)`](#decimallesslimit)\n    - [`decimal.max(limit)`](#decimalmaxlimit)\n    - [`decimal.min(limit)`](#decimalminlimit)\n    - [`decimal.multiple(base)`](#decimalmultiplebase)\n    - [`decimal.nan()`](#decimalnan)\n    - [`decimal.negative()`](#decimalnegative)\n    - [`decimal.positive()`](#decimalpositive)\n    - [`decimal.precision(sd, rm)`](#decimalprecisionsd-rm)\n    - [`decimal.zero()`](#decimalzero)\n- [List of errors](#list-of-errors)\n  - [`decimal.base`](#decimalbase)\n  - [`decimal.finite`](#decimalfinite-1)\n  - [`decimal.greater`](#decimalgreater)\n  - [`decimal.integer`](#decimalinteger-1)\n  - [`decimal.less`](#decimalless)\n  - [`decimal.max`](#decimalmax)\n  - [`decimal.min`](#decimalmin)\n  - [`decimal.multiple`](#decimalmultiple)\n  - [`decimal.nan`](#decimalnan-1)\n  - [`decimal.negative`](#decimalnegative-1)\n  - [`decimal.positive`](#decimalpositive-1)\n  - [`decimal.precision`](#decimalprecision)\n  - [`decimal.ref`](#decimalref)\n  - [`decimal.zero`](#decimalzero-1)\n\n\n### `decimal` - inherits from `Any`\n\nGenerates a schema object that matches a Decimal type (as well as a JavaScript string or number that can be converted to Decimal type). If\nthe validation `convert` option is on (enabled by default), a string or number will be converted to a `Decimal`, if specified.\nAlso, if\n`convert` is on and `decimal.precision()` is used, the value will be converted to the specified `precision` as well.\n\n\n```js\nconst dec = Joi.decimal();\ndec.validate('0.046875', (err, value) =\u003e { });\n```\n\nPossible validation errors: [`decimal.base`](#decimalbase)\n\n\n#### `decimal.finite()`\n\nRequires the number to be finite.\n\n```js\nconst schema = Joi.decimal().finite();\n```\n\nPossible validation errors: [`decimal.finite`](#decimalfinite-1)\n\n\n#### `decimal.greater(limit)`\n\nSpecifies that the value must be greater than `limit` or a reference.\n\n```js\nconst schema = Joi.decimal().greater(5.000);\n```\n\n```js\nconst schema = Joi.object({\n  min: Joi.decimal().required(),\n  max: Joi.decimal().greater(Joi.ref('min')).required()\n});\n```\n\nPossible validation errors: [`decimal.greater`](#decimalgreater), [`decimal.ref`](#decimalref)\n\n\n#### `decimal.integer()`\n\nRequires the number to be an integer (no floating point).\n\n```js\nconst schema = Joi.decimal().integer();\n```\n\nPossible validation errors: [`decimal.integer`](#decimalinteger)\n\n\n#### `decimal.less(limit)`\n\nSpecifies that the value must be less than `limit` or a reference.\n\n```js\nconst schema = Joi.decimal().less(10);\n```\n\n```js\nconst schema = Joi.object({\n  min: Joi.decimal().less(Joi.ref('max')).required(),\n  max: Joi.decimal().required()\n});\n```\n\nPossible validation errors: [`decimal.less`](#decimalless), [`decimal.ref`](#decimalref)\n\n\n#### `decimal.max(limit)`\n\nSpecifies the maximum value where:\n- `limit` - the maximum value allowed or a reference.\n\n```js\nconst schema = Joi.decimal().max(10);\n```\n\n```js\nconst schema = Joi.object({\n  min: Joi.decimal().max(Joi.ref('max')).required(),\n  max: Joi.decimal().required()\n});\n```\n\nPossible validation errors: [`decimal.max`](#decimalmax), [`decimal.ref`](#decimalref)\n\n\n#### `decimal.min(limit)`\n\nSpecifies the minimum value where:\n- `limit` - the minimum value allowed or a reference.\n\n```js\nconst schema = Joi.decimal().min(2);\n```\n\n```js\nconst schema = Joi.object({\n  min: Joi.decimal().required(),\n  max: Joi.decimal().min(Joi.ref('min')).required()\n});\n```\n\nPossible validation errors: [`decimal.min`](#decimalmin), [`decimal.ref`](#decimalref)\n\n\n#### `decimal.multiple(base)`\n\nSpecifies that the value must be a multiple of `base` (or a reference):\n\n```js\nconst schema = Joi.decimal().multiple(3);\n```\n\nPossible validation errors: [`decimal.multiple`](#decimalmultiple), [`decimal.ref`](#decimalref)\n\n\n#### `decimal.nan()`\n\nRequires the number to be NaN.\n\n```js\nconst schema = Joi.decimal().nan();\n```\n\nPossible validation errors: [`decimal.nan`](#decimalnan-1)\n\n\n#### `decimal.negative()`\n\nRequires the number to be negative.\n\n```js\nconst schema = Joi.decimal().negative();\n```\n\nPossible validation errors: [`decimal.negative`](#decimalnegative-1)\n\n\n#### `decimal.positive()`\n\nRequires the number to be positive.\n\n```js\nconst schema = Joi.decimal().positive();\n```\n\nPossible validation errors: [`decimal.positive`](#decimalpositive-1)\n\n\n#### `decimal.precision(sd, rm)`\n\nSpecifies the maximum precision where:\n- `sd` - the number of significant digits on which to round.\n- `rm` - the rounding mode to use.\n\n```js\nconst schema = Joi.decimal().precision(2, 5);\n```\n\nPossible validation errors: [`decimal.precision`](#decimalprecision)\n\n\n#### `decimal.zero()`\n\nRequires the number to be zero.\n\n```js\nconst schema = Joi.decimal().zero();\n```\n\nPossible validation errors: [`decimal.zero`](#decimalzero-1)\n\n\n\n### List of errors\n\n#### `decimal.base`\n\nThe value is not a Decimal or could not be cast to a Decimal.\n\n\n#### `decimal.finite`\n\nThe number was not finite.\n\n\n#### `decimal.greater`\n\nThe number is lower or equal to the limit that you set.\n\nAdditional local context properties:\n```ts\n{\n    limit: number // Minimum value that was expected for this number\n}\n```\n\n\n#### `decimal.integer`\n\nThe number is not a valid integer.\n\n\n#### `decimal.less`\n\nThe number is higher or equal to the limit that you set.\n\nAdditional local context properties:\n```ts\n{\n    limit: number // Maximum value that was expected for this number\n}\n```\n\n\n#### `decimal.max`\n\nThe number is higher than the limit that you set.\n\nAdditional local context properties:\n```ts\n{\n    limit: number // Maximum value that was expected for this number\n}\n```\n\n#### `decimal.min`\n\nThe number is lower than the limit that you set.\n\nAdditional local context properties:\n```ts\n{\n    limit: number // Minimum value that was expected for this number\n}\n```\n\n\n#### `decimal.multiple`\n\nThe number could not be divided by the base you provided.\n\nAdditional local context properties:\n```ts\n{\n    base: number // The number of which the input is supposed to be a multiple of\n}\n```\n\n\n#### `decimal.nan`\n\nThe number is not NaN.\n\n\n#### `decimal.negative`\n\nThe number was positive.\n\n\n#### `decimal.positive`\n\nThe number was negative.\n\n\n#### `decimal.precision`\n\nThe arguments (`sd` and/or `rm`) are not numbers.\n\n\n#### `decimal.ref`\n\nA reference was used in one of [`decimal.greater()`](#decimalgreaterlimit), [`decimal.less()`](#decimallesslimit), [`decimal.max()`](#decimalmaxlimit), [`decimal.min()`](#decimalminlimit) or [`decimal.multiple()`](#decimalmultiplebase) and the value pointed to by that reference in the input is not a valid Decimal or could not be cast to a Decimal.\n\n\n#### `decimal.zero`\n\nThe number is not zero.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliottvincent%2Fjoi-decimal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feliottvincent%2Fjoi-decimal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliottvincent%2Fjoi-decimal/lists"}