{"id":22021573,"url":"https://github.com/lamansky/enforce-range","last_synced_at":"2026-04-10T15:53:39.063Z","repository":{"id":57225290,"uuid":"113661055","full_name":"lamansky/enforce-range","owner":"lamansky","description":"[Node.js] Enforce a minimum and/or maximum value for a number.","archived":false,"fork":false,"pushed_at":"2017-12-09T14:04:50.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-28T16:45:11.909Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/lamansky.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-09T10:29:09.000Z","updated_at":"2017-12-09T14:05:13.000Z","dependencies_parsed_at":"2022-08-24T11:00:15.947Z","dependency_job_id":null,"html_url":"https://github.com/lamansky/enforce-range","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fenforce-range","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fenforce-range/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fenforce-range/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fenforce-range/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamansky","download_url":"https://codeload.github.com/lamansky/enforce-range/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245085069,"owners_count":20558327,"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":[],"created_at":"2024-11-30T06:13:00.066Z","updated_at":"2025-12-30T23:35:08.108Z","avatar_url":"https://github.com/lamansky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# enforce-range\n\nEnforce a minimum and/or maximum value for a number.\n\n## Installation\n\n```bash\nnpm install enforce-range --save\n```\n\n## Usage\n\n```javascript\nconst enforceRange = require('enforce-range')\n\n// Number should be between 0 and 100\nenforceRange(0, 100, 51) // 51\nenforceRange(0, 100, -123) // 0\nenforceRange(0, 100, 456) // 100\n```\n\n### Partial Application\n\nIf you provide only the first two arguments (a minimum and a maximum value), the module will create a partially-applied function which enforces that range. Here's the above example repeated with this usage mode:\n\n```javascript\nconst enforce0to100 = require('enforce-range')(0, 100)\n\n// Number should be between 0 and 100\nenforce0to100(51) // 51\nenforce0to100(-123) // 0\nenforce0to100(456) // 100\n```\n\n### Open-Ended Ranges\n\nIf, for some reason, you want this module to enforce a range that is only bound on one end, you can do so by passing `null` or ±`Infinity` as the minimum/maximum value. (However, in such a case you’re probably better off cutting the overhead of using a module and just using `Math.min()` or `Math.max()`.)\n\n```javascript\nconst enforceRange = require('enforce-range')\n\n// Maximum only\nenforceRange(null, 100, 200) // 100\nenforceRange(-Infinity, 100, 200) // 100\n\n// Minimum only\nenforceRange(0, null, 51) // 51\nenforceRange(0, Infinity, 51) // 51\n\n// No range enforcement at all (module does nothing)\nenforceRange(null, null, 12345) // 12345\nenforceRange(-Infinity, Infinity, 12345) // 12345\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fenforce-range","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamansky%2Fenforce-range","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fenforce-range/lists"}