{"id":19201464,"url":"https://github.com/padcom/array-prototype-functions","last_synced_at":"2026-03-11T12:24:47.785Z","repository":{"id":55110329,"uuid":"327688349","full_name":"padcom/array-prototype-functions","owner":"padcom","description":"Array prototype augmentation for easier arithmetic and overall pleasure!","archived":false,"fork":false,"pushed_at":"2022-03-17T00:14:19.000Z","size":572,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-15T11:29:16.435Z","etag":null,"topics":["javascript","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/padcom.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":"2021-01-07T18:03:10.000Z","updated_at":"2024-09-19T01:12:18.000Z","dependencies_parsed_at":"2022-08-14T12:20:22.164Z","dependency_job_id":null,"html_url":"https://github.com/padcom/array-prototype-functions","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/padcom/array-prototype-functions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padcom%2Farray-prototype-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padcom%2Farray-prototype-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padcom%2Farray-prototype-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padcom%2Farray-prototype-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/padcom","download_url":"https://codeload.github.com/padcom/array-prototype-functions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padcom%2Farray-prototype-functions/sbom","scorecard":{"id":717589,"data":{"date":"2025-08-11","repo":{"name":"github.com/padcom/array-prototype-functions","commit":"d9a5cca4730e108ca916117eb22bbcddc172feec"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.5,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/main.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/padcom/array-prototype-functions/main.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/padcom/array-prototype-functions/main.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/padcom/array-prototype-functions/main.yml/master?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/main.yml:20","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 1 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"25 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-22T10:11:12.057Z","repository_id":55110329,"created_at":"2025-08-22T10:11:12.057Z","updated_at":"2025-08-22T10:11:12.057Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30380940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["javascript","typescript"],"created_at":"2024-11-09T12:38:54.099Z","updated_at":"2026-03-11T12:24:47.763Z","avatar_url":"https://github.com/padcom.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/padcom/array-prototype-functions/actions?query=workflow%3Abuild\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/workflow/status/padcom/array-prototype-functions/build?logo=github\u0026sanitize=true\" alt=\"Build status\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://coveralls.io/github/padcom/array-prototype-functions\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/coveralls/github/padcom/array-prototype-functions?logo=coveralls\u0026sanitize=true\" alt=\"Code coverage\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/padcom/array-prototype-functions/issues\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/issues/padcom/array-prototype-functions?logo=github\u0026sanitize=true\" alt=\"Issues\"\u003e\n  \u003c/a\u003e\n  \u003c!--\u003cimg src=\"https://img.shields.io/github/languages/top/padcom/array-prototype-functions?logo=typescript\u0026logoColor=yellow\u0026sanitize=true\"\u003e--\u003e\n  \u003ca href=\"https://raw.githubusercontent.com/padcom/array-prototype-functions/master/LICENSE\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/padcom/array-prototype-functions?logo=apache\u0026sanitize=true\" alt=\"License\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/array-prototype-functions\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/package-json/v/padcom/array-prototype-functions?logo=npm\u0026sanitize=true\" alt=\"Current version\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/array-prototype-functions\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dm/array-prototype-functions?logo=npm\u0026sanitize=true\" alt=\"Downloads\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n# Array prototype functions\n\nThe API for arrays in JavaScript is quite vast. Functions such as `filter()`, `map()` and `reduce()` are quite powerful. The only problem with them is that they are very very generic.\n\nThe purpose of this library is to augment the `Array.prototype` to provide functions that have a more distinct meaning, such as finding the min or max value in an array or grouping an array of objects by the key.\n\nI wrote those functions far too many times and have gotten sick maintaining them throughout multiple projects.\n\n## Usage\n\nThe usage is dead simple. Just import the package and you're done:\n\n```\n// ES6 module\nimport 'array-prototype-functions/avg'\nimport 'array-prototype-functions/first'\nimport 'array-prototype-functions/group-by'\nimport 'array-prototype-functions/group-by-as-map'\nimport 'array-prototype-functions/head'\nimport 'array-prototype-functions/last'\nimport 'array-prototype-functions/max'\nimport 'array-prototype-functions/median'\nimport 'array-prototype-functions/min'\nimport 'array-prototype-functions/pluck'\nimport 'array-prototype-functions/sort-by'\nimport 'array-prototype-functions/static'\nimport 'array-prototype-functions/sum'\nimport 'array-prototype-functions/tail'\nimport 'array-prototype-functions/uniq'\n\n// node.js\nrequire('array-prototype-functions/avg')\nrequire('array-prototype-functions/first')\nrequire('array-prototype-functions/group-by')\nrequire('array-prototype-functions/group-by-as-map')\nrequire('array-prototype-functions/head')\nrequire('array-prototype-functions/last')\nrequire('array-prototype-functions/max')\nrequire('array-prototype-functions/median')\nrequire('array-prototype-functions/min')\nrequire('array-prototype-functions/pluck')\nrequire('array-prototype-functions/sort-by')\nrequire('array-prototype-functions/static')\nrequire('array-prototype-functions/sum')\nrequire('array-prototype-functions/tail')\nrequire('array-prototype-functions/uniq')\n```\n\nPlease be aware that there are some dependencies between the imported functions (see below in the API section). You will need to import the dependencies yourself.\n\nOnce the file is executed the `Array.prototype` is automatically augmented.\n\nPlease note that if the functions are already present they will not be overriden! This means that if at any point in time the `Array.prototype` will gain functions like `head`, `tail` or any other that is provided by this library they will take precedense over the ones from this library.\n\n## Why augmenting the `Array.prototype`?\n\nThe question you might be asking is why do I augment the prototype instead of providing standalone functions that would do the same? The reason for it is simple: readability of the code that uses them. Here are a few examples:\n\n```\nconst a = [ 1, 2, 3, 4 ]\n\na.filter(x =\u003e x % 2 == 0).sum()\na.filter(x =\u003e x % 2 == 0).avg()\na.filter(x =\u003e x % 2 == 0).median()\n\nconst a = [ { x: 1 }, { x: 2 } ]\na.sum('x')\n```\n\nThis way the built-in functions can directly be the source and the syntax flows nicely with the rest of the code.\n\n## API\n\n### `Array.prototype.head()`\n\nDependencies: none\n\nReturns the first element of the array or null if the array is empty.\n\n### `Array.prototype.tail()`\n\nDependencies: none\n\nReturns all elements of the array besides the first element. Returns an empty array if the original array was empty or had just one element.\n\n### `Array.prototype.first(n = null)`\n\nDependencies: none\n\nReturns the first element of the array or null if the array is empty. If the `n` parameter is given it returns an array of `n` or less elements (if the array doesn't contain as many elements to begin with)\n\n### `Array.prototype.last(n = null)`\n\nDependencies: none\n\nReturns the last element of the array or null if the array is empty. If the `n` parameter is given it returns an array of `n` or less elements (if the array doesn't contain as many elements to begin with)\n\n### `Array.prototype.sum(fieldOrMapper = null)`\n\nDependencies: none\n\nReturns a sum of elements in the array. The `fieldOrMapper` can be one of:\n- null (or not provided) which means the elements will be treated as sumable\n- string - in which case it will be a name of field to extract from the objects in the array and then to sum them up\n- a function that takes the array element as parameter and shall return a sum-able value\n\n### `Array.prototype.avg(fieldOrMapper = null)`\n\nDependencies: `sum`\n\nReturns an average of values from the array (sum of all divided by the number of elements). Returns null if the array was empty. The `fieldOrMapper` can be one of:\n- null (or not provided) which means the elements will be treated as sum-able\n- string - in which case it will be a name of field to extract from the objects in the array and then to sum them up\n- a function that takes the array element as parameter and shall return a sum-able value\n\n### `Array.prototype.pluck(fieldOrMapper)`\n\nDependencies: `none`\n\nReturns an array containing objects having a subset of properties of the original elements of the array. The `fieldOrMapper` can be one of:\n- string - in which case it will be a name of field to extract from the objects in the array\n- a function that takes the array element as parameter and shall return the values to pluck\n\n### `Array.prototype.sortBy(fieldOrMapper = null, order = 1)`\n\nDependencies: none\n\nReturns a copy of the array that is sorted. The `fieldOrMapper` can be one of:\n- null (or not provided) which means the elements will be treated as comparable\n- string - in which case it will be a name of field to extract from the objects in the array and then to sort them up\n- a function that takes the array element as parameter and shall return a comparable value\n\nThe `order` parameter is either a positive or negative number. If it is negative it will reverse the order of sorted elements.\n\n### `Array.ptototype.min(fieldOrMapper = null)`\n\nDependencies: `sort-by`, `first`\n\nReturns the smallest element in the list. The `fieldOrMapper` can be one of:\n- null (or not provided) which means the elements will be treated as comparable\n- string - in which case it will be a name of field to extract from the objects in the array and then to sort them up\n- a function that takes the array element as parameter and shall return a comparable value\n\n### `Array.prototype.max(fieldOrMapper = null)`\n\nDependencies: `sort-by`, `first`\n\nReturns the largest element in the list. The `fieldOrMapper` can be one of:\n- null (or not provided) which means the elements will be treated as comparable\n- string - in which case it will be a name of field to extract from the objects in the array and then to sort them up\n- a function that takes the array element as parameter and shall return a comparable value\n\n### `Array.prototype.median(fieldOrMapper = null)`\n\nDependencies: `sort-by`\n\nReturns the median element in the list. The `fieldOrMapper` can be one of:\n- null (or not provided) which means the elements will be treated as comparable\n- string - in which case it will be a name of field to extract from the objects in the array and then to sort them up\n- a function that takes the array element as parameter and shall return a comparable value\n\n### `Array.prototype.groupBy(fieldOrMapper)`\n\nDependencies: none\n\nReturns a dictionary of lists of objects from the array grouped by a field name. The `fieldOrMapper` is required and can be one of:\n\n- string - in which case it will be a name of field to extract from the objects in the array and then to sort them up\n- a function that takes the array element as parameter and shall return a string to group objects by\n\nObjects that don't have the field in them will be skipped.\n\n### `Array.prototype.groupByAsMap(field)`\n\nDependencies: none\n\nReturns a Map of lists of objects from the array grouped by a field name. The `fieldOrMapper` is required and can be one of:\n\n- string - in which case it will be a name of field to extract from the objects in the array and then to sort them up\n- a function that takes the array element as parameter and shall return a value to group objects by\n\nThe difference to `groupBy(field)` is that the return value is an instance of `Map\u003cany, T[]\u003e` which means that the original type of the values of the field is also preserved and not converted to a string. This also means that if throughout the objects in the source array field values have different types they will be treated differently and you'll end up having more than one item in the result.\n\nObjects that don't have the field in them will be skipped.\n\n### `Array.prototype.uniq(fieldOrMapper = null)`\n\nDependencies: none\n\nReturns a list of unique values from the original array. The `fieldOrMapper` can be one of:\n- null (or not provided) which means the elements will be treated as comparable\n- string - in which case it will be a name of field to extract from the objects in the array and then to sort them up\n- a function that takes the array element as parameter and shall return a comparable value\n\nIf the `fieldOrMapper` is specified the final list will return only values of the specified field or the values returned by the mapper.\n\n### `Array.generate\u003cT\u003e(length: number, init: index =\u003e T | null): T[]`\n\nDependencies: none\n\nReturns a new list with elements initialized with the init method.\n\nFor example, to generate 10 random numbers:\n\n```\nconst values = Array.generate(10, Math.random)\n```\n\nor to generate a list of numbers from 0 to 9\n\n```\nconst values = Array.generate(10, index =\u003e index)\n```\n\n## Additional information\n\nThere's an extensive suite of tests in this package. You can run them by running the issuing the following command:\n\n```\n$ npm run test:unit\n```\n\nor run them continuously while doing changes by running the following command:\n\n```\n$ npm run test:unit:watch\n```\n\nTo build the latest output files run\n\n```\n$ npm run build\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadcom%2Farray-prototype-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpadcom%2Farray-prototype-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadcom%2Farray-prototype-functions/lists"}