{"id":15698994,"url":"https://github.com/pgilad/array-scaler","last_synced_at":"2025-03-30T14:25:39.665Z","repository":{"id":22425810,"uuid":"25763684","full_name":"pgilad/array-scaler","owner":"pgilad","description":"Scale an array preserving order to a discrete or continuous scale","archived":false,"fork":false,"pushed_at":"2015-05-22T17:14:30.000Z","size":212,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-20T23:42:03.995Z","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/pgilad.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":"2014-10-26T08:30:19.000Z","updated_at":"2014-12-29T09:24:32.000Z","dependencies_parsed_at":"2022-08-20T17:01:00.559Z","dependency_job_id":null,"html_url":"https://github.com/pgilad/array-scaler","commit_stats":null,"previous_names":["pgilad/scaler"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgilad%2Farray-scaler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgilad%2Farray-scaler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgilad%2Farray-scaler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgilad%2Farray-scaler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgilad","download_url":"https://codeload.github.com/pgilad/array-scaler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246329704,"owners_count":20759935,"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-10-03T19:37:17.838Z","updated_at":"2025-03-30T14:25:39.647Z","avatar_url":"https://github.com/pgilad.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# array-scaler [![Build Status](http://img.shields.io/travis/pgilad/array-scaler.svg?style=flat)](https://travis-ci.org/pgilad/array-scaler)\n\n\u003e Scale an array preserving order to a discrete or continuous scale\n\n## Install\n\n```bash\n$ npm install --save array-scaler\n```\n\n## Usage\n\n```js\nvar scaler = require('array-scaler');\nvar scaledArray;\n\n// scale a simple array with default step = 1\nscaledArray = scaler.scale([1, 2, 5], {\n        min: 1\n});\nconsole.log(scaledArray);\n//=\u003e [1, 2, 3]\n\n// scale a simple array with a custom step\nscaledArray = scaler.scale([1, 2, 5]), {\n        min: 1,\n        step: 2\n});\nconsole.log(scaledArray);\n//=\u003e [1, 3, 5]\n\n// provide max value to validate fitting (using unique items)\nscaledArray = scaler.scale([1, 2, 5]), {\n        min: 1,\n        max: 2\n});\n//=\u003e Error: Count of unique items (3) is more than spread (2) / step (1)\n\n// works with negative numbers and negative range\nscaledArray = scaler.scale([-10, 5, -1]), {\n        min: -5,\n        step: 1\n});\nconsole.log(scaledArray);\n//=\u003e [-5, -3, -4]\n\n// Get a continuous scale\nscaledArray = scaler.scale([1, 2, 5], {\n        min: 1,\n        max: 3,\n        continuous: true\n});\nconsole.log(scaledArray);\n//=\u003e [1, 1.5, 3]\n```\n\n## API\n\n### .scale(array, params)\n\n#### array\n\nType: `array` **required**\n\nThe array you want to scale\n\n#### params\n\n##### min\n\nType: `number` **required**\n\nThe minimum number to start the scale with.\n\n##### max\n\nType: `number`\n\nDefault: `Infinity`\n\nThe maximum number to fit the scale into.\nIf supplied - validation will be done to make sure the number of unique items in the array will fit the range.\n\n##### continuous\n\nType: `boolean`\n\nDefault: `false`\n\nWhether to use a `continuous` scale. Default is to use a `discrete` scale.\n\n##### step\n\nType: `number`\n\nDefault: `1`\n\nStep to use when scaling in `discrete` mode. Has no effect in `continuous` mode.\n\n## License\n\nMIT @[Gilad Peleg](http://giladpeleg.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgilad%2Farray-scaler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgilad%2Farray-scaler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgilad%2Farray-scaler/lists"}