Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
raon0211 committed Jul 24, 2024
1 parent 0142e9d commit b24caf2
Show file tree
Hide file tree
Showing 47 changed files with 374 additions and 342 deletions.
8 changes: 4 additions & 4 deletions benchmarks/bundle-size/camelCase.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest"
import { getBundleSize } from "./utils/getBundleSize"
import { describe, expect, it } from 'vitest';
import { getBundleSize } from './utils/getBundleSize';

describe('camelCase bundle size', () => {
it('lodash-es', async () => {
Expand All @@ -10,5 +10,5 @@ describe('camelCase bundle size', () => {
it('es-toolkit', async () => {
const bundleSize = await getBundleSize('es-toolkit', 'camelCase');
expect(bundleSize).toMatchInlineSnapshot(`297`);
})
});
});
});
10 changes: 5 additions & 5 deletions benchmarks/bundle-size/chunk.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest"
import { getBundleSize } from "./utils/getBundleSize"
import { describe, expect, it } from 'vitest';
import { getBundleSize } from './utils/getBundleSize';

describe('chunk bundle size', () => {
it('lodash-es', async () => {
Expand All @@ -10,10 +10,10 @@ describe('chunk bundle size', () => {
it('es-toolkit', async () => {
const bundleSize = await getBundleSize('es-toolkit', 'chunk');
expect(bundleSize).toMatchInlineSnapshot(`238`);
})
});

it('es-toolkit/compat', async () => {
const bundleSize = await getBundleSize('es-toolkit/compat', 'chunk');
expect(bundleSize).toMatchInlineSnapshot(`307`);
})
});
});
});
8 changes: 4 additions & 4 deletions benchmarks/bundle-size/difference.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest"
import { getBundleSize } from "./utils/getBundleSize"
import { describe, expect, it } from 'vitest';
import { getBundleSize } from './utils/getBundleSize';

describe('difference bundle size', () => {
it('lodash-es', async () => {
Expand All @@ -10,5 +10,5 @@ describe('difference bundle size', () => {
it('es-toolkit', async () => {
const bundleSize = await getBundleSize('es-toolkit', 'difference');
expect(bundleSize).toMatchInlineSnapshot(`90`);
})
});
});
});
2 changes: 1 addition & 1 deletion benchmarks/bundle-size/utils/getBundleSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export async function getBundleSize(pkg: 'lodash-es' | 'es-toolkit' | 'es-toolki
});

return Buffer.from(bundled.outputFiles![0].contents).byteLength;
}
}
8 changes: 4 additions & 4 deletions benchmarks/bundle-size/zipObjectDeep.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest"
import { getBundleSize } from "./utils/getBundleSize"
import { describe, expect, it } from 'vitest';
import { getBundleSize } from './utils/getBundleSize';

describe('zipObjectDeep bundle size', () => {
it('lodash-es', async () => {
Expand All @@ -10,5 +10,5 @@ describe('zipObjectDeep bundle size', () => {
it('es-toolkit/compat', async () => {
const bundleSize = await getBundleSize('es-toolkit/compat', 'zipObjectDeep');
expect(bundleSize).toMatchInlineSnapshot(`938`);
})
});
});
});
20 changes: 10 additions & 10 deletions benchmarks/performance/get.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import { get as getLodash } from 'lodash';

describe('get with string', () => {
bench('es-toolkit/get', () => {
getToolkit({ a: { b: 3 } }, 'a.b')
})
getToolkit({ a: { b: 3 } }, 'a.b');
});

bench('lodash/get', () => {
getLodash({ a: { b: 3 } }, 'a.b')
})
})
getLodash({ a: { b: 3 } }, 'a.b');
});
});

describe('get with string array', () => {
bench('es-toolkit/get', () => {
getToolkit({ a: { b: 3 } }, ['a', 'b'])
})
getToolkit({ a: { b: 3 } }, ['a', 'b']);
});

bench('lodash/get', () => {
getLodash({ a: { b: 3 } }, ['a', 'b'])
})
})
getLodash({ a: { b: 3 } }, ['a', 'b']);
});
});
4 changes: 2 additions & 2 deletions benchmarks/performance/zipObjectDeep.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { zipObjectDeep as zipObjectDeepLodash } from 'lodash';
describe('zipObjectDeep', () => {
bench('es-toolkit/zipObjectDeep', () => {
const str = 'kebab-case';
zipObjectDeepToolkit(['a.b[0].c', 'a.b[1].d'], [1, 2])
zipObjectDeepToolkit(['a.b[0].c', 'a.b[1].d'], [1, 2]);
});

bench('lodash/zipObjectDeep', () => {
const str = 'kebab-case';
zipObjectDeepLodash(['a.b[0].c', 'a.b[1].d'], [1, 2])
zipObjectDeepLodash(['a.b[0].c', 'a.b[1].d'], [1, 2]);
});
});
5 changes: 1 addition & 4 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ function declarationOptions({ entrypoints, outDir }) {
/** @type {(srcFiles: string[]) => Record<string, string>} */
function mapInputs(srcFiles) {
return Object.fromEntries(
srcFiles.map(file => [
file.replace(/^(\.\/)?src\//, '').replace(/\.[cm]?(js|ts)$/, ''),
path.join(__dirname, file),
])
srcFiles.map(file => [file.replace(/^(\.\/)?src\//, '').replace(/\.[cm]?(js|ts)$/, ''), path.join(__dirname, file)])
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/array/countBy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import {countBy} from "./countBy.ts";
import { countBy } from './countBy.ts';

describe('countBy', () => {
it('should count the occurrences of each item in an array', () => {
Expand All @@ -16,11 +16,11 @@ describe('countBy', () => {
});
it('should count the occurrences of each item in an array that applied transformer', () => {
const arr = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5];
const result = countBy(arr, (item) => item % 2 === 0 ? 'even' : 'odd');
const result = countBy(arr, item => (item % 2 === 0 ? 'even' : 'odd'));

expect(result).toEqual({
'odd': 6,
'even': 4,
odd: 6,
even: 4,
});
})
});
});
6 changes: 3 additions & 3 deletions src/array/countBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/
export function countBy<T>(arr: T[], mapper: (item: T) => string): Record<string, number> {
const result: Record<string, number> = {};

for (const item of arr) {
const key = mapper(item);

result[key] = (result[key] ?? 0) + 1;
}

return result;
}
5 changes: 4 additions & 1 deletion src/array/flatMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ export function flatMap<T, U, D extends number>(
iteratee: (item: T) => U,
depth = 1 as D
): Array<FlatArray<U[], D>> {
return flatten(arr.map(item => iteratee(item)), depth);
return flatten(
arr.map(item => iteratee(item)),
depth
);
}
8 changes: 4 additions & 4 deletions src/array/forEachRight.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/**
* Iterates over elements of 'arr' from right to left and invokes 'callback' for each element.
*
*
* @template T - The type of elements in the array.
* @param {T[]} arr - The array to iterate over.
* @param {(value: T, index: number, arr: T[]) => void} callback - The function invoked per iteration.
* The callback function receives three arguments:
* - 'value': The current element being processed in the array.
* - 'index': The index of the current element being processed in the array.
* - 'arr': The array 'forEachRight' was called upon.
*
*
* @example
* const array = [1, 2, 3];
* const result: number[] = [];
*
*
* // Use the forEachRight function to iterate through the array and add each element to the result array.
* forEachRight(array, (value) => {
* result.push(value);
* })
*
*
* console.log(result) // Output: [3, 2, 1]
*/

Expand Down
2 changes: 1 addition & 1 deletion src/array/unzipWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param {T[][]} target - The nested array to unzip. This is an array of arrays,
* where each inner array contains elements to be unzipped.
* @param {(...args: T[]) => R} iteratee - A function to transform the unzipped elements.
* @returns {R[]} A new array of unzipped and transformed elements.
* @returns {R[]} A new array of unzipped and transformed elements.
*
* @example
* const nestedArray = [[1, 2], [3, 4], [5, 6]];
Expand Down
2 changes: 1 addition & 1 deletion src/compat/_internal/LARGE_ARRAY_SIZE.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const LARGE_ARRAY_SIZE = 200;
export const LARGE_ARRAY_SIZE = 200;
4 changes: 2 additions & 2 deletions src/compat/_internal/empties.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { falsey } from "./falsey.ts";
import { falsey } from './falsey.ts';

export const empties = [[], {}].concat(falsey.slice(1));
export const empties = [[], {}].concat(falsey.slice(1));
20 changes: 10 additions & 10 deletions src/compat/_internal/isDeepKey.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { describe, expect, it } from "vitest";
import { isDeepKey } from "./isDeepKey";
import { describe, expect, it } from 'vitest';
import { isDeepKey } from './isDeepKey';

describe("isDeepKey function", () => {
it("returns true for deep keys", () => {
expect(isDeepKey("a.b")).toBe(true);
expect(isDeepKey("a[b]")).toBe(true);
expect(isDeepKey("a.b.c")).toBe(true);
expect(isDeepKey("a[b][c]")).toBe(true);
describe('isDeepKey function', () => {
it('returns true for deep keys', () => {
expect(isDeepKey('a.b')).toBe(true);
expect(isDeepKey('a[b]')).toBe(true);
expect(isDeepKey('a.b.c')).toBe(true);
expect(isDeepKey('a[b][c]')).toBe(true);
});

it("returns false for non-deep keys", () => {
expect(isDeepKey("a")).toBe(false);
it('returns false for non-deep keys', () => {
expect(isDeepKey('a')).toBe(false);
expect(isDeepKey(123)).toBe(false);
});
});
4 changes: 2 additions & 2 deletions src/compat/_internal/isIndex.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/
const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;

export function isIndex(value: PropertyKey) {
switch (typeof value) {
Expand All @@ -12,4 +12,4 @@ export function isIndex(value: PropertyKey) {
return IS_UNSIGNED_INTEGER.test(value);
}
}
}
}
2 changes: 1 addition & 1 deletion src/compat/_internal/toArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export function toArgs(array: unknown[]): IArguments {
// eslint-disable-next-line prefer-rest-params
return arguments;
})(...array);
}
}
48 changes: 24 additions & 24 deletions src/compat/_internal/toPath.spec.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import { describe, expect, it } from "vitest";
import { toPath } from "./toPath";
import { describe, expect, it } from 'vitest';
import { toPath } from './toPath';

describe("toPath function", () => {
it("converts dot-separated keys correctly", () => {
const result = toPath("a.b.c");
expect(result).toEqual(["a", "b", "c"]);
describe('toPath function', () => {
it('converts dot-separated keys correctly', () => {
const result = toPath('a.b.c');
expect(result).toEqual(['a', 'b', 'c']);
});

it("converts bracket notation keys correctly", () => {
const result = toPath("a[b][c]");
expect(result).toEqual(["a", "b", "c"]);
it('converts bracket notation keys correctly', () => {
const result = toPath('a[b][c]');
expect(result).toEqual(['a', 'b', 'c']);
});

it("handles mixed notation correctly", () => {
const result = toPath("a[b].c");
expect(result).toEqual(["a", "b", "c"]);
it('handles mixed notation correctly', () => {
const result = toPath('a[b].c');
expect(result).toEqual(['a', 'b', 'c']);
});

it("handles leading dots correctly", () => {
const result = toPath(".a.b.c");
expect(result).toEqual(["", "a", "b", "c"]);
it('handles leading dots correctly', () => {
const result = toPath('.a.b.c');
expect(result).toEqual(['', 'a', 'b', 'c']);
});

it("handles quoted keys correctly", () => {
it('handles quoted keys correctly', () => {
const result = toPath('a["b.c"].d');
expect(result).toEqual(["a", "b.c", "d"]);
expect(result).toEqual(['a', 'b.c', 'd']);
});

it("handles empty input correctly", () => {
const result = toPath("");
it('handles empty input correctly', () => {
const result = toPath('');
expect(result).toEqual([]);
});

it("handles complex paths correctly", () => {
it('handles complex paths correctly', () => {
const result = toPath('a[-1.23]["[\\"b\\"]"].c[\'[\\\'d\\\']\'][\ne\n][f].g');
expect(result).toEqual(['a', '-1.23', '["b"]', 'c', "['d']", '\ne\n', 'f', 'g']);
});

it("handles complex input with leading dot correctly", () => {
it('handles complex input with leading dot correctly', () => {
const result = toPath('.a[b].c.d[e]["f.g"].h');
expect(result).toEqual(["", "a", "b", "c", "d", "e", "f.g", "h"]);
expect(result).toEqual(['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']);
});

it("handles empty brackets correctly", () => {
const result = toPath("a[].b");
it('handles empty brackets correctly', () => {
const result = toPath('a[].b');
expect(result).toEqual(['a', '', 'b']);
});
});
6 changes: 3 additions & 3 deletions src/compat/array/compact.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { compact } from "../../array/compact";
import { falsey } from "../_internal/falsey";
import { describe, expect, it } from 'vitest';
import { compact } from '../../array/compact';
import { falsey } from '../_internal/falsey';

/**
* @see https://github.com/lodash/lodash/blob/6a2cc1dfcf7634fea70d1bc5bd22db453df67b42/test/compact.spec.js#L1
Expand Down
Loading

0 comments on commit b24caf2

Please sign in to comment.