{"id":17772613,"url":"https://github.com/jamesplease/quantize-number","last_synced_at":"2025-07-23T15:33:26.863Z","repository":{"id":57332312,"uuid":"49754995","full_name":"jamesplease/quantize-number","owner":"jamesplease","description":"Quantize a number","archived":false,"fork":false,"pushed_at":"2016-01-16T03:31:23.000Z","size":17,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-06T17:02:34.188Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/jamesplease.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-01-16T02:07:16.000Z","updated_at":"2023-05-16T21:15:54.000Z","dependencies_parsed_at":"2022-09-15T12:22:52.225Z","dependency_job_id":null,"html_url":"https://github.com/jamesplease/quantize-number","commit_stats":null,"previous_names":["jmeas/quantize-number"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jamesplease/quantize-number","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesplease%2Fquantize-number","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesplease%2Fquantize-number/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesplease%2Fquantize-number/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesplease%2Fquantize-number/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesplease","download_url":"https://codeload.github.com/jamesplease/quantize-number/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesplease%2Fquantize-number/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266704228,"owners_count":23971439,"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-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":[],"created_at":"2024-10-26T21:40:02.530Z","updated_at":"2025-07-23T15:33:26.810Z","avatar_url":"https://github.com/jamesplease.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# quantize-number\n\nQuantize a number\n\n[![Travis build status](http://img.shields.io/travis/jmeas/quantize-number.svg?style=flat)](https://travis-ci.org/jmeas/quantize-number)\n[![Code Climate](https://codeclimate.com/github/jmeas/quantize-number/badges/gpa.svg)](https://codeclimate.com/github/jmeas/quantize-number)\n[![Test Coverage](https://codeclimate.com/github/jmeas/quantize-number/badges/coverage.svg)](https://codeclimate.com/github/jmeas/quantize-number)\n[![Dependency Status](https://david-dm.org/jmeas/quantize-number.svg)](https://david-dm.org/jmeas/quantize-number)\n[![devDependency Status](https://david-dm.org/jmeas/quantize-number/dev-status.svg)](https://david-dm.org/jmeas/quantize-number#info=devDependencies)\n\n### About\n\nQuantization is an operation that takes some number and constrains it to a discrete\nset of numbers.\n\nFor instance, quantizing the value of 3 to the even numbers could yield either\n2 or 4. If the value of 4 is desired, then this library calls that a \"covering\" algorithm.\nIf the value of 2 is desired, then that is called a \"fitting\" algorithm.\n\nThis library provides a utility to quantize numbers using both types of algorithms.\n\n### Uses\n\nTwo use cases for quantization are varied, and include:\n\n1. Drag-to-resize user interfaces\n2. Infinite scroll algorithms\n\n#### Caveats\n\nThis library is generally unsuitable for quantum physics applications, as it\nrequires that the discrete set of numbers have even spacing between them.\n\n### Installation\n\nThe easiest way to install this library is through npm.\n\n```sh\nnpm install quantize-number\n```\n\nThen, import or require it into your library.\n\n```js\n// ES2015 syntax\nimport quantizeNumber from 'quantize-number';\n\n// CJS syntax\nvar quantizeNumber = require('quantize-number');\n```\n\nThis library exports UMD, so it works in the most popular JavaScript module\nenvironments, including ES2015, CommonJS, AMD, and also browser globals.\n\n### Usage\n\n##### `quantizeNumber( val, quantum [, options] )`\n\n- `val`: The number to be quantized\n- `quantum`: The gap between the discrete set numbers\n- `options`: There's currently only one option, `cover`, which accepts a Boolean\n  value. This determines whether the algorithm is covering or fitting (see below).\n\n### Examples\n\n```js\nquantizeNumber(9, 3) === 9;\n\nquantizeNumber(10, 4) === 8;\nquantizeNumber(10, 4, {\n  cover: true\n}) === 12;\n\nquantizeNumber(-77, 25) === -75;\n```\n\n### Covering vs. Fitting\n\nThe idea of covering vs. fitting is important to this library. Consider quantizing\nthe value of 78 to a quantum of 25. There are two choices: 75 or 100. If you want\nthe larger of the two choices, 100, then you want `cover: true`. Otherwise,\nyou want `cover: false`.\n\nThe same works for the negative numbers, too. If we have -78 and we're quantizing it\nagainst 25 (or -25), then `cover: true` would return -100, whereas `cover: false` would\nreturn -50.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesplease%2Fquantize-number","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesplease%2Fquantize-number","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesplease%2Fquantize-number/lists"}