-
Notifications
You must be signed in to change notification settings - Fork 294
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
Conversation
… lodash compatibility
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ 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 |
docs/reference/compat/array/every.md
Outdated
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; |
There was a problem hiding this comment.
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.
:::
done |
There was a problem hiding this 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!
add
ArrayLike<T> | null | undefined
for every/fill/filter/find/findIndex/findLastIndex/indexOf/joinadd
fromIndex
for findIndex