From be4162dc19003c7accde6c051edc0f85e3b72d76 Mon Sep 17 00:00:00 2001 From: Sojin Park Date: Sun, 11 Aug 2024 10:54:13 +0900 Subject: [PATCH] style: Apply prettier --- benchmarks/bundle-size/camelCase.spec.ts | 8 +- benchmarks/bundle-size/chunk.spec.ts | 10 +- benchmarks/bundle-size/difference.spec.ts | 8 +- benchmarks/bundle-size/isEqual.spec.ts | 8 +- benchmarks/bundle-size/utils/getBundleSize.ts | 2 +- benchmarks/bundle-size/zipObjectDeep.spec.ts | 8 +- benchmarks/performance/get.bench.ts | 20 +-- benchmarks/performance/isEqual.bench.ts | 5 +- benchmarks/performance/isMatch.bench.ts | 4 +- benchmarks/performance/matches.bench.ts | 2 +- benchmarks/performance/property.bench.ts | 6 +- docs/bundle-size.md | 3 +- docs/ko/bundle-size.md | 3 +- docs/ko/reference/array/difference.md | 2 +- docs/ko/reference/array/flatMap.md | 6 +- docs/ko/reference/array/forEachRight.md | 14 +- docs/ko/reference/array/without.md | 2 +- docs/ko/reference/array/zipObject.md | 2 +- docs/ko/reference/function/ary.md | 5 +- docs/ko/reference/object/flattenObject.md | 8 +- docs/reference/array/countBy.md | 5 +- docs/reference/array/difference.md | 2 +- docs/reference/array/flatMap.md | 6 +- docs/reference/array/forEachRight.md | 13 +- docs/reference/array/unzipWith.md | 2 +- docs/reference/function/ary.md | 5 +- docs/reference/object/flattenObject.md | 8 +- docs/reference/promise/withTimeout.md | 2 +- docs/reference/string/kebabCase.md | 38 ++--- docs/zh_hans/bundle-size.md | 4 +- docs/zh_hans/reference/array/compact.md | 1 + docs/zh_hans/reference/array/countBy.md | 6 +- docs/zh_hans/reference/array/flatMap.md | 6 +- docs/zh_hans/reference/array/forEachRight.md | 4 +- docs/zh_hans/reference/array/isSubset.md | 1 + docs/zh_hans/reference/math/randomInt.md | 2 +- .../zh_hans/reference/object/flattenObject.md | 10 +- jsr.json | 6 +- package.json | 2 +- src/array/countBy.spec.ts | 10 +- src/array/countBy.ts | 6 +- src/array/flatMap.ts | 5 +- src/array/forEachRight.ts | 8 +- src/array/unzipWith.ts | 2 +- src/compat/_internal/LARGE_ARRAY_SIZE.ts | 2 +- src/compat/_internal/arrayViews.ts | 7 +- src/compat/_internal/empties.ts | 4 +- src/compat/_internal/getSymbols.ts | 5 +- src/compat/_internal/identity.ts | 2 +- src/compat/_internal/isDeepKey.spec.ts | 20 +-- src/compat/_internal/isIndex.ts | 4 +- src/compat/_internal/numberProto.ts | 2 +- src/compat/_internal/tags.ts | 4 +- src/compat/_internal/toPath.spec.ts | 48 +++--- src/compat/array/compact.spec.ts | 6 +- src/compat/array/difference.spec.ts | 13 +- src/compat/array/difference.ts | 2 +- src/compat/array/zipObjectDeep.ts | 8 +- src/compat/function/ary.ts | 8 +- src/compat/function/bind.spec.ts | 6 +- src/compat/function/bind.ts | 2 +- src/compat/math/min.spec.ts | 5 +- src/compat/object/cloneDeep.ts | 3 +- src/compat/object/get.ts | 148 ++++++++++++------ src/compat/object/get.types.ts | 48 +++--- src/compat/object/mapValues.spec.ts | 2 - src/compat/object/property.ts | 8 +- src/compat/object/set.ts | 10 +- src/compat/predicate/isArray.spec.ts | 6 +- src/compat/predicate/isArrayLike.spec.ts | 4 +- src/compat/predicate/isArrayLike.ts | 5 +- src/compat/predicate/isBoolean.spec.ts | 2 +- src/compat/predicate/isBoolean.ts | 3 +- src/compat/predicate/isEqual.spec.ts | 121 +++++--------- src/compat/predicate/isMatch.spec.ts | 14 +- src/compat/predicate/isMatch.ts | 2 +- src/compat/predicate/isObjectLike.ts | 2 +- src/compat/predicate/matches.ts | 2 +- src/compat/string/padStart.ts | 6 +- src/function/ary.ts | 4 +- src/function/debounce.ts | 2 +- src/function/negate.spec.ts | 10 +- src/function/negate.ts | 2 +- src/function/unary.ts | 4 +- src/math/round.spec.ts | 4 +- src/object/clone.ts | 2 +- src/object/cloneDeep.spec.ts | 6 +- src/object/flattenObject.spec.ts | 86 +++++----- src/object/flattenObject.ts | 12 +- src/object/invert.ts | 2 +- src/predicate/isEqual.spec.ts | 4 +- src/predicate/isEqual.ts | 52 ++++-- src/predicate/isPlainObject.spec.ts | 6 +- src/predicate/isPlainObject.ts | 6 +- src/promise/withTimeout.ts | 6 +- src/string/camelCase.spec.ts | 44 +++--- src/string/camelCase.ts | 9 +- tests/utils/createPackageTarball.ts | 4 +- tests/utils/createTmpDir.ts | 2 +- tests/utils/parseTar.ts | 2 +- vitest.config.mts | 2 +- 101 files changed, 534 insertions(+), 551 deletions(-) diff --git a/benchmarks/bundle-size/camelCase.spec.ts b/benchmarks/bundle-size/camelCase.spec.ts index 851f6ccf..dcef3317 100644 --- a/benchmarks/bundle-size/camelCase.spec.ts +++ b/benchmarks/bundle-size/camelCase.spec.ts @@ -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 () => { @@ -10,5 +10,5 @@ describe('camelCase bundle size', () => { it('es-toolkit', async () => { const bundleSize = await getBundleSize('es-toolkit', 'camelCase'); expect(bundleSize).toMatchInlineSnapshot(`297`); - }) -}); \ No newline at end of file + }); +}); diff --git a/benchmarks/bundle-size/chunk.spec.ts b/benchmarks/bundle-size/chunk.spec.ts index c4f74fd1..2ba5f704 100644 --- a/benchmarks/bundle-size/chunk.spec.ts +++ b/benchmarks/bundle-size/chunk.spec.ts @@ -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 () => { @@ -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`); - }) -}); \ No newline at end of file + }); +}); diff --git a/benchmarks/bundle-size/difference.spec.ts b/benchmarks/bundle-size/difference.spec.ts index 8f579399..a3522fb7 100644 --- a/benchmarks/bundle-size/difference.spec.ts +++ b/benchmarks/bundle-size/difference.spec.ts @@ -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 () => { @@ -10,5 +10,5 @@ describe('difference bundle size', () => { it('es-toolkit', async () => { const bundleSize = await getBundleSize('es-toolkit', 'difference'); expect(bundleSize).toMatchInlineSnapshot(`90`); - }) -}); \ No newline at end of file + }); +}); diff --git a/benchmarks/bundle-size/isEqual.spec.ts b/benchmarks/bundle-size/isEqual.spec.ts index ead41221..332136d6 100644 --- a/benchmarks/bundle-size/isEqual.spec.ts +++ b/benchmarks/bundle-size/isEqual.spec.ts @@ -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('isEqual bundle size', () => { it('lodash-es', async () => { @@ -10,5 +10,5 @@ describe('isEqual bundle size', () => { it('es-toolkit', async () => { const bundleSize = await getBundleSize('es-toolkit', 'isEqual'); expect(bundleSize).toMatchInlineSnapshot(`2930`); - }) -}); \ No newline at end of file + }); +}); diff --git a/benchmarks/bundle-size/utils/getBundleSize.ts b/benchmarks/bundle-size/utils/getBundleSize.ts index e09fb3a8..df4aa53d 100644 --- a/benchmarks/bundle-size/utils/getBundleSize.ts +++ b/benchmarks/bundle-size/utils/getBundleSize.ts @@ -17,4 +17,4 @@ export async function getBundleSize(pkg: 'lodash-es' | 'es-toolkit' | 'es-toolki }); return Buffer.from(bundled.outputFiles![0].contents).byteLength; -} \ No newline at end of file +} diff --git a/benchmarks/bundle-size/zipObjectDeep.spec.ts b/benchmarks/bundle-size/zipObjectDeep.spec.ts index 641befc0..e89e3ece 100644 --- a/benchmarks/bundle-size/zipObjectDeep.spec.ts +++ b/benchmarks/bundle-size/zipObjectDeep.spec.ts @@ -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 () => { @@ -10,5 +10,5 @@ describe('zipObjectDeep bundle size', () => { it('es-toolkit/compat', async () => { const bundleSize = await getBundleSize('es-toolkit/compat', 'zipObjectDeep'); expect(bundleSize).toMatchInlineSnapshot(`992`); - }) -}); \ No newline at end of file + }); +}); diff --git a/benchmarks/performance/get.bench.ts b/benchmarks/performance/get.bench.ts index 1919a86f..7779b0dd 100644 --- a/benchmarks/performance/get.bench.ts +++ b/benchmarks/performance/get.bench.ts @@ -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']) - }) -}) \ No newline at end of file + getLodash({ a: { b: 3 } }, ['a', 'b']); + }); +}); diff --git a/benchmarks/performance/isEqual.bench.ts b/benchmarks/performance/isEqual.bench.ts index 7a2ffa90..0687f3e9 100644 --- a/benchmarks/performance/isEqual.bench.ts +++ b/benchmarks/performance/isEqual.bench.ts @@ -28,7 +28,6 @@ import { isEqual as isEqualLodash } from 'lodash'; // }); // }); - // describe('isEqual dates', () => { // bench('es-toolkit/isEqual', () => { // isEqualToolkit(new Date('2020-01-01'), new Date('2020-01-01')); @@ -65,7 +64,7 @@ describe('isEqual objects', () => { isEqualLodash({ a: 1, b: { c: 2 } }, { a: 1, b: { c: 3 } }); isEqualLodash({ a: 1, b: 2 }, { a: 1, b: 2 }); }); -}) +}); // describe('isEqual arrays', () => { // bench('es-toolkit/isEqual', () => { @@ -78,5 +77,3 @@ describe('isEqual objects', () => { // isEqualLodash([1, 2, 3], [1, 2, 4]); // }); // }) - - diff --git a/benchmarks/performance/isMatch.bench.ts b/benchmarks/performance/isMatch.bench.ts index c8f27c7b..a4369eed 100644 --- a/benchmarks/performance/isMatch.bench.ts +++ b/benchmarks/performance/isMatch.bench.ts @@ -4,9 +4,9 @@ import { isMatch as isMatchLodash } from 'lodash'; describe('isMatch', () => { bench('es-toolkit/isMatch', () => { - isMatchToolkit({ a: { b: { c: 1, d: 2 }, e: 3 }, f: 4 }, { a: { b: { c: 1 } } }) + isMatchToolkit({ a: { b: { c: 1, d: 2 }, e: 3 }, f: 4 }, { a: { b: { c: 1 } } }); }); bench('lodash/isMatch', () => { - isMatchLodash({ a: { b: { c: 1, d: 2 }, e: 3 }, f: 4 }, { a: { b: { c: 1 } } }) + isMatchLodash({ a: { b: { c: 1, d: 2 }, e: 3 }, f: 4 }, { a: { b: { c: 1 } } }); }); }); diff --git a/benchmarks/performance/matches.bench.ts b/benchmarks/performance/matches.bench.ts index 6f0be00b..6402b88c 100644 --- a/benchmarks/performance/matches.bench.ts +++ b/benchmarks/performance/matches.bench.ts @@ -4,7 +4,7 @@ import { matches as matchesLodash } from 'lodash'; describe('matches', () => { bench('es-toolkit/matches', () => { - const isMatch = matchesToolkit({ a: { b: { c: 1 } } }) + const isMatch = matchesToolkit({ a: { b: { c: 1 } } }); isMatch({ a: { b: { c: 1, d: 2 }, e: 3 }, f: 4 }); }); bench('lodash/matches', () => { diff --git a/benchmarks/performance/property.bench.ts b/benchmarks/performance/property.bench.ts index f81ed90b..e9f79d71 100644 --- a/benchmarks/performance/property.bench.ts +++ b/benchmarks/performance/property.bench.ts @@ -6,10 +6,10 @@ describe('property', () => { bench('es-toolkit/property', () => { const getValue = propertyToolkit('a.b'); getValue({ 'a.b': 1, a: { b: 1 } }); - }) + }); bench('lodash/property', () => { const getValue = propertyLodash('a.b'); getValue({ 'a.b': 1, a: { b: 1 } }); - }) -}) + }); +}); diff --git a/docs/bundle-size.md b/docs/bundle-size.md index fe0c90f6..d6ac524c 100644 --- a/docs/bundle-size.md +++ b/docs/bundle-size.md @@ -27,11 +27,10 @@ This makes es-toolkit the most efficient in terms of bundle size, with some util Our bundle size is measured using [esbuild 0.23.0](https://esbuild.github.io), by analyzing the size of code like the following: ```tsx -import { chunk } from 'es-toolkit'; +import { chunk } from 'es-toolkit'; // or import { chunk } from 'lodash-es'; console.log(chunk); ``` See our [bundle size benchmark code](https://github.com/toss/es-toolkit/tree/main/benchmarks/bundle-size) for details. - diff --git a/docs/ko/bundle-size.md b/docs/ko/bundle-size.md index 233198b5..283edb37 100644 --- a/docs/ko/bundle-size.md +++ b/docs/ko/bundle-size.md @@ -22,13 +22,12 @@ es-toolkit은 현대적인 구현을 가지고 있기 때문에, 다른 라이 | [pick](./reference/object/pick.md) | 657 bytes | 3860 bytes | -83.0% | | [zip](./reference/array/zip.md) | 797 bytes | 1790 bytes | -55.5% | - ## 번들 사이즈 측정 방법 [esbuild 0.23.0](https://esbuild.github.io)로 번들 사이즈를 측정하고 있어요. 아래와 같은 코드를 사용해요. ```tsx -import { chunk } from 'es-toolkit'; +import { chunk } from 'es-toolkit'; // or import { chunk } from 'lodash-es'; console.log(chunk); diff --git a/docs/ko/reference/array/difference.md b/docs/ko/reference/array/difference.md index 2f9fa052..f4dedddb 100644 --- a/docs/ko/reference/array/difference.md +++ b/docs/ko/reference/array/difference.md @@ -37,4 +37,4 @@ const result = difference(array1, array2); | | [번들 사이즈](../../bundle-size.md) | [성능](../../performance.md) | | ---------- | ----------------------------------- | ---------------------------- | | es-toolkit | 90 바이트 (92.4% 작음) | 9,317,227 회 (85% 빠름) | -| lodash-es | 7,958 바이트 | 5,030,861 회 | \ No newline at end of file +| lodash-es | 7,958 바이트 | 5,030,861 회 | diff --git a/docs/ko/reference/array/flatMap.md b/docs/ko/reference/array/flatMap.md index 553783b0..4b2247a3 100644 --- a/docs/ko/reference/array/flatMap.md +++ b/docs/ko/reference/array/flatMap.md @@ -7,11 +7,7 @@ JavaScript 언어에 포함된 [Array#flat](https://developer.mozilla.org/en-US/ ## 인터페이스 ```typescript -function flatMap( - arr: T[], - iteratee: (item: T) => U, - depth?: D -): Array>; +function flatMap(arr: T[], iteratee: (item: T) => U, depth?: D): Array>; ``` ### 파라미터 diff --git a/docs/ko/reference/array/forEachRight.md b/docs/ko/reference/array/forEachRight.md index 94d8db4b..c6a798f8 100644 --- a/docs/ko/reference/array/forEachRight.md +++ b/docs/ko/reference/array/forEachRight.md @@ -11,10 +11,10 @@ function forEachRight(arr: T[], callback: (value: T, index: number, arr: T[]) ### 파라미터 - `arr`: (`T[]`): 순회할 배열. -- `callback`: (`(value: T, index: number, arr: T[])`): 각 반복마다 호출될 함수예요. - - `value`: 배열에서 처리 중인 현재 요소. - - `index`: 배열에서 처리 중인 현재 요소의 인덱스. - - `arr`: `forEachRight` 함수가 호출된 배열. +- `callback`: (`(value: T, index: number, arr: T[])`): 각 반복마다 호출될 함수예요. + - `value`: 배열에서 처리 중인 현재 요소. + - `index`: 배열에서 처리 중인 현재 요소의 인덱스. + - `arr`: `forEachRight` 함수가 호출된 배열. ### 반환 값 @@ -29,9 +29,9 @@ const array = [1, 2, 3]; const result: number[] = []; // forEachRight 함수를 사용하여 배열을 순회하며 각 요소를 결과 배열에 추가해요. -forEachRight(array, (value) => { +forEachRight(array, value => { result.push(value); }); -console.log(result) // Output: [3, 2, 1]; -``` \ No newline at end of file +console.log(result); // Output: [3, 2, 1]; +``` diff --git a/docs/ko/reference/array/without.md b/docs/ko/reference/array/without.md index 9916b5bc..59d45ca3 100644 --- a/docs/ko/reference/array/without.md +++ b/docs/ko/reference/array/without.md @@ -1,6 +1,6 @@ # without -배열에서 주어진 값을 제거한 새로운 배열을 만들어요. +배열에서 주어진 값을 제거한 새로운 배열을 만들어요. 값이 같은지는 [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero) 기준으로 비교하기 때문에, `NaN`과도 사용할 수 있어요. diff --git a/docs/ko/reference/array/zipObject.md b/docs/ko/reference/array/zipObject.md index f9a9243a..0b77cd8b 100644 --- a/docs/ko/reference/array/zipObject.md +++ b/docs/ko/reference/array/zipObject.md @@ -1,6 +1,6 @@ # zipObject -두 배열을 하나의 객체로 결합해요. 첫 번째 배열은 프로퍼티 이름을 나타내고, 두 번째 배열은 값을 나타내요. +두 배열을 하나의 객체로 결합해요. 첫 번째 배열은 프로퍼티 이름을 나타내고, 두 번째 배열은 값을 나타내요. 프로퍼티 이름을 나타내는 배열이 값을 나타내는 배열보다 길면, 값들은 `undefined`로 채워져요. diff --git a/docs/ko/reference/function/ary.md b/docs/ko/reference/function/ary.md index c400c9b1..050ed4a5 100644 --- a/docs/ko/reference/function/ary.md +++ b/docs/ko/reference/function/ary.md @@ -5,10 +5,7 @@ ## 인터페이스 ```typescript -function ary any>( - func: F, - n: number -): (...args: any[]) => ReturnType; +function ary any>(func: F, n: number): (...args: any[]) => ReturnType; ``` ### 파라미터 diff --git a/docs/ko/reference/object/flattenObject.md b/docs/ko/reference/object/flattenObject.md index ad053994..bdfc3905 100644 --- a/docs/ko/reference/object/flattenObject.md +++ b/docs/ko/reference/object/flattenObject.md @@ -25,14 +25,14 @@ function flattenObject(object: object): Record; const nestedObject = { a: { b: { - c: 1 - } + c: 1, + }, }, - d: [2, 3] + d: [2, 3], }; const flattened = flattenObject(nestedObject); -console.log(flattened); +console.log(flattened); // Output: // { // 'a.b.c': 1, diff --git a/docs/reference/array/countBy.md b/docs/reference/array/countBy.md index 8d731a99..986b7a38 100644 --- a/docs/reference/array/countBy.md +++ b/docs/reference/array/countBy.md @@ -5,7 +5,7 @@ Count the occurrences of each item in an array based on a `mapper` function. ## Signature ```typescript -function countBy(arr: T[], mapper: (item: T) => string): Record +function countBy(arr: T[], mapper: (item: T) => string): Record; ``` ### Parameters @@ -23,9 +23,8 @@ function countBy(arr: T[], mapper: (item: T) => string): Record x % 2 === 0 ? 'even' : 'odd'); +const result = countBy(array, x => (x % 2 === 0 ? 'even' : 'odd')); console.log(result); // Output: { 'odd': 3, 'even': 3 } ``` - diff --git a/docs/reference/array/difference.md b/docs/reference/array/difference.md index e5f561dc..d0c5a3e7 100644 --- a/docs/reference/array/difference.md +++ b/docs/reference/array/difference.md @@ -38,4 +38,4 @@ const result = difference(array1, array2); | | [Bundle Size](../../bundle-size.md) | [Performance](../../performance.md) | | ---------- | ----------------------------------- | ----------------------------------- | | es-toolkit | 90 bytes (92.4% smaller) | 9,317,227 times (85% faster) | -| lodash-es | 7,958 bytes | 5,030,861 times | \ No newline at end of file +| lodash-es | 7,958 bytes | 5,030,861 times | diff --git a/docs/reference/array/flatMap.md b/docs/reference/array/flatMap.md index 3501f60f..9bbd77c4 100644 --- a/docs/reference/array/flatMap.md +++ b/docs/reference/array/flatMap.md @@ -7,11 +7,7 @@ It works the same as if you called [Array#flat](https://developer.mozilla.org/en ## Signature ```typescript -function flatMap( - arr: T[], - iteratee: (item: T) => U, - depth?: D -): Array>; +function flatMap(arr: T[], iteratee: (item: T) => U, depth?: D): Array>; ``` ### Parameters diff --git a/docs/reference/array/forEachRight.md b/docs/reference/array/forEachRight.md index 7291dd2e..0266ea1a 100644 --- a/docs/reference/array/forEachRight.md +++ b/docs/reference/array/forEachRight.md @@ -2,7 +2,6 @@ Iterates over elements of `arr` from right to left and invokes `callback` for each element. - ## Signature ```ts @@ -13,9 +12,9 @@ function forEachRight(arr: T[], callback: (value: T, index: number, arr: T[]) - `arr` (`T[]`): The array to iterate over. - `callback` (`(value: T, index: number, arr: T[])`): The function invoked per iteration. - - `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. + - `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. ### Returns @@ -30,9 +29,9 @@ 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) => { +forEachRight(array, value => { result.push(value); }); -console.log(result) // Output: [3, 2, 1]; -``` \ No newline at end of file +console.log(result); // Output: [3, 2, 1]; +``` diff --git a/docs/reference/array/unzipWith.md b/docs/reference/array/unzipWith.md index cfe9d36a..48fbec3f 100644 --- a/docs/reference/array/unzipWith.md +++ b/docs/reference/array/unzipWith.md @@ -15,7 +15,7 @@ function unzipWith(target: T[][], iteratee: (...args: T[]) => R): R[]; ### Returns -(`R[]`): A new array of unzipped and transformed elements. +(`R[]`): A new array of unzipped and transformed elements. ## Examples diff --git a/docs/reference/function/ary.md b/docs/reference/function/ary.md index dee9c852..bd64a785 100644 --- a/docs/reference/function/ary.md +++ b/docs/reference/function/ary.md @@ -5,10 +5,7 @@ Creates a function that invokes func, with up to n arguments, ignoring any addit ## Signature ```typescript -function ary any>( - func: F, - n: number -): (...args: any[]) => ReturnType; +function ary any>(func: F, n: number): (...args: any[]) => ReturnType; ``` ### Parameters diff --git a/docs/reference/object/flattenObject.md b/docs/reference/object/flattenObject.md index 24b968d6..2222e4f8 100644 --- a/docs/reference/object/flattenObject.md +++ b/docs/reference/object/flattenObject.md @@ -25,14 +25,14 @@ function flattenObject(object: object): Record; const nestedObject = { a: { b: { - c: 1 - } + c: 1, + }, }, - d: [2, 3] + d: [2, 3], }; const flattened = flattenObject(nestedObject); -console.log(flattened); +console.log(flattened); // Output: // { // 'a.b.c': 1, diff --git a/docs/reference/promise/withTimeout.md b/docs/reference/promise/withTimeout.md index 7ae59429..e771cf20 100644 --- a/docs/reference/promise/withTimeout.md +++ b/docs/reference/promise/withTimeout.md @@ -1,6 +1,6 @@ # withTimeout -Executes an async function and enforces a timeout. +Executes an async function and enforces a timeout. If the promise does not resolve within the specified time, the timeout will trigger and the returned promise will be rejected. diff --git a/docs/reference/string/kebabCase.md b/docs/reference/string/kebabCase.md index f9561c99..ba69a6b9 100644 --- a/docs/reference/string/kebabCase.md +++ b/docs/reference/string/kebabCase.md @@ -1,30 +1,30 @@ - # kebabCase +# kebabCase - Converts a string to kebab case. +Converts a string to kebab case. - Kebab case is the naming convention in which each word is written in lowercase and separated by an dash (\-) character. For example, `kebab-case`. +Kebab case is the naming convention in which each word is written in lowercase and separated by an dash (\-) character. For example, `kebab-case`. - ## Signature +## Signature - ```typescript - function kebabCase(str: string): string; - ``` +```typescript +function kebabCase(str: string): string; +``` - ### Parameters +### Parameters - - `str` (`string`): The string that is to be changed to kebab case. +- `str` (`string`): The string that is to be changed to kebab case. - ### Returns +### Returns - (`string`) The converted string to kebab case. +(`string`) The converted string to kebab case. - ## Examples +## Examples - ```typescript - import { kebabCase } from 'es-toolkit/string'; +```typescript +import { kebabCase } from 'es-toolkit/string'; - kebabCase('camelCase'); // returns 'camel-case' - kebabCase('some whitespace'); // returns 'some-whitespace' - kebabCase('hyphen-text'); // returns 'hyphen-text' - kebabCase('HTTPRequest'); // returns 'http-request' - ``` +kebabCase('camelCase'); // returns 'camel-case' +kebabCase('some whitespace'); // returns 'some-whitespace' +kebabCase('hyphen-text'); // returns 'hyphen-text' +kebabCase('HTTPRequest'); // returns 'http-request' +``` diff --git a/docs/zh_hans/bundle-size.md b/docs/zh_hans/bundle-size.md index 3addebc1..1b0ac9fe 100644 --- a/docs/zh_hans/bundle-size.md +++ b/docs/zh_hans/bundle-size.md @@ -27,10 +27,10 @@ description: es-toolkit提供的最小包体积 我们的包体积是使用 [esbuild 0.23.0](https://esbuild.github.io) 测量的,通过分析如下代码的大小: ```tsx -import { chunk } from 'es-toolkit'; +import { chunk } from 'es-toolkit'; // 或 import { chunk } from 'lodash-es'; console.log(chunk); ``` -有关详细信息,请参见我们的[包体积基准代码](https://github.com/toss/es-toolkit/tree/main/benchmarks/bundle-size)。 \ No newline at end of file +有关详细信息,请参见我们的[包体积基准代码](https://github.com/toss/es-toolkit/tree/main/benchmarks/bundle-size)。 diff --git a/docs/zh_hans/reference/array/compact.md b/docs/zh_hans/reference/array/compact.md index 159ec31a..5cb8c6bf 100644 --- a/docs/zh_hans/reference/array/compact.md +++ b/docs/zh_hans/reference/array/compact.md @@ -21,3 +21,4 @@ function compact(arr: T[]): Array(arr: T[], mapper: (item: T) => string): Record +function countBy(arr: T[], mapper: (item: T) => string): Record; ``` ### 参数 @@ -23,7 +23,7 @@ function countBy(arr: T[], mapper: (item: T) => string): Record x % 2 === 0 ? 'even' : 'odd'); +const result = countBy(array, x => (x % 2 === 0 ? 'even' : 'odd')); console.log(result); // 输出: { 'odd': 3, 'even': 3 } diff --git a/docs/zh_hans/reference/array/flatMap.md b/docs/zh_hans/reference/array/flatMap.md index 38303412..6d29b1d0 100644 --- a/docs/zh_hans/reference/array/flatMap.md +++ b/docs/zh_hans/reference/array/flatMap.md @@ -7,11 +7,7 @@ ## 签名 ```typescript -function flatMap( - arr: T[], - iteratee: (item: T) => U, - depth?: D -): Array>; +function flatMap(arr: T[], iteratee: (item: T) => U, depth?: D): Array>; ``` ### 参数 diff --git a/docs/zh_hans/reference/array/forEachRight.md b/docs/zh_hans/reference/array/forEachRight.md index 5061de77..3a5701ba 100644 --- a/docs/zh_hans/reference/array/forEachRight.md +++ b/docs/zh_hans/reference/array/forEachRight.md @@ -29,9 +29,9 @@ const array = [1, 2, 3]; const result: number[] = []; // 使用 `forEachRight` 函数迭代数组,并将每个元素添加到结果数组中。 -forEachRight(array, (value) => { +forEachRight(array, value => { result.push(value); }); -console.log(result) // Output: [3, 2, 1]; +console.log(result); // Output: [3, 2, 1]; ``` diff --git a/docs/zh_hans/reference/array/isSubset.md b/docs/zh_hans/reference/array/isSubset.md index f3dac400..376c3070 100644 --- a/docs/zh_hans/reference/array/isSubset.md +++ b/docs/zh_hans/reference/array/isSubset.md @@ -31,3 +31,4 @@ const subset2 = ['a', 'd']; isSubset(superset2, subset2); // 返回 false +``` diff --git a/docs/zh_hans/reference/math/randomInt.md b/docs/zh_hans/reference/math/randomInt.md index 645a2cf9..2bc32a8c 100644 --- a/docs/zh_hans/reference/math/randomInt.md +++ b/docs/zh_hans/reference/math/randomInt.md @@ -18,7 +18,7 @@ function randomInt(minimum: number, maximum: number): number; ### 返回值 -- (`number`): 指定范围内的随机整数。 +- (`number`): 指定范围内的随机整数。 ## 示例 diff --git a/docs/zh_hans/reference/object/flattenObject.md b/docs/zh_hans/reference/object/flattenObject.md index 092674fc..a5687c07 100644 --- a/docs/zh_hans/reference/object/flattenObject.md +++ b/docs/zh_hans/reference/object/flattenObject.md @@ -25,18 +25,18 @@ function flattenObject(object: object): Record; const nestedObject = { a: { b: { - c: 1 - } + c: 1, + }, }, - d: [2, 3] + d: [2, 3], }; const flattened = flattenObject(nestedObject); -console.log(flattened); +console.log(flattened); // 输出: // { // 'a.b.c': 1, // 'd.0': 2, // 'd.1': 3 // } -``` \ No newline at end of file +``` diff --git a/jsr.json b/jsr.json index 32679e26..fbc1f447 100644 --- a/jsr.json +++ b/jsr.json @@ -6,8 +6,6 @@ "./compat": "./src/compat/index.ts" }, "publish": { - "include": [ - "./src/**/*.ts" - ] + "include": ["./src/**/*.ts"] } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 4b71ecf6..46841dd3 100644 --- a/package.json +++ b/package.json @@ -170,4 +170,4 @@ "lint": "eslint ./src --ext .ts", "format": "prettier --write ." } -} \ No newline at end of file +} diff --git a/src/array/countBy.spec.ts b/src/array/countBy.spec.ts index b8bd2544..c021adbb 100644 --- a/src/array/countBy.spec.ts +++ b/src/array/countBy.spec.ts @@ -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', () => { @@ -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, }); - }) + }); }); diff --git a/src/array/countBy.ts b/src/array/countBy.ts index f2943f83..60bd2c34 100644 --- a/src/array/countBy.ts +++ b/src/array/countBy.ts @@ -17,12 +17,12 @@ */ export function countBy(arr: T[], mapper: (item: T) => string): Record { const result: Record = {}; - + for (const item of arr) { const key = mapper(item); - + result[key] = (result[key] ?? 0) + 1; } - + return result; } diff --git a/src/array/flatMap.ts b/src/array/flatMap.ts index 7f863994..3aaa6576 100644 --- a/src/array/flatMap.ts +++ b/src/array/flatMap.ts @@ -25,5 +25,8 @@ export function flatMap( iteratee: (item: T) => U, depth = 1 as D ): Array> { - return flatten(arr.map(item => iteratee(item)), depth); + return flatten( + arr.map(item => iteratee(item)), + depth + ); } diff --git a/src/array/forEachRight.ts b/src/array/forEachRight.ts index 4c7028e0..352348db 100644 --- a/src/array/forEachRight.ts +++ b/src/array/forEachRight.ts @@ -1,6 +1,6 @@ /** * 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. @@ -8,16 +8,16 @@ * - '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] */ diff --git a/src/array/unzipWith.ts b/src/array/unzipWith.ts index 4ec68f90..0aa89dbf 100644 --- a/src/array/unzipWith.ts +++ b/src/array/unzipWith.ts @@ -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]]; diff --git a/src/compat/_internal/LARGE_ARRAY_SIZE.ts b/src/compat/_internal/LARGE_ARRAY_SIZE.ts index 6c52a13b..687e4b99 100644 --- a/src/compat/_internal/LARGE_ARRAY_SIZE.ts +++ b/src/compat/_internal/LARGE_ARRAY_SIZE.ts @@ -1 +1 @@ -export const LARGE_ARRAY_SIZE = 200; \ No newline at end of file +export const LARGE_ARRAY_SIZE = 200; diff --git a/src/compat/_internal/arrayViews.ts b/src/compat/_internal/arrayViews.ts index d984c947..2c0e4fdb 100644 --- a/src/compat/_internal/arrayViews.ts +++ b/src/compat/_internal/arrayViews.ts @@ -1,6 +1,3 @@ -import { typedArrays } from "./typedArrays"; +import { typedArrays } from './typedArrays'; -export const arrayViews = [ - ...typedArrays, - 'DataView' -]; \ No newline at end of file +export const arrayViews = [...typedArrays, 'DataView']; diff --git a/src/compat/_internal/empties.ts b/src/compat/_internal/empties.ts index 56e03b25..7903b2e2 100644 --- a/src/compat/_internal/empties.ts +++ b/src/compat/_internal/empties.ts @@ -1,3 +1,3 @@ -import { falsey } from "./falsey.ts"; +import { falsey } from './falsey.ts'; -export const empties = [[], {}].concat(falsey.slice(1)); \ No newline at end of file +export const empties = [[], {}].concat(falsey.slice(1)); diff --git a/src/compat/_internal/getSymbols.ts b/src/compat/_internal/getSymbols.ts index f28cc560..a47f0331 100644 --- a/src/compat/_internal/getSymbols.ts +++ b/src/compat/_internal/getSymbols.ts @@ -1,4 +1,3 @@ export function getSymbols(object: {}) { - return Object.getOwnPropertySymbols(object) - .filter(symbol => object.propertyIsEnumerable(symbol)); -} \ No newline at end of file + return Object.getOwnPropertySymbols(object).filter(symbol => object.propertyIsEnumerable(symbol)); +} diff --git a/src/compat/_internal/identity.ts b/src/compat/_internal/identity.ts index aacc8032..af8922b4 100644 --- a/src/compat/_internal/identity.ts +++ b/src/compat/_internal/identity.ts @@ -1,3 +1,3 @@ export function identity(x: T) { return x; -} \ No newline at end of file +} diff --git a/src/compat/_internal/isDeepKey.spec.ts b/src/compat/_internal/isDeepKey.spec.ts index a212469f..0d80f2f0 100644 --- a/src/compat/_internal/isDeepKey.spec.ts +++ b/src/compat/_internal/isDeepKey.spec.ts @@ -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); }); }); diff --git a/src/compat/_internal/isIndex.ts b/src/compat/_internal/isIndex.ts index 018e5adb..f7025e4c 100644 --- a/src/compat/_internal/isIndex.ts +++ b/src/compat/_internal/isIndex.ts @@ -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) { @@ -12,4 +12,4 @@ export function isIndex(value: PropertyKey) { return IS_UNSIGNED_INTEGER.test(value); } } -} \ No newline at end of file +} diff --git a/src/compat/_internal/numberProto.ts b/src/compat/_internal/numberProto.ts index 6dd22033..4dac6650 100644 --- a/src/compat/_internal/numberProto.ts +++ b/src/compat/_internal/numberProto.ts @@ -1 +1 @@ -export const numberProto: any = Number.prototype; \ No newline at end of file +export const numberProto: any = Number.prototype; diff --git a/src/compat/_internal/tags.ts b/src/compat/_internal/tags.ts index d4c38be8..328ecf3e 100644 --- a/src/compat/_internal/tags.ts +++ b/src/compat/_internal/tags.ts @@ -12,7 +12,7 @@ export const functionTag = '[object Function]'; export const arrayBufferTag = '[object ArrayBuffer]'; export const objectTag = '[object Object]'; export const errorTag = '[object Error]'; -export const dataViewTag = '[object DataView]' +export const dataViewTag = '[object DataView]'; export const uint8ArrayTag = '[object Uint8Array]'; export const uint8ClampedArrayTag = '[object Uint8ClampedArray]'; export const uint16ArrayTag = '[object Uint16Array]'; @@ -23,4 +23,4 @@ export const int16ArrayTag = '[object Int16Array]'; export const int32ArrayTag = '[object Int32Array]'; export const bigInt64ArrayTag = '[object BigInt64Array]'; export const float32ArrayTag = '[object Float32Array]'; -export const float64ArrayTag = '[object Float64Array]'; \ No newline at end of file +export const float64ArrayTag = '[object Float64Array]'; diff --git a/src/compat/_internal/toPath.spec.ts b/src/compat/_internal/toPath.spec.ts index 21a82ad3..f30f5297 100644 --- a/src/compat/_internal/toPath.spec.ts +++ b/src/compat/_internal/toPath.spec.ts @@ -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']); }); }); diff --git a/src/compat/array/compact.spec.ts b/src/compat/array/compact.spec.ts index 354f69f8..f1a88799 100644 --- a/src/compat/array/compact.spec.ts +++ b/src/compat/array/compact.spec.ts @@ -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 diff --git a/src/compat/array/difference.spec.ts b/src/compat/array/difference.spec.ts index fd9c474f..56b1dce2 100644 --- a/src/compat/array/difference.spec.ts +++ b/src/compat/array/difference.spec.ts @@ -1,13 +1,12 @@ -import { describe, expect, it } from "vitest"; -import { difference } from "./difference"; -import { LARGE_ARRAY_SIZE } from "../_internal/LARGE_ARRAY_SIZE"; -import { range } from "../../math/range"; +import { describe, expect, it } from 'vitest'; +import { difference } from './difference'; +import { LARGE_ARRAY_SIZE } from '../_internal/LARGE_ARRAY_SIZE'; +import { range } from '../../math/range'; /** * @see https://github.com/lodash/lodash/blob/6a2cc1dfcf7634fea70d1bc5bd22db453df67b42/test/difference-methods.spec.js#L1 */ describe('difference', () => { - it(`should return the difference of two arrays`, () => { const actual = difference([2, 1], [2, 3]); expect(actual).toEqual([1]); @@ -21,7 +20,7 @@ describe('difference', () => { it(`should treat \`-0\` as \`0\``, () => { const array = [-0, 0]; - const actual = array.map((value) => difference(array, [value])); + const actual = array.map(value => difference(array, [value])); expect(actual).toEqual([[], []]); @@ -49,7 +48,7 @@ describe('difference', () => { it(`should work with large arrays of \`-0\` as \`0\``, () => { const array = [-0, 0]; - const actual = array.map((value) => { + const actual = array.map(value => { const largeArray = Array.from({ length: LARGE_ARRAY_SIZE }).map(() => value); return difference(array, largeArray); diff --git a/src/compat/array/difference.ts b/src/compat/array/difference.ts index c5cbc435..d46d226c 100644 --- a/src/compat/array/difference.ts +++ b/src/compat/array/difference.ts @@ -6,4 +6,4 @@ export function difference(arr: readonly T[], ...values: Array) const arr2 = flatten(values); return differenceToolkit(arr1, arr2); -} \ No newline at end of file +} diff --git a/src/compat/array/zipObjectDeep.ts b/src/compat/array/zipObjectDeep.ts index 33a7b993..76565b59 100644 --- a/src/compat/array/zipObjectDeep.ts +++ b/src/compat/array/zipObjectDeep.ts @@ -1,5 +1,5 @@ -import { zip } from "../../array/zip.ts"; -import { set } from "../object/set.ts"; +import { zip } from '../../array/zip.ts'; +import { set } from '../object/set.ts'; /** * Creates a deeply nested object given arrays of paths and values. @@ -7,7 +7,7 @@ import { set } from "../object/set.ts"; * This function takes two arrays: one containing arrays of property paths, and the other containing corresponding values. * It returns a new object where paths from the first array are used as key paths to set values, with corresponding elements from the second array as values. * Paths can be dot-separated strings or arrays of property names. - * + * * If the `keys` array is longer than the `values` array, the remaining keys will have `undefined` as their values. * * @template V - The type of elements in the array. @@ -26,7 +26,7 @@ import { set } from "../object/set.ts"; * const values = [1, 2]; * const result = zipObjectDeep(paths, values); * // result will be { a: { b: { c: 1 } }, d: { e: { f: 2 } } } - * + * * @example * const paths = ['a.b[0].c', 'a.b[1].d']; * const values = [1, 2]; diff --git a/src/compat/function/ary.ts b/src/compat/function/ary.ts index 45584697..6900b92d 100644 --- a/src/compat/function/ary.ts +++ b/src/compat/function/ary.ts @@ -8,7 +8,11 @@ import { ary as aryToolkit } from '../../function/ary.ts'; * @param {number} n - The arity cap. * @returns {(...args: any[]) => ReturnType} Returns the new capped function. */ -export function ary any>(func: F, n: number = func.length, guard?: unknown): ((...args: any[]) => ReturnType) { +export function ary any>( + func: F, + n: number = func.length, + guard?: unknown +): (...args: any[]) => ReturnType { if (guard) { n = func.length; } @@ -18,4 +22,4 @@ export function ary any>(func: F, n: number = func } return aryToolkit(func, n); -}; +} diff --git a/src/compat/function/bind.spec.ts b/src/compat/function/bind.spec.ts index 63eca627..ee3af1aa 100644 --- a/src/compat/function/bind.spec.ts +++ b/src/compat/function/bind.spec.ts @@ -79,7 +79,7 @@ describe('bind', () => { it('should create a function with a `length` of `0`', () => { // eslint-disable-next-line @typescript-eslint/no-unused-vars - const fn = function (_a: unknown, _b: unknown, _c: unknown) { }; + const fn = function (_a: unknown, _b: unknown, _c: unknown) {}; let bound = bind(fn, {}); expect(bound.length).toBe(0); @@ -107,7 +107,7 @@ describe('bind', () => { return this; } - function Bar() { } + function Bar() {} const thisArg = { a: 1 }; const boundFoo = bind(Foo, thisArg) as any; @@ -173,7 +173,7 @@ describe('bind', () => { it('should not error when calling bound class constructors with the `new` operator', () => { const createCtor: any = function () { - return class A { }; + return class A {}; }; const bound = bind(createCtor()) as any; diff --git a/src/compat/function/bind.ts b/src/compat/function/bind.ts index 36537119..be90d0ef 100644 --- a/src/compat/function/bind.ts +++ b/src/compat/function/bind.ts @@ -58,4 +58,4 @@ export function bind(func: F, thisObj?: unknown, ...partialA } const bindPlaceholder: unique symbol = Symbol('bind.placeholder'); -bind.placeholder = bindPlaceholder; \ No newline at end of file +bind.placeholder = bindPlaceholder; diff --git a/src/compat/math/min.spec.ts b/src/compat/math/min.spec.ts index e831211c..fc14139b 100644 --- a/src/compat/math/min.spec.ts +++ b/src/compat/math/min.spec.ts @@ -1,6 +1,5 @@ -import { describe, expect, it } from "vitest"; -import { min } from "./min"; - +import { describe, expect, it } from 'vitest'; +import { min } from './min'; describe('min', () => { it('should return the largest value from a collection', () => { diff --git a/src/compat/object/cloneDeep.ts b/src/compat/object/cloneDeep.ts index a580e97a..244be43e 100644 --- a/src/compat/object/cloneDeep.ts +++ b/src/compat/object/cloneDeep.ts @@ -78,9 +78,8 @@ export function cloneDeep(obj: T): T { return result as T; } - default: { return cloneDeepToolkit(obj); } } -} \ No newline at end of file +} diff --git a/src/compat/object/get.ts b/src/compat/object/get.ts index 47ae1e38..c19db6ed 100644 --- a/src/compat/object/get.ts +++ b/src/compat/object/get.ts @@ -1,14 +1,14 @@ -import { isDeepKey } from "../_internal/isDeepKey.ts"; -import { toPath } from "../_internal/toPath.ts"; -import type { Get } from "./get.types.ts"; +import { isDeepKey } from '../_internal/isDeepKey.ts'; +import { toPath } from '../_internal/toPath.ts'; +import type { Get } from './get.types.ts'; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template K - The type of the key in the object. * @template D - The type of the default value. - * + * * @param {T} object - The object to query. * @param {K | [K]} path - The path of the property to get. * @returns {T[K]} - Returns the resolved value. @@ -16,10 +16,10 @@ import type { Get } from "./get.types.ts"; export function get(object: T, path: K | [K]): T[K]; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template K - The type of the key in the object. - * + * * @param {T | null | undefined} object - The object to query. * @param {K | [K]} path - The path of the property to get. * @returns {T[K] | undefined} - Returns the resolved value. @@ -27,24 +27,28 @@ export function get(object: T, path: K | [K export function get(object: T | null | undefined, path: K | [K]): T[K] | undefined; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template K - The type of the key in the object. * @template D - The type of the default value. - * + * * @param {T | null | undefined} object - The object to query. * @param {K | [K]} path - The path of the property to get. * @param {D} defaultValue - The value returned if the resolved value is undefined. * @returns {Exclude | D} - Returns the resolved value. */ -export function get(object: T | null | undefined, path: K | [K], defaultValue: D): Exclude | D; +export function get( + object: T | null | undefined, + path: K | [K], + defaultValue: D +): Exclude | D; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template K1 - The type of the first key in the object. * @template K2 - The type of the second key in the object. - * + * * @param {T} object - The object to query. * @param {[K1, K2]} path - The path of the property to get. * @returns {T[K1][K2]} - Returns the resolved value. @@ -52,120 +56,156 @@ export function get(object: T | null | u export function get(object: T, path: [K1, K2]): T[K1][K2]; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template K1 - The type of the first key in the object. * @template K2 - The type of the second key in the object. - * + * * @param {T | null | undefined} object - The object to query. * @param {[K1, K2]} path - The path of the property to get. * @returns {T[K1][K2] | undefined} - Returns the resolved value. */ -export function get(object: T | null | undefined, path: [K1, K2]): T[K1][K2] | undefined; +export function get( + object: T | null | undefined, + path: [K1, K2] +): T[K1][K2] | undefined; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template K1 - The type of the first key in the object. * @template K2 - The type of the second key in the object. * @template D - The type of the default value. - * + * * @param {T | null | undefined} object - The object to query. * @param {[K1, K2]} path - The path of the property to get. * @param {D} defaultValue - The value returned if the resolved value is undefined. * @returns {Exclude | D} - Returns the resolved value. */ -export function get(object: T | null | undefined, path: [K1, K2], defaultValue: D): Exclude | D; +export function get( + object: T | null | undefined, + path: [K1, K2], + defaultValue: D +): Exclude | D; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template K1 - The type of the first key in the object. * @template K2 - The type of the second key in the object. * @template K3 - The type of the third key in the object. - * + * * @param {T} object - The object to query. * @param {[K1, K2, K3]} path - The path of the property to get. * @returns {T[K1][K2][K3]} - Returns the resolved value. */ -export function get(object: T, path: [K1, K2, K3]): T[K1][K2][K3]; +export function get( + object: T, + path: [K1, K2, K3] +): T[K1][K2][K3]; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template K1 - The type of the first key in the object. * @template K2 - The type of the second key in the object. * @template K3 - The type of the third key in the object. - * + * * @param {T | null | undefined} object - The object to query. * @param {[K1, K2, K3]} path - The path of the property to get. * @returns {T[K1][K2][K3] | undefined} - Returns the resolved value. */ -export function get(object: T | null | undefined, path: [K1, K2, K3]): T[K1][K2][K3] | undefined; +export function get( + object: T | null | undefined, + path: [K1, K2, K3] +): T[K1][K2][K3] | undefined; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template K1 - The type of the first key in the object. * @template K2 - The type of the second key in the object. * @template K3 - The type of the third key in the object. * @template D - The type of the default value. - * + * * @param {T | null | undefined} object - The object to query. * @param {[K1, K2, K3]} path - The path of the property to get. * @param {D} defaultValue - The value returned if the resolved value is undefined. * @returns {Exclude | D} - Returns the resolved value. */ -export function get(object: T | null | undefined, path: [K1, K2, K3], defaultValue: D): Exclude | D; +export function get( + object: T | null | undefined, + path: [K1, K2, K3], + defaultValue: D +): Exclude | D; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template K1 - The type of the first key in the object. * @template K2 - The type of the second key in the object. * @template K3 - The type of the third key in the object. * @template K4 - The type of the fourth key in the object. - * + * * @param {T} object - The object to query. * @param {[K1, K2, K3, K4]} path - The path of the property to get. * @returns {T[K1][K2][K3][K4]} - Returns the resolved value. */ -export function get(object: T, path: [K1, K2, K3, K4]): T[K1][K2][K3][K4]; +export function get< + T extends object, + K1 extends keyof T, + K2 extends keyof T[K1], + K3 extends keyof T[K1][K2], + K4 extends keyof T[K1][K2][K3], +>(object: T, path: [K1, K2, K3, K4]): T[K1][K2][K3][K4]; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template K1 - The type of the first key in the object. * @template K2 - The type of the second key in the object. * @template K3 - The type of the third key in the object. * @template K4 - The type of the fourth key in the object. - * + * * @param {T | null | undefined} object - The object to query. * @param {[K1, K2, K3, K4]} path - The path of the property to get. * @returns {T[K1][K2][K3][K4] | undefined} - Returns the resolved value. */ -export function get(object: T | null | undefined, path: [K1, K2, K3, K4]): T[K1][K2][K3][K4] | undefined; +export function get< + T extends object, + K1 extends keyof T, + K2 extends keyof T[K1], + K3 extends keyof T[K1][K2], + K4 extends keyof T[K1][K2][K3], +>(object: T | null | undefined, path: [K1, K2, K3, K4]): T[K1][K2][K3][K4] | undefined; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template K1 - The type of the first key in the object. * @template K2 - The type of the second key in the object. * @template K3 - The type of the third key in the object. * @template K4 - The type of the fourth key in the object. * @template D - The type of the default value. - * + * * @param {T | null | undefined} object - The object to query. * @param {[K1, K2, K3, K4]} path - The path of the property to get. * @param {D} defaultValue - The value returned if the resolved value is undefined. * @returns {Exclude | D} - Returns the resolved value. */ -export function get(object: T | null | undefined, path: [K1, K2, K3, K4], defaultValue: D): Exclude | D; +export function get< + T extends object, + K1 extends keyof T, + K2 extends keyof T[K1], + K3 extends keyof T[K1][K2], + K4 extends keyof T[K1][K2][K3], + D, +>(object: T | null | undefined, path: [K1, K2, K3, K4], defaultValue: D): Exclude | D; /** * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the value. - * + * * @param {Record} object - The object to query. * @param {number} path - The path of the property to get. * @returns {T} - Returns the resolved value. @@ -173,9 +213,9 @@ export function get(object: Record, path: number): T; /** * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the value. - * + * * @param {Record | null | undefined} object - The object to query. * @param {number} path - The path of the property to get. * @returns {T | undefined} - Returns the resolved value. @@ -183,10 +223,10 @@ export function get(object: Record, path: number): T; export function get(object: Record | null | undefined, path: number): T | undefined; /** * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the value. * @template D - The type of the default value. - * + * * @param {Record | null | undefined} object - The object to query. * @param {number} path - The path of the property to get. * @param {D} defaultValue - The value returned if the resolved value is undefined. @@ -195,9 +235,9 @@ export function get(object: Record | null | undefined, path: numbe export function get(object: Record | null | undefined, path: number, defaultValue: D): T | D; /** * Retrieves the value at a given path from a null or undefined object, returning the default value. - * + * * @template D - The type of the default value. - * + * * @param {null | undefined} object - The object to query. * @param {PropertyKey} path - The path of the property to get. * @param {D} defaultValue - The value returned if the resolved value is undefined. @@ -206,7 +246,7 @@ export function get(object: Record | null | undefined, path: nu export function get(object: null | undefined, path: PropertyKey, defaultValue: D): D; /** * Retrieves the value at a given path from a null or undefined object, returning undefined. - * + * * @param {null | undefined} object - The object to query. * @param {PropertyKey} path - The path of the property to get. * @returns {undefined} - Returns undefined. @@ -214,10 +254,10 @@ export function get(object: null | undefined, path: PropertyKey, defaultValue export function get(object: null | undefined, path: PropertyKey): undefined; /** * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template P - The type of the path. - * + * * @param {T} data - The object to query. * @param {P} path - The path of the property to get. * @returns {string extends P ? any : Get} - Returns the resolved value. @@ -225,20 +265,24 @@ export function get(object: null | undefined, path: PropertyKey): undefined; export function get(data: T, path: P): string extends P ? any : Get; /** * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @template T - The type of the object. * @template P - The type of the path. * @template D - The type of the default value. - * + * * @param {T} data - The object to query. * @param {P} path - The path of the property to get. * @param {D} defaultValue - The value returned if the resolved value is undefined. * @returns {Exclude, null | undefined> | D} - Returns the resolved value. */ -export function get>(data: T, path: P, defaultValue: D): Exclude, null | undefined> | D; +export function get>( + data: T, + path: P, + defaultValue: D +): Exclude, null | undefined> | D; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. - * + * * @param {unknown} object - The object to query. * @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to get. * @param {unknown} [defaultValue] - The value returned if the resolved value is undefined. @@ -278,4 +322,4 @@ export function get(object: any, path: PropertyKey | readonly PropertyKey[], def } return current ?? defaultValue; -} \ No newline at end of file +} diff --git a/src/compat/object/get.types.ts b/src/compat/object/get.types.ts index ec02596b..9d0c6bf9 100644 --- a/src/compat/object/get.types.ts +++ b/src/compat/object/get.types.ts @@ -4,35 +4,31 @@ type GetIndexedField = K extends keyof T ? T[K] : K extends `${number}` - ? 'length' extends keyof T - ? number extends T['length'] - ? number extends keyof T - ? T[number] - : undefined - : undefined - : undefined - : undefined; + ? 'length' extends keyof T + ? number extends T['length'] + ? number extends keyof T + ? T[number] + : undefined + : undefined + : undefined + : undefined; -type FieldWithPossiblyUndefined = - | Get, Key> - | Extract; +type FieldWithPossiblyUndefined = Get, Key> | Extract; -type IndexedFieldWithPossiblyUndefined = - | GetIndexedField, Key> - | Extract; +type IndexedFieldWithPossiblyUndefined = GetIndexedField, Key> | Extract; export type Get = P extends `${infer Left}.${infer Right}` ? Left extends keyof Exclude - ? FieldWithPossiblyUndefined[Left], Right> | Extract - : Left extends `${infer FieldKey}[${infer IndexKey}]` - ? FieldKey extends keyof T - ? FieldWithPossiblyUndefined, Right> - : undefined - : undefined + ? FieldWithPossiblyUndefined[Left], Right> | Extract + : Left extends `${infer FieldKey}[${infer IndexKey}]` + ? FieldKey extends keyof T + ? FieldWithPossiblyUndefined, Right> + : undefined + : undefined : P extends keyof T - ? T[P] - : P extends `${infer FieldKey}[${infer IndexKey}]` - ? FieldKey extends keyof T - ? IndexedFieldWithPossiblyUndefined - : undefined - : IndexedFieldWithPossiblyUndefined; \ No newline at end of file + ? T[P] + : P extends `${infer FieldKey}[${infer IndexKey}]` + ? FieldKey extends keyof T + ? IndexedFieldWithPossiblyUndefined + : undefined + : IndexedFieldWithPossiblyUndefined; diff --git a/src/compat/object/mapValues.spec.ts b/src/compat/object/mapValues.spec.ts index 20633997..53c50588 100644 --- a/src/compat/object/mapValues.spec.ts +++ b/src/compat/object/mapValues.spec.ts @@ -1,4 +1,3 @@ - import { describe, expect, it } from 'vitest'; import { mapValues } from './mapValues'; import { isEqual } from '../../predicate/isEqual'; @@ -7,7 +6,6 @@ describe('mapValues', () => { const array = [1, 2]; const object = { a: 1, b: 2 }; - it('should map values in `object` to a new object', () => { const actual = mapValues(object, String); expect(actual).toEqual({ a: '1', b: '2' }); diff --git a/src/compat/object/property.ts b/src/compat/object/property.ts index a226e09d..ea3c44a6 100644 --- a/src/compat/object/property.ts +++ b/src/compat/object/property.ts @@ -1,4 +1,4 @@ -import { get } from "./get.ts"; +import { get } from './get.ts'; /** * Creates a function that returns the value at a given path of an object. @@ -10,7 +10,7 @@ import { get } from "./get.ts"; * const getObjectValue = property('a.b.c'); * const result = getObjectValue({ a: { b: { c: 3 } } }); * console.log(result); // => 3 - * + * * @example * const getObjectValue = property(['a', 'b', 'c']); * const result = getObjectValue({ a: { b: { c: 3 } } }); @@ -19,5 +19,5 @@ import { get } from "./get.ts"; export function property(path: PropertyKey | readonly PropertyKey[]): (object: unknown) => any { return function (object: unknown) { return get(object, path); - } -} \ No newline at end of file + }; +} diff --git a/src/compat/object/set.ts b/src/compat/object/set.ts index 86682461..93335112 100644 --- a/src/compat/object/set.ts +++ b/src/compat/object/set.ts @@ -1,5 +1,5 @@ -import { isIndex } from "../_internal/isIndex.ts"; -import { toPath } from "../_internal/toPath.ts"; +import { isIndex } from '../_internal/isIndex.ts'; +import { toPath } from '../_internal/toPath.ts'; /** * Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created. @@ -30,11 +30,7 @@ import { toPath } from "../_internal/toPath.ts"; */ export function set(obj: object, path: PropertyKey | readonly PropertyKey[], value: unknown): T; export function set(obj: T, path: PropertyKey | readonly PropertyKey[], value: unknown): T { - const resolvedPath = Array.isArray(path) - ? path - : typeof path === 'string' - ? toPath(path) - : [path]; + const resolvedPath = Array.isArray(path) ? path : typeof path === 'string' ? toPath(path) : [path]; let current: any = obj; diff --git a/src/compat/predicate/isArray.spec.ts b/src/compat/predicate/isArray.spec.ts index 662e399c..73fda93f 100644 --- a/src/compat/predicate/isArray.spec.ts +++ b/src/compat/predicate/isArray.spec.ts @@ -10,16 +10,16 @@ describe('isArray', function () { it('returns false if value is not an array', () => { expect(isArray('abc')).toBe(false); - expect(isArray(() => { })).toBe(false); + expect(isArray(() => {})).toBe(false); }); it('can be used with TypeScript as a type predicate', () => { - const arr1 = ['abc', () => { }, [1, 2, 3]]; + const arr1 = ['abc', () => {}, [1, 2, 3]]; const result1 = arr1.filter(isArray); expect(result1).toStrictEqual([[1, 2, 3]]); expectTypeOf(result1).toEqualTypeOf(); - const arr2 = ['abc', () => { }, [1, 2, 3] as const]; + const arr2 = ['abc', () => {}, [1, 2, 3] as const]; const result2 = arr2.filter(isArray); expect(result2).toStrictEqual([[1, 2, 3]]); }); diff --git a/src/compat/predicate/isArrayLike.spec.ts b/src/compat/predicate/isArrayLike.spec.ts index 0b349be3..16936117 100644 --- a/src/compat/predicate/isArrayLike.spec.ts +++ b/src/compat/predicate/isArrayLike.spec.ts @@ -20,8 +20,8 @@ describe('isArrayLike', () => { expect(actual).toEqual(expected); const slice = Array.prototype.slice; - const asyncFunc = async function () { }; - const genFunc = function* () { }; + const asyncFunc = async function () {}; + const genFunc = function* () {}; const symbol = Symbol ? Symbol('a') : undefined; expect(isArrayLike(true)).toBe(false); diff --git a/src/compat/predicate/isArrayLike.ts b/src/compat/predicate/isArrayLike.ts index 7f247982..96be22f8 100644 --- a/src/compat/predicate/isArrayLike.ts +++ b/src/compat/predicate/isArrayLike.ts @@ -1,4 +1,4 @@ -import { isLength } from "../../predicate/isLength.ts"; +import { isLength } from '../../predicate/isLength.ts'; /** * Checks if `value` is array-like. @@ -15,6 +15,5 @@ import { isLength } from "../../predicate/isLength.ts"; * isArrayLike(undefined); // false */ export function isArrayLike(value: unknown): value is ArrayLike { - return value != null && typeof value !== "function" && - isLength((value as ArrayLike).length); + return value != null && typeof value !== 'function' && isLength((value as ArrayLike).length); } diff --git a/src/compat/predicate/isBoolean.spec.ts b/src/compat/predicate/isBoolean.spec.ts index c951af17..fc755276 100644 --- a/src/compat/predicate/isBoolean.spec.ts +++ b/src/compat/predicate/isBoolean.spec.ts @@ -14,7 +14,7 @@ describe('isBoolean', () => { }); it('should return `false` for non-booleans', () => { - const expected = falsey.map((value) => value === false); + const expected = falsey.map(value => value === false); const actual = falsey.map((value, index) => isBoolean(value)); diff --git a/src/compat/predicate/isBoolean.ts b/src/compat/predicate/isBoolean.ts index 29c4be4e..877dd7c8 100644 --- a/src/compat/predicate/isBoolean.ts +++ b/src/compat/predicate/isBoolean.ts @@ -1,5 +1,4 @@ -import { getTag } from "../_internal/getTag.ts"; - +import { getTag } from '../_internal/getTag.ts'; /** * Checks if the given value is boolean. diff --git a/src/compat/predicate/isEqual.spec.ts b/src/compat/predicate/isEqual.spec.ts index d1bd391f..3495dcfc 100644 --- a/src/compat/predicate/isEqual.spec.ts +++ b/src/compat/predicate/isEqual.spec.ts @@ -1,9 +1,9 @@ -import { describe, expect, it } from "vitest"; -import { noop } from "../../function/noop"; -import { stubFalse } from "../_internal/stubFalse"; -import { isEqual } from "es-toolkit/compat"; -import { args } from "../_internal/args"; -import { arrayViews } from "../_internal/arrayViews"; +import { describe, expect, it } from 'vitest'; +import { noop } from '../../function/noop'; +import { stubFalse } from '../_internal/stubFalse'; +import { isEqual } from 'es-toolkit/compat'; +import { args } from '../_internal/args'; +import { arrayViews } from '../_internal/arrayViews'; describe('isEqual', () => { const symbol1 = Symbol ? Symbol('a') : true; @@ -55,9 +55,9 @@ describe('isEqual', () => { [undefined, '', false], ]; - const expected = pairs.map((pair) => pair[2]); + const expected = pairs.map(pair => pair[2]); - const actual = pairs.map((pair) => isEqual(pair[0], pair[1])); + const actual = pairs.map(pair => isEqual(pair[0], pair[1])); expect(actual).toEqual(expected); }); @@ -82,24 +82,8 @@ describe('isEqual', () => { expect(isEqual(array1, array2)).toBe(true); - array1 = [ - Object(1), - false, - Object('a'), - /x/, - new Date(2012, 4, 23), - ['a', 'b', [Object('c')]], - { a: 1 }, - ]; - array2 = [ - 1, - Object(false), - 'a', - /x/, - new Date(2012, 4, 23), - ['a', Object('b'), ['c']], - { a: 1 }, - ]; + array1 = [Object(1), false, Object('a'), /x/, new Date(2012, 4, 23), ['a', 'b', [Object('c')]], { a: 1 }]; + array2 = [1, Object(false), 'a', /x/, new Date(2012, 4, 23), ['a', Object('b'), ['c']], { a: 1 }]; expect(isEqual(array1, array2)).toBe(true); @@ -127,7 +111,7 @@ describe('isEqual', () => { array1.some = array1.reduce = array1.reduceRight = - null; + null; array2.concat = array2.join = @@ -138,7 +122,7 @@ describe('isEqual', () => { array2.sort = array2.splice = array2.unshift = - null; + null; expect(isEqual(array1, array2)).toBe(true); @@ -447,7 +431,7 @@ describe('isEqual', () => { it('should treat `arguments` objects like `Object` objects', () => { const object = { 0: 1, 1: 2, 2: 3 }; - function Foo() { } + function Foo() {} Foo.prototype = object; expect(isEqual(args, object)).toBe(true); @@ -502,21 +486,12 @@ describe('isEqual', () => { // @ts-ignore const bufferC = globalThis[otherType] ? new ArrayBuffer(16) : 16; - return [ - new CtorA(bufferA), - new CtorA(bufferA), - new CtorB(bufferB), - new CtorB(bufferC), - ]; + return [new CtorA(bufferA), new CtorA(bufferA), new CtorB(bufferB), new CtorB(bufferC)]; }); const expected = pairs.map(() => [true, false, false]); - const actual = pairs.map((pair) => [ - isEqual(pair[0], pair[1]), - isEqual(pair[0], pair[2]), - isEqual(pair[2], pair[3]), - ]); + const actual = pairs.map(pair => [isEqual(pair[0], pair[1]), isEqual(pair[0], pair[2]), isEqual(pair[2], pair[3])]); expect(actual).toEqual(expected); }); @@ -539,33 +514,23 @@ describe('isEqual', () => { }); it('should compare error objects', () => { - const pairs = [ - 'Error', - 'EvalError', - 'RangeError', - 'ReferenceError', - 'SyntaxError', - 'TypeError', - 'URIError', - ].map((type, index, errorTypes) => { - const otherType = errorTypes[++index % errorTypes.length]; - // eslint-disable-next-line - // @ts-ignore - const CtorA = globalThis[type]; - // eslint-disable-next-line - // @ts-ignore - const CtorB = globalThis[otherType]; + const pairs = ['Error', 'EvalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError'].map( + (type, index, errorTypes) => { + const otherType = errorTypes[++index % errorTypes.length]; + // eslint-disable-next-line + // @ts-ignore + const CtorA = globalThis[type]; + // eslint-disable-next-line + // @ts-ignore + const CtorB = globalThis[otherType]; - return [new CtorA('a'), new CtorA('a'), new CtorB('a'), new CtorB('b')]; - }); + return [new CtorA('a'), new CtorA('a'), new CtorB('a'), new CtorB('b')]; + } + ); const expected = pairs.map(() => [true, false, false]); - const actual = pairs.map((pair) => [ - isEqual(pair[0], pair[1]), - isEqual(pair[0], pair[2]), - isEqual(pair[2], pair[3]), - ]); + const actual = pairs.map(pair => [isEqual(pair[0], pair[1]), isEqual(pair[0], pair[2]), isEqual(pair[2], pair[3])]); expect(actual).toEqual(expected); }); @@ -583,9 +548,7 @@ describe('isEqual', () => { }); it('should compare maps', () => { - [ - [new Map(), new Map()], - ].forEach((maps) => { + [[new Map(), new Map()]].forEach(maps => { const map1 = maps[0]; const map2 = maps[1]; @@ -623,16 +586,13 @@ describe('isEqual', () => { }); it('should compare promises by reference', () => { - [ - [Promise.resolve(1), Promise.resolve(1)], - ].forEach( - (promises) => { - const promise1 = promises[0]; - const promise2 = promises[1]; + [[Promise.resolve(1), Promise.resolve(1)]].forEach(promises => { + const promise1 = promises[0]; + const promise2 = promises[1]; - expect(isEqual(promise1, promise2)).toBe(false); - expect(isEqual(promise1, promise1)).toBe(true); - }); + expect(isEqual(promise1, promise2)).toBe(false); + expect(isEqual(promise1, promise1)).toBe(true); + }); }); it('should compare regexes', () => { @@ -641,15 +601,11 @@ describe('isEqual', () => { expect(isEqual(/x/gi, /x/g)).toBe(false); expect(isEqual(/x/, /y/)).toBe(false); - expect( - isEqual(/x/g, { global: true, ignoreCase: false, multiline: false, source: 'x' }) - ).toBe(false); + expect(isEqual(/x/g, { global: true, ignoreCase: false, multiline: false, source: 'x' })).toBe(false); }); it('should compare sets', () => { - [ - [new Set(), new Set()], - ].forEach((sets) => { + [[new Set(), new Set()]].forEach(sets => { const set1 = sets[0]; const set2 = sets[1]; @@ -714,7 +670,6 @@ describe('isEqual', () => { expect(isEqual(object1, object2)).toBe(false); }); - it('should return `false` for objects with custom `toString` methods', () => { let primitive: any; const object = { @@ -725,7 +680,7 @@ describe('isEqual', () => { const values = [true, null, 1, 'a', undefined]; const expected = values.map(stubFalse); - const actual = values.map((value) => { + const actual = values.map(value => { primitive = value; return isEqual(object, value); }); diff --git a/src/compat/predicate/isMatch.spec.ts b/src/compat/predicate/isMatch.spec.ts index e5cc31b0..13ee254d 100644 --- a/src/compat/predicate/isMatch.spec.ts +++ b/src/compat/predicate/isMatch.spec.ts @@ -22,7 +22,7 @@ describe('isMatch', () => { } interface FooConstructor { - new(): Foo; + new (): Foo; } const Foo = function Foo(this: Foo) { @@ -42,7 +42,7 @@ describe('isMatch', () => { } interface FooConstructor { - new(): Foo; + new (): Foo; } const Foo = function Foo(this: Foo) { @@ -77,7 +77,7 @@ describe('isMatch', () => { it(`should compare functions by reference`, () => { const object1 = { a: noop }; - const object2 = { a: () => { } }; + const object2 = { a: () => {} }; const object3 = { a: {} }; expect(isMatch(object1, object1)).toBe(true); @@ -86,16 +86,16 @@ describe('isMatch', () => { }); it(`should work with a function for \`object\``, () => { - function Foo() { } + function Foo() {} Foo.a = { b: 2, c: 3 }; expect(isMatch(Foo, { a: { b: 2 } })).toBe(true); }); it(`should work with a function for \`source\``, () => { - function Foo() { } + function Foo() {} Foo.a = 1; - Foo.b = function () { }; + Foo.b = function () {}; Foo.c = 3; const objects = [{ a: 1 }, { a: 1, b: Foo.b, c: 3 }]; @@ -112,7 +112,7 @@ describe('isMatch', () => { } interface FooConstructor { - new(arg: Partial): Foo; + new (arg: Partial): Foo; } const Foo = function Foo(this: Foo, object: Partial) { diff --git a/src/compat/predicate/isMatch.ts b/src/compat/predicate/isMatch.ts index bca5875c..da765b5c 100644 --- a/src/compat/predicate/isMatch.ts +++ b/src/compat/predicate/isMatch.ts @@ -6,7 +6,7 @@ import { isSetMatch } from '../_internal/isSetMatch.ts'; /** * Checks if the target matches the source by comparing their structures and values. * This function supports deep comparison for objects, arrays, maps, and sets. - * + * * @param {unknown} target - The target value to match against. * @param {unknown} source - The source value to match with. * @returns {boolean} - Returns `true` if the target matches the source, otherwise `false`. diff --git a/src/compat/predicate/isObjectLike.ts b/src/compat/predicate/isObjectLike.ts index 019ae82a..629e4b72 100644 --- a/src/compat/predicate/isObjectLike.ts +++ b/src/compat/predicate/isObjectLike.ts @@ -1,6 +1,6 @@ /** * Checks if the given value is object-like. - * + * * A value is object-like if its type is object and it is not null. * * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object-like value. diff --git a/src/compat/predicate/matches.ts b/src/compat/predicate/matches.ts index de751bf0..c6bd4462 100644 --- a/src/compat/predicate/matches.ts +++ b/src/compat/predicate/matches.ts @@ -3,7 +3,7 @@ import { isMatch } from './isMatch.ts'; /** * Creates a function that performs a deep comparison between a given target and the source object. - * + * * @param {unknown} source - The source object to create the matcher from. * @returns {(target: unknown) => boolean} - Returns a function that takes a target object and returns `true` if the target matches the source, otherwise `false`. * diff --git a/src/compat/string/padStart.ts b/src/compat/string/padStart.ts index 2bf6c592..5b91bc74 100644 --- a/src/compat/string/padStart.ts +++ b/src/compat/string/padStart.ts @@ -1,11 +1,11 @@ /** * Pads the start of a string with a given character until it reaches the specified length. - * + * * If the length is less than or equal to the original string's length, or if the padding character is an empty string, * the original string is returned unchanged. * * @param {string} str - The string to pad. - * @param {number} [length] - The length of the resulting string once padded. + * @param {number} [length] - The length of the resulting string once padded. * @param {string} [chars] - The character(s) to use for padding. * @returns {string} - The padded string, or the original string if padding is not required. * @@ -17,4 +17,4 @@ */ export function padStart(str: string, length = 0, chars = ' '): string { return str.padStart(length, chars); -}; +} diff --git a/src/function/ary.ts b/src/function/ary.ts index d2722d9e..e10cffef 100644 --- a/src/function/ary.ts +++ b/src/function/ary.ts @@ -7,8 +7,8 @@ * @param {any} guard - Enables use as an iteratee for methods like `map`. * @returns {(...args: any[]) => ReturnType} Returns the new capped function. */ -export function ary any>(func: F, n: number): ((...args: any[]) => ReturnType) { +export function ary any>(func: F, n: number): (...args: any[]) => ReturnType { return function (this: any, ...args: Parameters) { return func.apply(this, args.slice(0, n)); }; -}; +} diff --git a/src/function/debounce.ts b/src/function/debounce.ts index 929c7dff..85e48361 100644 --- a/src/function/debounce.ts +++ b/src/function/debounce.ts @@ -56,7 +56,7 @@ export function debounce void>( timeoutId = setTimeout(() => { func(...args); timeoutId = null; - }, debounceMs) ; + }, debounceMs); } as F & { cancel: () => void }; const onAbort = function () { diff --git a/src/function/negate.spec.ts b/src/function/negate.spec.ts index ee0face6..ba39cf27 100644 --- a/src/function/negate.spec.ts +++ b/src/function/negate.spec.ts @@ -2,9 +2,9 @@ import { describe, it, expect } from 'vitest'; import { negate } from './negate'; describe('negate', () => { - it('should negate the given predicate function', () => { - expect(typeof negate(() => true)).toBe('function'); - expect(negate(() => true)()).toBe(false); - expect(negate(() => false)()).toBe(true); - }); + it('should negate the given predicate function', () => { + expect(typeof negate(() => true)).toBe('function'); + expect(negate(() => true)()).toBe(false); + expect(negate(() => false)()).toBe(true); + }); }); diff --git a/src/function/negate.ts b/src/function/negate.ts index edd4cad6..bbbab214 100644 --- a/src/function/negate.ts +++ b/src/function/negate.ts @@ -6,5 +6,5 @@ * @returns {F} The new negated function, which negates the boolean result of `func`. */ export function negate boolean>(func: F): F { - return ((...args: any[]) => !func(...args)) as F; + return ((...args: any[]) => !func(...args)) as F; } diff --git a/src/function/unary.ts b/src/function/unary.ts index 8447c001..8be3b02f 100644 --- a/src/function/unary.ts +++ b/src/function/unary.ts @@ -7,6 +7,6 @@ import { ary } from './ary.ts'; * @param {F} func - The function to cap arguments for. * @returns {(...args: any[]) => ReturnType} Returns the new capped function. */ -export function unary any>(func: F): ((...args: any[]) => ReturnType) { +export function unary any>(func: F): (...args: any[]) => ReturnType { return ary(func, 1); -}; +} diff --git a/src/math/round.spec.ts b/src/math/round.spec.ts index 1d97668f..55977b89 100644 --- a/src/math/round.spec.ts +++ b/src/math/round.spec.ts @@ -55,8 +55,6 @@ describe('round function', () => { it('handles edge cases where precision is not integer', () => { const value = 1.2345; const precision = 3.1; - expect(() => round(value, precision)).toThrow( - 'Precision must be an integer.' - ); + expect(() => round(value, precision)).toThrow('Precision must be an integer.'); }); }); diff --git a/src/object/clone.ts b/src/object/clone.ts index 966257dd..a598c375 100644 --- a/src/object/clone.ts +++ b/src/object/clone.ts @@ -61,7 +61,7 @@ export function clone(obj: T): T { if (typeof obj === 'object') { const prototype = Object.getPrototypeOf(obj); - const result = Object.create(prototype) + const result = Object.create(prototype); return Object.assign(result, obj); } return obj; diff --git a/src/object/cloneDeep.spec.ts b/src/object/cloneDeep.spec.ts index 90cbec80..dd0b66a3 100644 --- a/src/object/cloneDeep.spec.ts +++ b/src/object/cloneDeep.spec.ts @@ -32,7 +32,7 @@ describe('cloneDeep', () => { expect(cloned).toEqual(arr); expect(cloned).not.toBe(arr); - }) + }); it('should clone arrays with nested objects', () => { const arr = [{ a: 1 }, { b: 2 }, { c: 3 }]; @@ -337,7 +337,7 @@ describe('cloneDeep', () => { expect(cloned).not.toBe(view); expect(cloned.getInt8(0)).toBe(view.getInt8(0)); expect(cloned.getInt8(1)).toBe(view.getInt8(1)); - }) + }); it('should clone buffers', () => { const buffer = Buffer.from([1, 2, 3]); @@ -346,5 +346,5 @@ describe('cloneDeep', () => { expect(cloned).not.toBe(buffer); expect(cloned).toEqual(buffer); - }) + }); }); diff --git a/src/object/flattenObject.spec.ts b/src/object/flattenObject.spec.ts index 02cc9bc6..deb962db 100644 --- a/src/object/flattenObject.spec.ts +++ b/src/object/flattenObject.spec.ts @@ -1,17 +1,17 @@ -import { describe, expect, it } from "vitest" -import { flattenObject } from "./flattenObject"; +import { describe, expect, it } from 'vitest'; +import { flattenObject } from './flattenObject'; describe('flattenObject', function () { it('flattens primitive values correctly', () => { const result1 = flattenObject({ a: { - b: 'yay' - } + b: 'yay', + }, }); expect(result1).toEqual({ - 'a.b': 'yay' - }) + 'a.b': 'yay', + }); const date = new Date(); @@ -24,9 +24,9 @@ describe('flattenObject', function () { null: null, undefined: undefined, date: date, - } - } - }) + }, + }, + }); expect(result2).toEqual({ 'a.b.string': 'hello world', @@ -35,8 +35,8 @@ describe('flattenObject', function () { 'a.b.null': null, 'a.b.undefined': undefined, 'a.b.date': date, - }) - }) + }); + }); it('flattens multiple keys', () => { const date = new Date(); @@ -49,58 +49,58 @@ describe('flattenObject', function () { d: { e: { f: { - g: date - } - } - } + g: date, + }, + }, + }, }, h: { - i: 'hi' - } + i: 'hi', + }, }); expect(result).toEqual({ 'a.b.c': 1, 'a.d.e.f.g': date, - 'h.i': 'hi' - }) - }) + 'h.i': 'hi', + }); + }); it('handles empty objects correctly', () => { const result = flattenObject({ a: { - b: {} - } + b: {}, + }, }); expect(result).toEqual({ 'a.b': {}, - }) - }) + }); + }); it('handles `Buffer`s correctly', () => { const result = flattenObject({ a: { - b: Buffer.from('test') - } + b: Buffer.from('test'), + }, }); expect(result).toEqual({ - 'a.b': Buffer.from('test') + 'a.b': Buffer.from('test'), }); - }) + }); it('handles `TypedArray`s correctly', () => { const result = flattenObject({ a: { - b: new Uint8Array([1, 2, 3, 4]) - } + b: new Uint8Array([1, 2, 3, 4]), + }, }); expect(result).toEqual({ - 'a.b': new Uint8Array([1, 2, 3, 4]) + 'a.b': new Uint8Array([1, 2, 3, 4]), }); - }) + }); it('handles numeric keys', () => { const result = flattenObject({ @@ -108,31 +108,31 @@ describe('flattenObject', function () { '02': { '03': 1, }, - } + }, }); expect(result).toEqual({ '01.02.03': 1, }); - }) + }); it('handles mixed keys', () => { const result = flattenObject({ - 'a1': { - 'b2': { - 'c3': 1, + a1: { + b2: { + c3: 1, }, - } + }, }); expect(result).toEqual({ - 'a1.b2.c3': 1 + 'a1.b2.c3': 1, }); - }) + }); it('handles arrays', () => { const result = flattenObject({ - a: [1, 2, 3] + a: [1, 2, 3], }); expect(result).toEqual({ @@ -140,5 +140,5 @@ describe('flattenObject', function () { 'a.1': 2, 'a.2': 3, }); - }) -}) + }); +}); diff --git a/src/object/flattenObject.ts b/src/object/flattenObject.ts index ad240940..ac471aba 100644 --- a/src/object/flattenObject.ts +++ b/src/object/flattenObject.ts @@ -1,11 +1,11 @@ -import { isPlainObject } from "../predicate/isPlainObject.ts"; +import { isPlainObject } from '../predicate/isPlainObject.ts'; /** * Flattens a nested object into a single level object with dot-separated keys. - * + * * @param {object} object - The object to flatten. * @returns {Record} - The flattened object. - * + * * @example * const nestedObject = { * a: { @@ -15,9 +15,9 @@ import { isPlainObject } from "../predicate/isPlainObject.ts"; * }, * d: [2, 3] * }; - * + * * const flattened = flattenObject(nestedObject); - * console.log(flattened); + * console.log(flattened); * // Output: * // { * // 'a.b.c': 1, @@ -55,4 +55,4 @@ function flattenObjectImpl(object: object, prefix = ''): Record { } return result; -} \ No newline at end of file +} diff --git a/src/object/invert.ts b/src/object/invert.ts index a83a0e08..33a858c8 100644 --- a/src/object/invert.ts +++ b/src/object/invert.ts @@ -20,7 +20,7 @@ export function invert(obj: Record const result = {} as { [key in V]: K }; const keys = Object.keys(obj) as K[]; - + for (let i = 0; i < keys.length; i++) { const key = keys[i]; const value = obj[key]; diff --git a/src/predicate/isEqual.spec.ts b/src/predicate/isEqual.spec.ts index 016678ba..d842d364 100644 --- a/src/predicate/isEqual.spec.ts +++ b/src/predicate/isEqual.spec.ts @@ -99,7 +99,7 @@ describe('isEqual', () => { const buffer2 = new Uint8Array([1, 2, 3]).buffer; expect(isEqual(buffer1, buffer2)).toBe(true); - }) + }); it('should return false for different array buffers', () => { const buffer1 = new Uint8Array([1, 2, 3]).buffer; @@ -111,5 +111,5 @@ describe('isEqual', () => { const buffer4 = new Uint8Array([1, 2, 4]).buffer; expect(isEqual(buffer3, buffer4)).toBe(false); - }) + }); }); diff --git a/src/predicate/isEqual.ts b/src/predicate/isEqual.ts index f1889a47..50174fbd 100644 --- a/src/predicate/isEqual.ts +++ b/src/predicate/isEqual.ts @@ -1,12 +1,40 @@ +import { + argumentsTag, + arrayBufferTag, + arrayTag, + bigInt64ArrayTag, + bigUint64ArrayTag, + booleanTag, + dataViewTag, + dateTag, + errorTag, + float32ArrayTag, + float64ArrayTag, + functionTag, + int16ArrayTag, + int32ArrayTag, + int8ArrayTag, + mapTag, + numberTag, + objectTag, + regexpTag, + setTag, + stringTag, + symbolTag, + uint16ArrayTag, + uint32ArrayTag, + uint8ArrayTag, + uint8ClampedArrayTag, +} from '../compat/_internal/tags.ts'; +import { getSymbols } from '../compat/_internal/getSymbols.ts'; +import { getTag } from '../compat/_internal/getTag.ts'; +import { isPlainObject } from './isPlainObject.ts'; -import { argumentsTag, arrayBufferTag, arrayTag, bigInt64ArrayTag, bigUint64ArrayTag, booleanTag, dataViewTag, dateTag, errorTag, float32ArrayTag, float64ArrayTag, functionTag, int16ArrayTag, int32ArrayTag, int8ArrayTag, mapTag, numberTag, objectTag, regexpTag, setTag, stringTag, symbolTag, uint16ArrayTag, uint32ArrayTag, uint8ArrayTag, uint8ClampedArrayTag } from "../compat/_internal/tags.ts"; -import { getSymbols } from "../compat/_internal/getSymbols.ts"; -import { getTag } from "../compat/_internal/getTag.ts"; -import { isPlainObject } from "./isPlainObject.ts"; - -declare var Buffer: { - isBuffer: (a: any) => boolean; -} | undefined; +declare var Buffer: + | { + isBuffer: (a: any) => boolean; + } + | undefined; /** * Checks if two values are equal, including support for `Date`, `RegExp`, and deep object comparison. @@ -75,7 +103,7 @@ function areObjectsEqual(a: any, b: any, stack?: Map) { const x = a.valueOf(); const y = b.valueOf(); - return x === y || Number.isNaN(x) && Number.isNaN(y); + return x === y || (Number.isNaN(x) && Number.isNaN(y)); } case booleanTag: @@ -132,7 +160,7 @@ function areObjectsEqual(a: any, b: any, stack?: Map) { const aValue = aValues[i]; const index = bValues.findIndex(bValue => { return areObjectsEqual(aValue, bValue, stack); - }) + }); if (index === -1) { return false; @@ -196,8 +224,7 @@ function areObjectsEqual(a: any, b: any, stack?: Map) { case objectTag: { const areEqualInstances = - areObjectsEqual(a.constructor, b.constructor, stack) || - (isPlainObject(a) && isPlainObject(b)); + areObjectsEqual(a.constructor, b.constructor, stack) || (isPlainObject(a) && isPlainObject(b)); if (!areEqualInstances) { return false; @@ -236,4 +263,3 @@ function areObjectsEqual(a: any, b: any, stack?: Map) { stack.delete(b); } } - diff --git a/src/predicate/isPlainObject.spec.ts b/src/predicate/isPlainObject.spec.ts index 001be4bb..7ed4dc11 100644 --- a/src/predicate/isPlainObject.spec.ts +++ b/src/predicate/isPlainObject.spec.ts @@ -1,5 +1,5 @@ -import { describe, expect, it } from "vitest"; -import { isPlainObject } from "./isPlainObject"; +import { describe, expect, it } from 'vitest'; +import { isPlainObject } from './isPlainObject'; describe('isPlainObject', () => { it('returns true for plain objects', () => { @@ -15,4 +15,4 @@ describe('isPlainObject', () => { expect(isPlainObject(Buffer.from('123123'))).toBe(false); expect(isPlainObject(new Uint8Array([1, 2, 3]))).toBe(false); }); -}); \ No newline at end of file +}); diff --git a/src/predicate/isPlainObject.ts b/src/predicate/isPlainObject.ts index 059f48cd..52b45474 100644 --- a/src/predicate/isPlainObject.ts +++ b/src/predicate/isPlainObject.ts @@ -1,9 +1,9 @@ /** * Checks if a given value is a plain object. - * + * * @param {object} object - The value to check. * @returns {boolean} - True if the value is a plain object, otherwise false. - * + * * @example * console.log(isPlainObject({})); // true * console.log(isPlainObject([])); // false @@ -35,4 +35,4 @@ export function isPlainObject(object: object): boolean { } return Object.getPrototypeOf(object) === proto; -} \ No newline at end of file +} diff --git a/src/promise/withTimeout.ts b/src/promise/withTimeout.ts index c9e331b7..0f1baaab 100644 --- a/src/promise/withTimeout.ts +++ b/src/promise/withTimeout.ts @@ -1,13 +1,13 @@ import { timeout } from './timeout.ts'; /** - * Executes an async function and enforces a timeout. - * + * Executes an async function and enforces a timeout. + * * If the promise does not resolve within the specified time, * the timeout will trigger and the returned promise will be rejected. * * - * @template T + * @template T * @param {() => Promise} run - A function that returns a promise to be executed. * @param {number} ms - The timeout duration in milliseconds. * @returns {Promise} A promise that resolves with the result of the `run` function or rejects if the timeout is reached. diff --git a/src/string/camelCase.spec.ts b/src/string/camelCase.spec.ts index 329be967..12372d16 100644 --- a/src/string/camelCase.spec.ts +++ b/src/string/camelCase.spec.ts @@ -1,42 +1,40 @@ -import { describe, expect, it } from "vitest"; -import { camelCase } from "./camelCase"; +import { describe, expect, it } from 'vitest'; +import { camelCase } from './camelCase'; -describe("camelCase", () => { - it("should change camel case to camel case", async () => { - expect(camelCase("camelCase")).toEqual("camelCase"); +describe('camelCase', () => { + it('should change camel case to camel case', async () => { + expect(camelCase('camelCase')).toEqual('camelCase'); }); - it("should change space to camel case", async () => { - expect(camelCase("some whitespace")).toEqual("someWhitespace"); + it('should change space to camel case', async () => { + expect(camelCase('some whitespace')).toEqual('someWhitespace'); }); - it("should change hyphen to camel case", async () => { - expect(camelCase("hyphen-text")).toEqual("hyphenText"); + it('should change hyphen to camel case', async () => { + expect(camelCase('hyphen-text')).toEqual('hyphenText'); }); - it("should change Acronyms to small letter", async () => { - expect(camelCase("HTTPRequest")).toEqual("httpRequest"); + it('should change Acronyms to small letter', async () => { + expect(camelCase('HTTPRequest')).toEqual('httpRequest'); }); - it("should handle leading and trailing whitespace", async () => { - expect(camelCase(" leading and trailing whitespace")).toEqual( - "leadingAndTrailingWhitespace", - ); + it('should handle leading and trailing whitespace', async () => { + expect(camelCase(' leading and trailing whitespace')).toEqual('leadingAndTrailingWhitespace'); }); - it("should handle special characters correctly", async () => { - expect(camelCase("special@characters!")).toEqual("specialCharacters"); + it('should handle special characters correctly', async () => { + expect(camelCase('special@characters!')).toEqual('specialCharacters'); }); - it("should handle strings that are already in camel_case", async () => { - expect(camelCase("camel_case")).toEqual("camelCase"); + it('should handle strings that are already in camel_case', async () => { + expect(camelCase('camel_case')).toEqual('camelCase'); }); - it("should work with an empty string", async () => { - expect(camelCase("")).toEqual(""); + it('should work with an empty string', async () => { + expect(camelCase('')).toEqual(''); }); - it("should work with screaming camel case", async () => { - expect(camelCase("FOO_BAR")).toEqual("fooBar"); + it('should work with screaming camel case', async () => { + expect(camelCase('FOO_BAR')).toEqual('fooBar'); }); }); diff --git a/src/string/camelCase.ts b/src/string/camelCase.ts index 4e0f12e1..b1e43c74 100644 --- a/src/string/camelCase.ts +++ b/src/string/camelCase.ts @@ -1,5 +1,5 @@ -import { capitalize } from "./capitalize.ts"; -import { getWords } from "./_internal/getWords.ts"; +import { capitalize } from './capitalize.ts'; +import { getWords } from './_internal/getWords.ts'; /** * Converts a string to camel case. @@ -20,11 +20,10 @@ export function camelCase(str: string): string { const words = getWords(str); if (words.length === 0) { - return ""; + return ''; } const [first, ...rest] = words; - return `${first.toLowerCase()}${rest.map((word) => capitalize(word)).join("") - }`; + return `${first.toLowerCase()}${rest.map(word => capitalize(word)).join('')}`; } diff --git a/tests/utils/createPackageTarball.ts b/tests/utils/createPackageTarball.ts index 3dcde230..89f63e55 100644 --- a/tests/utils/createPackageTarball.ts +++ b/tests/utils/createPackageTarball.ts @@ -13,5 +13,5 @@ export async function createPackageTarball() { return { path: tarballPath, - } -} \ No newline at end of file + }; +} diff --git a/tests/utils/createTmpDir.ts b/tests/utils/createTmpDir.ts index dd441f05..976fa4fb 100644 --- a/tests/utils/createTmpDir.ts +++ b/tests/utils/createTmpDir.ts @@ -8,4 +8,4 @@ export async function createTmpDir() { await fs.promises.mkdir(tmpdir, { recursive: true }); return tmpdir; -} \ No newline at end of file +} diff --git a/tests/utils/parseTar.ts b/tests/utils/parseTar.ts index 3992d627..d322bae2 100644 --- a/tests/utils/parseTar.ts +++ b/tests/utils/parseTar.ts @@ -27,4 +27,4 @@ export async function* parseTar(tgz: Buffer) { yield it; it.resume(); } -} \ No newline at end of file +} diff --git a/vitest.config.mts b/vitest.config.mts index 3c1b8012..d7b626e0 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -8,7 +8,7 @@ export default defineConfig({ coverage: { provider: 'istanbul', include: ['src/**/*'], - exclude: ['src/compat/_internal/**/*'] + exclude: ['src/compat/_internal/**/*'], }, }, });