Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/performance/cloneDeep.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const obj = {
date: new Date(),
regex: /abc/g,
instance: new (class Test {
value: 1;
value = 1;
})(),
nested: { a: [1, 2, 3], b: { c: 'es-toolkit' }, d: new Date() },
nested2: { a: { b: { c: { d: { e: { f: { g: 'es-toolkit' } } } } } } },
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/performance/cond.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const condToolkitCompat = condToolkitCompat_;
const condLodash = condLodash_;

describe('cond', () => {
const isA = obj => obj && obj.a === 1;
const isB = obj => obj && obj.b === 1;
const isC = obj => obj && obj.c;
const isA = (obj: { a: number }) => obj && obj.a === 1;
const isB = (obj: { b: number }) => obj && obj.b === 1;
const isC = (obj: { c: number }) => obj && obj.c;

const returnA = () => 'a';
const returnB = () => 'b';
Expand Down
8 changes: 5 additions & 3 deletions benchmarks/performance/conformsTo.bench.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { bench, describe } from 'vitest';
import { conformsTo as conformsToolkit_ } from 'es-toolkit/compat';
import { conformsTo as conformsToToolkit_ } from 'es-toolkit/compat';
import { conformsTo as conformsToLodash_ } from 'lodash';

const conformsToolkit = conformsToolkit_;
const conformsToToolkit = conformsToToolkit_;
const conformsToLodash = conformsToLodash_;

describe('conformsTo', () => {
bench('es-toolkit/conformsTo', () => {
conformsToolkit(
conformsToToolkit(
{ a: 1, b: 2 },
{
a: (n: number) => n > 0,
b: (n: number) => n > 1,
}
);
Expand All @@ -19,6 +20,7 @@ describe('conformsTo', () => {
conformsToLodash(
{ a: 1, b: 2 },
{
a: (n: number) => n > 0,
b: (n: number) => n > 1,
}
);
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/performance/curryRight.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ describe('curryRight - compat', () => {
const fn = (a: number, b: string, c: boolean) => ({ a, b, c });

bench('es-toolkit/compat/curryRight', () => {
curryRightToolkitCompat(fn)(true, 'a', 1);
curryRightToolkitCompat(fn)(true)(1, 'a');
});

bench('lodash/curryRight', () => {
curryRightLodash(fn)(true, 'a', 1);
curryRightLodash(fn)(true)(1, 'a');
});
});

describe('curryRight - compat with placeholder', () => {
const fn = (a: number, b: string, c: boolean) => ({ a, b, c });

bench('es-toolkit/compat/curryRight', () => {
curryRightToolkitCompat(fn)(true, curryRightToolkitCompat.placeholder, 1)('a');
curryRightToolkitCompat(fn)(true)(1, curryRightToolkitCompat.placeholder)('a');
});

bench('lodash/curryRight', () => {
curryRightLodash(fn)(true, curryRightLodash.placeholder, 1)('a');
curryRightLodash(fn)(true)(1, curryRightLodash.placeholder)('a');
});
});
3 changes: 2 additions & 1 deletion benchmarks/performance/flatten.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const flattenToolkit = flattenToolkit_;
const flattenCompatToolkit = flattenCompatToolkit_;
const flattenDepthLodash = flattenDepthLodash_;

const createNestedArray = (values: any[]) => {
const createNestedArray = (values: any[]): any[] => {
if (values.length === 0) {
return [];
}
Expand All @@ -23,6 +23,7 @@ describe('flatten', () => {
});

bench('es-toolkit/flatten (compat)', () => {
// @ts-expect-error - depth parameter is a hidden feature in compat version
flattenCompatToolkit(arr, 30);
});

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/performance/flattenDeep.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const flattenDeepToolkit = flattenDeepToolkit_;
const flattenDeepToolkitCompat = flattenDeepToolkitCompat_;
const flattenDeepLodash = flattenDeepLodash_;

const createNestedArray = (values: number[]) => {
const createNestedArray = (values: number[]): any[] => {
if (values.length === 0) {
return [];
}
Expand Down
14 changes: 7 additions & 7 deletions benchmarks/performance/functionsIn.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ const functionsInToolkitCompat = functionsInToolkitCompat_;
const functionsInLodash = functionsInLodash_;

describe('functionsIn', () => {
function Foo() {
this.a = function () {
class Foo {
a = function () {
return 'a';
};
this.b = function () {

b = function () {
return 'b';
};
c() {
return 'c';
}
}

Foo.prototype.c = function () {
return 'c';
};

const foo = new Foo();
const plainObject = {
a: function () {
Expand Down
25 changes: 13 additions & 12 deletions benchmarks/performance/hasIn.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ describe('hasIn', () => {

// 상속된 속성 테스트 (문자열)
describe('with inherited property (string)', () => {
function Rectangle() {}
Rectangle.prototype.area = function () {
return 0;
};
class Rectangle {
area() {
return 0;
}
}
const rect = new Rectangle();

bench('es-toolkit/hasIn', () => {
Expand All @@ -51,8 +52,9 @@ describe('hasIn', () => {

// 상속된 중첩 속성 테스트 (배열)
describe('with inherited nested property (array)', () => {
function Rectangle() {}
Rectangle.prototype.dimensions = { width: 10, height: 5 };
class Rectangle {
dimensions = { width: 10, height: 5 };
}
const rect = new Rectangle();

bench('es-toolkit/hasIn', () => {
Expand All @@ -79,14 +81,13 @@ describe('hasIn', () => {

// 깊은 상속 체인 테스트
describe('with deep inheritance chain', () => {
function GrandParent() {}
GrandParent.prototype.method = function () {};
class GrandParent {
method() {}
}

function Parent() {}
Parent.prototype = Object.create(GrandParent.prototype);
class Parent extends GrandParent {}

function Child() {}
Child.prototype = Object.create(Parent.prototype);
class Child extends Parent {}

const child = new Child();

Expand Down
4 changes: 0 additions & 4 deletions benchmarks/performance/includes.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('includes (object)', () => {
includesToolkitCompat(object, undefined);
includesToolkitCompat(object, null);
includesToolkitCompat(object, Infinity);
includesToolkitCompat(object, Symbol('sym1'));
includesToolkitCompat(object, -0);
includesToolkitCompat(object, 1, -1);
});
Expand All @@ -35,9 +34,6 @@ describe('includes (object)', () => {
includesLodash(object, undefined);
includesLodash(object, null);
includesLodash(object, Infinity);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
includesLodash(object, Symbol('sym1'));
includesLodash(object, -0);
includesLodash(object, 1, -1);
});
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/performance/intersectionWith.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ describe('intersectionWith', () => {
bench('es-toolkit/intersectionWith', () => {
const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
const array2 = [{ id: 2 }, { id: 4 }];
const areItemsEqual = (a, b) => a.id === b.id;
const areItemsEqual = (a: { id: number }, b: { id: number }) => a.id === b.id;
intersectionWithToolkit(array1, array2, areItemsEqual);
});

bench('es-toolkit/compat/intersectionWith', () => {
const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
const array2 = [{ id: 2 }, { id: 4 }];
const areItemsEqual = (a, b) => a.id === b.id;
const areItemsEqual = (a: { id: number }, b: { id: number }) => a.id === b.id;
intersectionWithCompat(array1, array2, areItemsEqual);
});

bench('lodash/intersectionWith', () => {
const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
const array2 = [{ id: 2 }, { id: 4 }];
const areItemsEqual = (a, b) => a.id === b.id;
const areItemsEqual = (a: { id: number }, b: { id: number }) => a.id === b.id;
intersectionWithLodash(array1, array2, areItemsEqual);
});
});

describe('intersectionWith/largeArrays', () => {
const array1 = Array.from({ length: 10000 }, (_, i) => ({ id: i }));
const array2 = Array.from({ length: 10000 }, (_, i) => ({ id: i + 5000 }));
const areItemsEqual = (a, b) => a.id === b.id;
const areItemsEqual = (a: { id: number }, b: { id: number }) => a.id === b.id;

bench('es-toolkit/intersectionWith', () => {
intersectionWithToolkit(array1, array2, areItemsEqual);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/performance/invokeMap.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('invokeMap', () => {
const numberObject = { a: 1, b: 2, c: 3 };
const largeArray = Array.from({ length: 1000 }, (_, i) => String(i));
const array = ['a', 'b', 'c'];
const func = function (left, right) {
const func = function (this: string, left: string, right: string) {
return left + this.toUpperCase() + right;
};

Expand Down
12 changes: 6 additions & 6 deletions benchmarks/performance/isEqualWith.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const isEqualWithToolkitCompat = isEqualWithToolkitCompat_;
const isEqualWithLodash = isEqualWithLodash_;

describe('isEqualWith primitives', () => {
const customizer = (a, b) => {
const customizer = (a: unknown, b: unknown) => {
if (typeof a === 'string' && typeof b === 'string') {
return a.toLowerCase() === b.toLowerCase();
}
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('isEqualWith primitives', () => {
});

describe('isEqualWith dates', () => {
const customizer = (a, b) => {
const customizer = (a: unknown, b: unknown) => {
if (a instanceof Date && b instanceof Date) {
return a.getTime() === b.getTime();
}
Expand All @@ -74,7 +74,7 @@ describe('isEqualWith dates', () => {
});

describe('isEqualWith RegExps', () => {
const customizer = (a, b) => {
const customizer = (a: unknown, b: unknown) => {
if (a instanceof RegExp && b instanceof RegExp) {
return a.source === b.source;
}
Expand All @@ -96,8 +96,8 @@ describe('isEqualWith RegExps', () => {
});

describe('isEqualWith objects', () => {
const customizer = (a, b) => {
if (typeof a === 'object' && typeof b === 'object') {
const customizer = (a: unknown, b: unknown) => {
if (typeof a === 'object' && typeof b === 'object' && a !== null && b !== null) {
return Object.keys(a).length === Object.keys(b).length;
}
};
Expand All @@ -121,7 +121,7 @@ describe('isEqualWith objects', () => {
});

describe('isEqualWith arrays', () => {
const customizer = (a, b) => {
const customizer = (a: unknown, b: unknown) => {
if (Array.isArray(a) && Array.isArray(b)) {
return a.length === b.length;
}
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/performance/isMatchWith.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isMatchWith as isMatchWithLodash_ } from 'lodash';
const isMatchWithToolkitCompat = isMatchWithToolkitCompat_;
const isMatchWithLodash = isMatchWithLodash_;

const customizer = (objValue, srcValue) => {
const customizer = (objValue: unknown, srcValue: unknown) => {
if (typeof objValue === 'string' && typeof srcValue === 'string') {
return objValue.toLowerCase() === srcValue.toLowerCase();
}
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/performance/mergeWith.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const object = { a: 1, b: 2 };

const other = { b: 3, c: 4 };

const merge = (targetValue: any, sourceValue: any) => {
const merge = (targetValue: unknown, sourceValue: unknown) => {
if (typeof targetValue === 'number' && typeof sourceValue === 'number') {
return targetValue + sourceValue;
}
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/performance/overArgs.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ describe('overArgs - property shorthand', () => {
const user2 = { name: 'Jane', age: 25 };

bench('es-toolkit/overArgs - property shorthand', () => {
const func = overArgsToolkitCompat((name, age) => `${name} is ${age} years old`, ['name', 'age']);
const func = overArgsToolkitCompat((name, age) => `${name} is ${age} years old`, ['name', 'age'] as any[]);
func(user1, user2);
func(user2, user1);
});

bench('lodash/overArgs - property shorthand', () => {
const func = overArgsLodash((name, age) => `${name} is ${age} years old`, ['name', 'age']);
const func = overArgsLodash((name, age) => `${name} is ${age} years old`, ['name', 'age'] as any[]);
func(user1, user2);
func(user2, user1);
});
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/performance/pull.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('pull array size 100', () => {
const even = [...Array(50)].map((_, i) => i * 2);

bench('es-toolkit/pull', () => {
pullToolkit([...array], even);
pullToolkit([...array], ...even);
});

bench('lodash/pull', () => {
Expand All @@ -23,7 +23,7 @@ describe('pull array size 1000', () => {
const even = [...Array(500)].map((_, i) => i * 2);

bench('es-toolkit/pull', () => {
pullToolkit([...array], [...even]);
pullToolkit([...array], ...even);
});

bench('lodash/pull', () => {
Expand All @@ -36,7 +36,7 @@ describe('pull array size 10000', () => {
const even = [...Array(5000)].map((_, i) => i * 2);

bench('es-toolkit/pull', () => {
pullToolkit([...array], [...even]);
pullToolkit([...array], ...even);
});

bench('lodash/pull', () => {
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/performance/pullAllWith.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('pullAllWith', () => {
const array = [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 4 }, { x: 5 }];
const valuesToRemove = [{ x: 2 }, { x: 4 }];

const comparator = (a, b) => a.x === b.x;
const comparator = (a: { x: number }, b: { x: number }) => a.x === b.x;

bench('es-toolkit/pullAllWith', () => {
pullAllWithToolkit([...array], valuesToRemove, comparator);
Expand All @@ -24,7 +24,7 @@ describe('pullAllWith/largeArray', () => {
const largeArray = Array.from({ length: 10000 }, (_, i) => ({ x: i }));
const valuesToRemove = Array.from({ length: 1000 }, (_, i) => ({ x: i + 1000 }));

const comparator = (a, b) => a.x === b.x;
const comparator = (a: { x: number }, b: { x: number }) => a.x === b.x;

bench('es-toolkit/pullAllWith', () => {
pullAllWithToolkit([...largeArray], valuesToRemove, comparator);
Expand Down
6 changes: 0 additions & 6 deletions benchmarks/performance/round.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ describe('round (compat)', () => {
roundCompat(4160, -2);
roundCompat(4.006, NaN);
roundCompat(4.016, 2.6);
roundCompat(4.016, '+2');
roundCompat(5e1, 2);
roundCompat('5e', 1);
roundCompat('5e1e1', 1);
});

bench('lodash/round', () => {
Expand All @@ -46,9 +43,6 @@ describe('round (compat)', () => {
roundLodash(4160, -2);
roundLodash(4.006, NaN);
roundLodash(4.016, 2.6);
roundLodash(4.016, '+2');
roundLodash(5e1, 2);
roundLodash('5e', 1);
roundLodash('5e1e1', 1);
});
});
2 changes: 1 addition & 1 deletion benchmarks/performance/spread.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('spread', () => {
}

bench('es-toolkit/spread', () => {
spreadToolkit(fn, 1);
spreadToolkit(fn);
});

bench('es-toolkit/compat/spread', () => {
Expand Down
Loading