Skip to content

feat(array): add new array helpers and array-like detection#525

Merged
nev21 merged 1 commit intomainfrom
nev21/array
Mar 17, 2026
Merged

feat(array): add new array helpers and array-like detection#525
nev21 merged 1 commit intomainfrom
nev21/array

Conversation

@nev21
Copy link
Contributor

@nev21 nev21 commented Feb 26, 2026

  • add arrUnique, arrCompact, arrFlatten, arrGroupBy, arrChunk with ArrayLike support
  • add isArrayLike helper and export in index
  • add tests for new array helpers and isArrayLike

@nev21 nev21 added this to the 0.13.0 milestone Feb 26, 2026
@nev21 nev21 requested a review from a team as a code owner February 26, 2026 06:36
Copilot AI review requested due to automatic review settings February 26, 2026 06:36
@nev21 nev21 requested a review from a team as a code owner February 26, 2026 06:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds five new array helper functions with ArrayLike support and introduces the isArrayLike type guard helper. The changes enhance the library's array manipulation capabilities with common utility functions like deduplication, compaction, flattening, grouping, and chunking, all following the established arr* naming convention and supporting both arrays and array-like objects.

Changes:

  • Added isArrayLike helper function to detect array-like objects (objects with numeric length property >= 0)
  • Added five new array utility functions: arrUnique, arrCompact, arrFlatten, arrGroupBy, and arrChunk
  • Updated bundle size limits to accommodate the new functionality (~1KB increase)
  • Removed redundant /*#__PURE__*/ markers from simple function assignments in unwrapFunction.ts
  • Updated version documentation in customError.ts

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
lib/src/helpers/base.ts Adds isArrayLike type guard function with proper null/undefined/function checks and exports it
lib/src/array/unique.ts New function to remove duplicate values from arrays using object-based tracking
lib/src/array/compact.ts New function to filter out all falsy values from arrays
lib/src/array/flatten.ts New function to flatten nested arrays to specified depth
lib/src/array/groupBy.ts New function to group array elements by callback result
lib/src/array/chunk.ts New function to split arrays into fixed-size chunks
lib/src/index.ts Exports all new functions and types including isArrayLike
lib/test/src/common/helpers/base.test.ts Comprehensive tests for isArrayLike covering various input types
lib/test/src/common/helpers/array.test.ts Comprehensive tests for all five new array functions
lib/src/internal/unwrapFunction.ts Removes redundant /*#__PURE__*/ markers from simple assignments
lib/src/helpers/customError.ts Updates version comment from v0.12.7 to v0.13.0 for superArgsFn parameter
.size-limit.json Updates bundle size limits to reflect new functionality
lib/test/bundle-size-check.js Updates bundle size limits for ES5 and ES6 builds
README.md Updates documentation to include new array functions in the function list

@nev21 nev21 modified the milestones: 0.13.0, 0.14.0 Mar 4, 2026
@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 99.80620% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.82%. Comparing base (077f469) to head (8eac301).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/src/helpers/arrayLike.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #525      +/-   ##
==========================================
+ Coverage   98.78%   98.82%   +0.03%     
==========================================
  Files         111      134      +23     
  Lines        3384     3905     +521     
  Branches      716      852     +136     
==========================================
+ Hits         3343     3859     +516     
- Misses         41       46       +5     
Files with missing lines Coverage Δ
lib/src/array/at.ts 100.00% <100.00%> (ø)
lib/src/array/callbacks.ts 50.00% <ø> (ø)
lib/src/array/chunk.ts 100.00% <100.00%> (ø)
lib/src/array/compact.ts 100.00% <100.00%> (ø)
lib/src/array/difference.ts 100.00% <100.00%> (ø)
lib/src/array/drop.ts 100.00% <100.00%> (ø)
lib/src/array/drop_while.ts 100.00% <100.00%> (ø)
lib/src/array/fill.ts 100.00% <100.00%> (ø)
lib/src/array/flatten.ts 100.00% <100.00%> (ø)
lib/src/array/groupBy.ts 100.00% <100.00%> (ø)
... and 17 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- add new array helpers: arrAt, arrChunk, arrCompact, arrDifference, arrDrop,
  arrDropWhile, arrFill, arrFlatten, arrGroupBy, arrIntersection, arrPartition,
  arrReverse, arrRotate, arrSample, arrShuffle, arrTake, arrTakeWhile, arrUnion,
  arrUnique, arrUnzip, arrWith, arrZip
- add polyfills: polyArrAt, polyArrFill, polyArrWith
- add WritableArrayLike type and export it publicly
- add isArrayLike type guard in helpers/base, export it, and add tests
- add comprehensive common tests for new array APIs and edge cases
- update README utility matrix to include newly added functions
- adjust bundle size limits for expanded API surface
- include minor docs/typo cleanup updates
@nev21 nev21 requested a review from Copilot March 17, 2026 07:07
@nev21 nev21 enabled auto-merge (squash) March 17, 2026 07:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 45 out of 45 changed files in this pull request and generated 14 comments.

Comment on lines +546 to +550
* Checks if the type of value is array-like (has a numeric length property and numeric indices).
* @since 0.14.0
* @function
* @group Type Identity
* @group Array
*/

import { isArrayLike } from "../helpers/base";
import { normalizeJsName } from "../helpers/encode";
Comment on lines +44 to +48
arrForEach(theArray, (item) => {
const key = ((typeof item) + "_" + item);

if (!objHasOwn(seen, key)) {
seen[key] = 1;
* @param theArray - The array or array-like object to copy from
* @param index - The index at which to change the value. Negative index counts from the end
* @param value - The new value to set at the index
* @returns A new array with the element at index replaced, or the original array if index is out of range
Comment on lines +62 to +64
if (!isArrayLike(theArray)) {
throw new RangeError("Invalid array");
}

import { fnCall } from "../funcs/funcs";
import { isArrayLike } from "../helpers/base";
import { getLength } from "../helpers/length";
*/

import { arrSlice } from "./slice";
import { getLength } from "../helpers/length";
* @group ArrayLike
* @typeParam T - Identifies the type of array elements
* @param theArray - The array or array-like object to rotate
* @param count - Number of positions to rotate. Positive = right, negative = left
Comment on lines +9 to +14
import { ArrProto, UNDEF_VALUE, UNDEFINED } from "../internal/constants";
import { _unwrapFunctionWithPoly } from "../internal/unwrapFunction";
import { isArrayLike } from "../helpers/base";
import { getLength } from "../helpers/length";
import { WritableArrayLike } from "../helpers/arrayLike";
import { mathMax, mathMin } from "../math/min_max";
Comment on lines +89 to +93
it("should throw for null and undefined", () => {
// arrSample expects a valid array
assert.isUndefined(arrSample(null));
assert.isUndefined(arrSample(undefined));
});
Copy link
Contributor

@nevware21-bot nevware21-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by nevware21-bot

@nev21 nev21 merged commit 75626d3 into main Mar 17, 2026
14 checks passed
@nev21 nev21 deleted the nev21/array branch March 17, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants