{"id":23053569,"url":"https://github.com/component/enumerable","last_synced_at":"2025-07-30T01:34:09.991Z","repository":{"id":5085527,"uuid":"6247817","full_name":"component/enumerable","owner":"component","description":"Enumerable mixin","archived":false,"fork":false,"pushed_at":"2014-04-04T02:10:55.000Z","size":300,"stargazers_count":58,"open_issues_count":11,"forks_count":10,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-03T07:05:09.548Z","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":"p3/regal","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/component.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-16T16:51:20.000Z","updated_at":"2024-06-19T23:01:43.000Z","dependencies_parsed_at":"2022-08-26T22:50:14.073Z","dependency_job_id":null,"html_url":"https://github.com/component/enumerable","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/component/enumerable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fenumerable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fenumerable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fenumerable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fenumerable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/component","download_url":"https://codeload.github.com/component/enumerable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fenumerable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267792737,"owners_count":24144931,"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-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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-12-16T00:18:40.442Z","updated_at":"2025-07-30T01:34:09.963Z","avatar_url":"https://github.com/component.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enumerable\n\n  Enumerable mixin.\n\n```js\nusers\n  .map('friends')\n  .select('age \u003e 20')\n  .map('name.first')\n  .select(/^T/)\n```\n\n## Installation\n\n    $ component install component/enumerable\n\n## Implementation\n\n  Nearly all methods utilize the [to-function](https://github.com/component/to-function)\n  component, which converts the argument passed to a function. For example\n  `.map('name.first')` expands to a function effectively defined as `return obj.name.first`,\n  likewise `.select(/^Tobi/)` expands to `return /^Tobi/.test(str)` and so on. For details\n  check out to-function's Readme and familiarize yourself since all of that is applicable\n  to Enumerable.\n\n## API\n\n  - [mixin()](#mixin)\n  - [.each()](#eachfnfunction)\n  - [.map()](#mapfnfunction)\n  - [.select()](#selectfnfunctionstring)\n  - [.unique()](#unique)\n  - [.reject()](#rejectfnfunctionstringmixed)\n  - [.compact()](#compact)\n  - [.find()](#findfnfunction)\n  - [.findLast()](#findlastfnfunction)\n  - [.none()](#nonefnfunctionstring)\n  - [.any()](#anyfnfunction)\n  - [.count()](#countfnfunction)\n  - [.indexOf()](#indexofobjmixed)\n  - [.has()](#hasobjmixed)\n  - [.reduce()](#reducefnfunctionvalmixed)\n  - [.max()](#maxfnfunctionstring)\n  - [.sum()](#sumfnfunctionstring)\n  - [.first()](#firstnnumberfunction)\n  - [.last()](#lastnnumberfunction)\n  - [.inGroupsOf()](#ingroupsofnnumber)\n  - [.at()](#atinumber)\n  - [.value()](#value)\n\n### mixin()\n\n  Mixin to `obj`.\n\n```js\n var Enumerable = require('enumerable');\n Enumerable(Something.prototype);\n```\n\n### .each(fn:Function)\n\n  Iterate each value and invoke `fn(val, i)`.\n\n```js\n users.each(function(val, i){\n\n })\n```\n\n### .map(fn:Function)\n\n  Map each return value from `fn(val, i)`.\n\n  Passing a callback function:\n\n```js\n users.map(function(user){\n   return user.name.first\n })\n```\n\n\n  Passing a property string:\n\n```js\n users.map('name.first')\n```\n\n### .select(fn:Function|String)\n\n  Select all values that return a truthy value of `fn(val, i)`.\n\n```js\n users.select(function(user){\n   return user.age \u003e 20\n })\n```\n\n\n   With a property:\n\n```js\n items.select('complete')\n```\n\n### .unique()\n\n  Select all unique values.\n\n```js\n nums.unique()\n```\n\n### .reject(fn:Function|String|Mixed)\n\n  Reject all values that return a truthy value of `fn(val, i)`.\n\n  Rejecting using a callback:\n\n```js\n users.reject(function(user){\n   return user.age \u003c 20\n })\n```\n\n\n  Rejecting with a property:\n\n```js\n items.reject('complete')\n```\n\n\n  Rejecting values via `==`:\n\n```js\n data.reject(null)\n users.reject(toni)\n```\n\n### .compact()\n\n  Reject `null` and `undefined`.\n\n```js\n [1, null, 5, undefined].compact()\n // =\u003e [1,5]\n```\n\n### .find(fn:Function)\n\n  Return the first value when `fn(val, i)` is truthy,\n  otherwise return `undefined`.\n\n```js\n users.find(function(user){\n   return user.role == 'admin'\n })\n```\n\n### .findLast(fn:Function)\n\n  Return the last value when `fn(val, i)` is truthy,\n  otherwise return `undefined`.\n\n```js\n users.findLast(function(user){\n   return user.role == 'admin'\n })\n```\n\n### .none(fn:Function|String)\n\n  Assert that none of the invocations of `fn(val, i)` are truthy.\n\n  For example ensuring that no pets are admins:\n\n```js\n pets.none(function(p){ return p.admin })\n pets.none('admin')\n```\n\n### .any(fn:Function)\n\n  Assert that at least one invocation of `fn(val, i)` is truthy.\n\n  For example checking to see if any pets are ferrets:\n\n```js\n pets.any(function(pet){\n   return pet.species == 'ferret'\n })\n```\n\n### .count(fn:Function)\n\n  Count the number of times `fn(val, i)` returns true.\n\n```js\n var n = pets.count(function(pet){\n   return pet.species == 'ferret'\n })\n```\n\n### .indexOf(obj:Mixed)\n\n  Determine the indexof `obj` or return `-1`.\n\n### .has(obj:Mixed)\n\n  Check if `obj` is present in this enumerable.\n\n### .reduce(fn:Function, [val]:Mixed)\n\n  Reduce with `fn(accumulator, val, i)` using\n  optional `init` value defaulting to the first\n  enumerable value.\n\n### .max(fn:Function|String)\n\n  Determine the max value.\n\n  With a callback function:\n\n```js\n pets.max(function(pet){\n   return pet.age\n })\n```\n\n\n  With property strings:\n\n```js\n pets.max('age')\n```\n\n\n  With immediate values:\n\n```js\n nums.max()\n```\n\n### .sum(fn:Function|String)\n\n  Determine the sum.\n\n  With a callback function:\n\n```js\n pets.sum(function(pet){\n   return pet.age\n })\n```\n\n\n  With property strings:\n\n```js\n pets.sum('age')\n```\n\n\n  With immediate values:\n\n```js\n nums.sum()\n```\n\n### .first([n]:Number|Function)\n\n  Return the first value, or first `n` values.\n\n### .last([n]:Number|Function)\n\n  Return the last value, or last `n` values.\n\n### .inGroupsOf(n:Number)\n\n  Return values in groups of `n`.\n\n### .at(i:Number)\n\n  Return the value at the given index.\n\n### .value()\n\n  Return the enumerable value.\n\n## License\n\n  MIT\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomponent%2Fenumerable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomponent%2Fenumerable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomponent%2Fenumerable/lists"}