Skip to content

Commit 566ba41

Browse files
committed
Merge branch 'alpha'
2 parents ccafa22 + 6b4c34a commit 566ba41

File tree

3 files changed

+17
-64
lines changed

3 files changed

+17
-64
lines changed

index.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
excludeFirst,
1515
excludeNull,
1616
filter,
17-
filterFirst,
1817
find,
1918
findIndex,
2019
findLast,
@@ -204,13 +203,6 @@ test("filter", t => {
204203
);
205204
});
206205

207-
test("filterFirst", t => {
208-
t.deepEqual(
209-
filterFirst([1, 2, 3, 4, 3, 2, 1], n => n < 3),
210-
[1, 2, 4, 3, 2, 1]
211-
);
212-
});
213-
214206
test("exclude", t => {
215207
t.deepEqual(
216208
exclude([1, 2, 3, 4, 3, 2, 1], n => n < 3),

index.ts

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ export const copy: <T>(array: ArrayLike<T>) => T[] = Array.from;
4242
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4343
// @ts-ignore duplicate identifier: This is the exported declaration, the implementation is below.
4444
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
45-
export function isArray<T = unknown>(value: readonly T[] | unknown): value is readonly T[];
45+
export function isArray(value: unknown): value is readonly unknown[];
4646

4747
/** @internal This implementation is for internal use only, the exported declaration is above */
4848
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4949
// @ts-ignore duplicate identifier: This is the actual implementation, the exported declaration is above.
5050
export const isArray: (value: unknown) => value is unknown[] = Array.isArray;
5151

5252
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
53-
export function isArrayLike<T>(value: ArrayLike<T> | unknown): value is ArrayLike<T> {
53+
export function isArrayLike(value: unknown): value is ArrayLike<unknown> {
5454
return (
5555
typeof value === "object" &&
5656
value != null &&
@@ -67,16 +67,6 @@ export function first<T>(array: ArrayLike<T>): T | null {
6767
return array.length === 0 ? null : (array[0] as T);
6868
}
6969

70-
/** @deprecated Use {@link first} instead. */
71-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
72-
// @ts-ignore duplicate identifier: This is the exported declaration, the implementation is below.
73-
export function head<T>(array: ArrayLike<T>): T | null;
74-
75-
/** @internal This implementation is for internal use only, the exported declaration is above */
76-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
77-
// @ts-ignore duplicate identifier: This is the actual implementation, the exported declaration is above.
78-
export const head = first;
79-
8070
export function tail<T>(array: ArrayLike<T>): T[] {
8171
return nativeSlice.call(array, 1) as T[];
8272
}
@@ -327,36 +317,6 @@ export function filterFn<T>(
327317
return array => nativeFilter.call(array, predicate) as T[];
328318
}
329319

330-
/** @deprecated This function is confusing, use {@link excludeFirst} instead,
331-
* and invert the predicate. */
332-
export function filterFirst<T>(
333-
array: ArrayLike<T>,
334-
predicate: (element: T, index: number) => boolean
335-
): T[] {
336-
const result: T[] = [];
337-
let i = 0;
338-
for (; i < array.length; ++i) {
339-
const element = array[i] as T;
340-
if (predicate(element, i)) {
341-
result.push(element);
342-
} else {
343-
break;
344-
}
345-
}
346-
for (++i; i < array.length; ++i) {
347-
result.push(array[i] as T);
348-
}
349-
return result;
350-
}
351-
352-
/** @deprecated This function is confusing, use {@link excludeFirstFn} instead,
353-
* and invert the predicate. */
354-
export function filterFirstFn<T>(
355-
predicate: (element: T, index: number) => boolean
356-
): (array: ArrayLike<T>) => T[] {
357-
return array => filterFirst(array, predicate);
358-
}
359-
360320
export function exclude<T, U>(
361321
array: ArrayLike<T | U>,
362322
predicate: (element: T | U) => element is T
@@ -392,7 +352,20 @@ export function excludeFirst<T>(
392352
array: ArrayLike<T>,
393353
predicate: (element: T, index: number) => boolean
394354
): T[] {
395-
return filterFirst(array, (element, index) => !predicate(element, index));
355+
const result: T[] = [];
356+
let i = 0;
357+
for (; i < array.length; ++i) {
358+
const element = array[i] as T;
359+
if (!predicate(element, i)) {
360+
result.push(element);
361+
} else {
362+
break;
363+
}
364+
}
365+
for (++i; i < array.length; ++i) {
366+
result.push(array[i] as T);
367+
}
368+
return result;
396369
}
397370

398371
export function excludeFirstFn<T>(
@@ -1715,18 +1688,6 @@ export function uniqueAdjacentByHashFn<T>(
17151688
return array => uniqueAdjacentByHash(array, hash);
17161689
}
17171690

1718-
/** @deprecated Use [array-shuffle](https://npmjs.com/array-shuffle) instead. */
1719-
export function shuffle<T>(array: ArrayLike<T>): T[] {
1720-
const result = copy(array);
1721-
for (let i = 0; i < array.length; ++i) {
1722-
const j = i + Math.floor(Math.random() * (array.length - i));
1723-
const replacement = result[j] as T;
1724-
result[j] = result[i] as T;
1725-
result[i] = replacement;
1726-
}
1727-
return result;
1728-
}
1729-
17301691
export function sort(array: ArrayLike<boolean>): boolean[];
17311692
export function sort(array: ArrayLike<number>): number[];
17321693
export function sort(array: ArrayLike<string>): string[];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"sideEffects": false,
2525
"engines": {
26-
"node": "^14 || ^16 || >=18"
26+
"node": "^18 || >=20"
2727
},
2828
"dependencies": {
2929
"@softwareventures/nullable": "^1.0.0 || ^2.0.0 || ^3.0.0",

0 commit comments

Comments
 (0)