{"id":20497238,"url":"https://github.com/alexcambose/advmap","last_synced_at":"2025-04-13T18:22:52.636Z","repository":{"id":46940252,"uuid":"153017215","full_name":"alexcambose/advmap","owner":"alexcambose","description":"[...].map() that supports skip, limit, step and more","archived":false,"fork":false,"pushed_at":"2023-01-04T15:35:38.000Z","size":714,"stargazers_count":3,"open_issues_count":10,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-21T04:21:14.849Z","etag":null,"topics":["array","improved","javascript","mapping","object","pagination","prototype"],"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/alexcambose.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":"2018-10-14T20:43:55.000Z","updated_at":"2023-08-18T15:17:59.000Z","dependencies_parsed_at":"2023-02-02T18:02:43.752Z","dependency_job_id":null,"html_url":"https://github.com/alexcambose/advmap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcambose%2Fadvmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcambose%2Fadvmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcambose%2Fadvmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcambose%2Fadvmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexcambose","download_url":"https://codeload.github.com/alexcambose/advmap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248759135,"owners_count":21157096,"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":["array","improved","javascript","mapping","object","pagination","prototype"],"created_at":"2024-11-15T18:10:28.548Z","updated_at":"2025-04-13T18:22:52.615Z","avatar_url":"https://github.com/alexcambose.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# advmap\n\n[![Build Status](https://travis-ci.org/alexcambose/advmap.svg?branch=master)](https://travis-ci.org/alexcambose/advmap)\n[![Coverage Status](https://coveralls.io/repos/github/alexcambose/advmap/badge.svg?branch=master)](https://coveralls.io/github/alexcambose/advmap?branch=master)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/Naereen/StrapDown.js/blob/master/LICENSE)\n\n`[...].map()` that supports skip, limit, step and more\n\n![logo](logo.png)\n\n## Installation\n\nAs [npm](https://www.npmjs.com/package/advmap) package\n\n```\nnpm i -S advmap\n```\n\nImporting the module. It will automatically add a method to the [array prototype](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype).\n\n```js\nrequire('advmap');\n// or\nimport 'advmap';\n```\n\n# Table of Contents\n\n- [Configuration](#configuration)\n\n  - [Skip](#skip)\n  - [Limit](#limit)\n  - [Step](#step)\n  - [previousParamsCount](#previous-params)\n  - [nextParamsCount](#next-params)\n\n- [Filtering](#filtering)\n- [Examples](#examples)\n\n## Configuration\n\n### Skip\n\n`skip` controls how many items to skip before returning results\n\nExample:\n\n```js\nconst array = [1, 2, 3, 4, 5].advmap(e =\u003e e, { skip: 2 });\nconsole.log(array); // [3, 4, 5]\n```\n\n### Limit\n\n`limit` controls the maximum number of items returned\n\nExample:\n\n```js\nconst array = [1, 2, 3, 4, 5].advmap(e =\u003e e, { limit: 2 });\nconsole.log(array); // [1, 2]\n```\n\nit can be nicely combined with the `skip` property to create a pagination\n\n```js\nconst array = [1, 2, 3, 4, 5].advmap(e =\u003e e, { limit: 2, skip: 2 });\nconsole.log(array); // [3, 4]\n```\n\n### Step\n\ncontrols the interval between two adjacent elements\n\n```js\nconst array = [1, 2, 3, 4, 5].advmap(e =\u003e e, { step: 2 });\nconsole.log(array); // [1, 3, 5]\n\n// if step is bigger than the array length it returns only the first element\nconst array = [1, 2, 3, 4, 5].advmap(e =\u003e e, { step: 10 });\nconsole.log(array); // [1]\n```\n\nit also provides an additional index parameter that is the actual array index that is being mapped\n\n```js\n[1, 2, 3, 4, 5].advmap((e, i, ii) =\u003e console.log(e, i, ii), { step: 2 });\n/*\nlast parameter is where the item (e) is located in the array\n[1, 0, 0]\n[3, 1, 2]\n[5, 2, 4]\n*/\n[1, 2, 3, 4, 5].advmap((e, i, ii) =\u003e console.log(e, i, ii), { step: 1 });\n/*\nIf step is set to 1 (default) index parameters will be the same\n[1, 0, 0]\n[2, 1, 1]\n[3, 2, 2]\n[4, 3, 3]\n[5, 4, 4]\n*/\n```\n\n### Previous params\n\nadds a number of fixed parameters to the `advmap` method, before the current element\n\n```js\n[1, 2, 3, 4, 5].advmap((p2, p1, e) =\u003e console.log(p2, p1, e), {\n  previousParamsCount: 2,\n});\n/*\n[undefined, undefined, 1]\n[undefined, 1, 2]\n[1, 2, 3]\n[2, 3, 4]\n[3, 4, 5]\n*/\n```\n\nelements that are outsite of the array are `undefined`\n\n### Next params\n\nadds a number of fixed parameters to the `advmap` method, after the current element\n\n```js\n[1, 2, 3, 4, 5].advmap((e, p1, p2) =\u003e console.log(e, p1, p2), {\n  nextParamsCount: 2,\n});\n/*\n[1, 2, 3]\n[2, 3, 4]\n[3, 4, 5]\n[4, 5, undefined]\n[5, undefined, undefined]\n*/\n```\n\nelements that are outsite of the array are `undefined`\n\n### Previous and next params combined\n\n```js\n[1, 2, 3, 4, 5].advmap((p1, e, n2, n1) =\u003e console.log(p1, e, n2, n1), {\n  previousParamsCount: 1,\n  nextParamsCount: 2,\n});\n/*\n[undefined, 1, 2, 3]\n[1, 2, 3, 4]\n[2, 3, 4, 5]\n[3, 4, 5, undefined]\n[4, 5, undefined, undefined]\n*/\n```\n\n## Filtering\n\n**advmap** provides an additional parameter that can be used to check if the current element, index etc.. respects a particular condition\n\n```js\n[1, 2, 3, 4, 5].advmap(e =\u003e e \u003e 2 \u0026\u0026 e \u003c 4, e =\u003e e + ' apples');\n// [ '3 apples' ]\n```\n\nit also has all the arguments that the main map function has\n\n```js\n[0, 2, 3, 1, 5].advmap(\n  (p1, e, n1) =\u003e p1 \u003e e \u0026\u0026 e \u003c n1,\n  (p1, e) =\u003e e + ' is between two bigger numbers',\n  {\n    previousParamsCount: 1,\n    nextParamsCount: 1,\n  }\n);\n// [ '1 is between two bigger numbers' ]\n```\n\n## Examples\n\n### Simple usage like the native `[].map` function\n\n```js\nconst array = [1, 2, 3, 4].advmap(e =\u003e e + 1);\nconsole.log(array); // [2,3,4,5]\n```\n\nGenerate the next number in a [fibonacci sequence](https://en.wikipedia.org/wiki/Fibonacci_number)\n\n```js\nlet array = [1, 1];\nconst nextNumber = () =\u003e\n  array.advmap((p1, e, n1) =\u003e (p1 ? p1 + e : n1), {\n    previousParamsCount: 1,\n    nextParamsCount: 1,\n  });\narray = nextNumber(); // [1, 2]\narray = nextNumber(); // [2, 3]\narray = nextNumber(); // [3, 5]\narray = nextNumber(); // [5, 8]\narray = nextNumber(); // [8, 13]\n```\n---\n\n#### Find this module useful ? Give it a :star: !\n\n---\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexcambose%2Fadvmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexcambose%2Fadvmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexcambose%2Fadvmap/lists"}