Skip to content

Commit 261b60d

Browse files
committed
refactor(utils)!: [includes] order position arg before identity
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent da89078 commit 261b60d

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

src/utils/__tests__/includes.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@ describe('unit:utils/includes', () => {
1111
// Arrange
1212
const cases: Parameters<typeof testSubject>[] = [
1313
['abc', 'z'],
14-
['abc', 'a', null, 1],
14+
['abc', 'a', 1, null],
1515
[['a', 'b', 'c'], 'z'],
16-
[['a', 'b', 'c'], 'a', undefined, 1]
16+
[['a', 'b', 'c'], 'a', 1]
1717
]
1818

1919
// Act + Expect
20-
cases.forEach(([value, target, identity, position]) => {
21-
expect(testSubject(value, target, identity, position)).to.be.false
20+
cases.forEach(([value, target, position, identity]) => {
21+
expect(testSubject(value, target, position, identity)).to.be.false
2222
})
2323
})
2424

2525
it('should return true if value includes target', () => {
2626
// Arrange
2727
const cases: Parameters<typeof testSubject>[] = [
2828
['foobar', 'foo'],
29-
['foobar', 'bar', null, 3],
30-
[[faker.number.int(), { x: 0, y: 0 }], { x: 0, y: 0 }, undefined, 1],
29+
['foobar', 'bar', 3],
30+
[[faker.number.int(), { x: 0, y: 0 }], { x: 0, y: 0 }, 1],
3131
[
3232
[faker.number.int(), { x: 0, y: 0 }],
3333
{ x: 0, y: 0 },
34+
1,
3435
item => {
3536
const { x, y = Number.NaN } = cast<{ x: number; y?: number }>(item)
3637
return `[${x},${y}]`
37-
},
38-
1
38+
}
3939
]
4040
]
4141

4242
// Act + Expect
43-
cases.forEach(([value, target, identity, position]) => {
44-
expect(testSubject(value, target, identity, position)).to.be.true
43+
cases.forEach(([value, target, position, identity]) => {
44+
expect(testSubject(value, target, position, identity)).to.be.true
4545
})
4646
})
4747
})

src/utils/diff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const diff = <T, K extends PropertyKey = PropertyKey>(
3030
): T[] => {
3131
return intersects(arr1, arr2, identity)
3232
? arr1.reduce<T[]>((acc, item) => {
33-
return includes(arr2, item, identity) ? acc : [...acc, item]
33+
return includes(arr2, item, null, identity) ? acc : [...acc, item]
3434
}, [])
3535
: [...arr1]
3636
}

src/utils/includes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @module tutils/utils/includes
44
*/
55

6-
import type { Fn, IfString, NIL, Nilable, PropertyKey } from '#src/types'
6+
import type { Fn, Nilable, PropertyKey } from '#src/types'
77
import cast from './cast'
88
import equal from './equal'
99
import isString from './is-string'
@@ -36,8 +36,8 @@ const includes = <
3636
>(
3737
value: T,
3838
target: unknown,
39-
identity?: IfString<T, NIL, Nilable<Fn<[T[number]], K>>>,
40-
position?: Nilable<number>
39+
position?: Nilable<number>,
40+
identity?: Nilable<Fn<[T[number]], K>>
4141
): boolean => {
4242
position ??= 0
4343

src/utils/intersection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ const intersection = <T, K extends PropertyKey = PropertyKey>(
2727
arr1: readonly T[],
2828
arr2: readonly T[],
2929
identity?: Nilable<Fn<[T], K>>
30-
): T[] => select(arr1, item => includes(arr2, item, identity))
30+
): T[] => select(arr1, item => includes(arr2, item, null, identity))
3131

3232
export default intersection

src/utils/pull.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ const pull = <T, K extends PropertyKey = PropertyKey, U = T>(
2828
arr: readonly T[],
2929
drop: readonly T[],
3030
identity?: Nilable<Fn<[T], K>>
31-
): U[] => select(arr, item => !includes(drop, item, identity))
31+
): U[] => select(arr, item => !includes(drop, item, null, identity))
3232

3333
export default pull

src/utils/unique.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const unique = <T, K extends PropertyKey = PropertyKey, U = T>(
2929
): U[] => {
3030
return cast(
3131
arr.reduce<T[]>((acc, item) => {
32-
return includes(acc, item, identity) ? acc : [...acc, item]
32+
return includes(acc, item, null, identity) ? acc : [...acc, item]
3333
}, [])
3434
)
3535
}

0 commit comments

Comments
 (0)