Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(every/fill/filter/find/findIndex/findLastIndex/indexOf/join): fix lodash compatibility #707

Merged
merged 8 commits into from
Oct 14, 2024

Conversation

D-Sketon
Copy link
Contributor

@D-Sketon D-Sketon commented Oct 13, 2024

add ArrayLike<T> | null | undefined for every/fill/filter/find/findIndex/findLastIndex/indexOf/join
add fromIndex for findIndex

Copy link

vercel bot commented Oct 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
es-toolkit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 14, 2024 2:54pm

@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.29%. Comparing base (76ec5f1) to head (bd4962e).
Report is 5 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #707   +/-   ##
=======================================
  Coverage   97.28%   97.29%           
=======================================
  Files         283      287    +4     
  Lines        2433     2477   +44     
  Branches      685      703   +18     
=======================================
+ Hits         2367     2410   +43     
- Misses         60       61    +1     
  Partials        6        6           

function every<T>(arr: T[], doesMatch: Partial<T>): boolean;
function every<T>(arr: T[], doesMatch: [keyof T, unknown]): boolean;
function every<T>(arr: T[], doesMatch: string): boolean;
function every<T>(arr: ArrayLike<T> | null | undefined): boolean;
Copy link
Collaborator

@raon0211 raon0211 Oct 13, 2024

Choose a reason for hiding this comment

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

I’m not completely convinced we need to explicitly mention that every and other functions accept null or undefined in the signature section of documentation.

The function signature ends up looking quite verbose, making it harder to focus on the key points.

How about we keep the original function signature in the docs and add a special info section like this:

 function every<T>(arr: T[]): boolean;
 function every<T>(arr: T[], doesMatch: (item: T, index: number, arr: T[]) => unknown): boolean;
 function every<T>(arr: T[], doesMatch: Partial<T>): boolean;
 function every<T>(arr: T[], doesMatch: [keyof T, unknown]): boolean;
 function every<T>(arr: T[], doesMatch: string): boolean;

 function every<T extends Record<string, unknown>>(
   object: T,
   doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown
 ): boolean;
 function every<T extends Record<string, unknown>>(object: T, doesMatch: Partial<T[keyof T]>): boolean;
 function every<T extends Record<string, unknown>>(object: T, doesMatch: [keyof T, unknown]): boolean;
 function every<T extends Record<string, unknown>>(object: T, doesMatch: string): boolean;

::: info `arr` can be `ArrayLike<T>`, `null`, or `undefined`

The `every` function is designed for complete compatibility with lodash:

- If arr is an `ArrayLike<T>`, it gets converted into an array using `Array.from(...)`.
- If arr is `null` or `undefined`, it will be treated as an empty array.

:::

::: info `object` can be `null` or `undefined`

To ensure full compatibility with lodash, the every function handles `object` in this way:

- If `object` is `null` or `undefined`, it will be converted into an empty object.

:::

@D-Sketon
Copy link
Contributor Author

done

raon0211
raon0211 previously approved these changes Oct 14, 2024
Copy link
Collaborator

@raon0211 raon0211 left a comment

Choose a reason for hiding this comment

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

Great work. Thanks so much!

@raon0211 raon0211 merged commit f37b4ac into toss:main Oct 14, 2024
5 of 8 checks passed
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