Skip to content

Commit 5a7f120

Browse files
committed
chore: 文件名优化
1 parent 7299636 commit 5a7f120

11 files changed

+21
-21
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function normalizeError(error: unknown): Error {
1+
export function errorNormalize(error: unknown): Error {
22
if (error && error instanceof Error) return error;
33
return new Error(String(error ?? ''));
44
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export { pkgName, pkgVersion } from './const';
22
export * from './callbackCurry';
3-
export * from './normalize-error';
3+
export * from './errorNormalize';
44
export * from './tryFunction';
55
export * from './tryCallback';
66
export * from './tryPromise';

src/tryCallback.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
CallbackFunction6,
99
} from './callbackCurry';
1010
import { callbackCurry } from './callbackCurry';
11-
import { normalizeError } from './normalize-error';
11+
import { errorNormalize } from './errorNormalize';
1212
import type { FlattenReturn } from './types/return';
1313

1414
export function tryCallback<T>(cf: CallbackFunction0<T>): Promise<FlattenReturn<T>>;
@@ -45,7 +45,7 @@ export function tryCallback(cf: any, ...args: any[]): Promise<FlattenReturn<any>
4545
// @ts-ignore
4646
callbackCurry.apply(this, [cf, ...args])((err, res) => {
4747
if (err) {
48-
resolve([normalizeError(err), undefined] as const);
48+
resolve([errorNormalize(err), undefined] as const);
4949
} else {
5050
resolve([null, res] as const);
5151
}

src/tryFunction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { normalizeError } from './normalize-error';
1+
import { errorNormalize } from './errorNormalize';
22
import type { FlattenReturn } from './types/return';
33

44
export type SyncFunction<T> = () => T;
@@ -7,6 +7,6 @@ export function tryFunction<T>(syncFn: () => T): FlattenReturn<T> {
77
try {
88
return [null, syncFn()] as const;
99
} catch (err) {
10-
return [normalizeError(err), undefined] as const;
10+
return [errorNormalize(err), undefined] as const;
1111
}
1212
}

src/tryPromise.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { normalizeError } from './normalize-error';
1+
import { errorNormalize } from './errorNormalize';
22
import type { FlattenReturn } from './types/return';
33

44
export function tryPromise<T>(promise: PromiseLike<T>): PromiseLike<FlattenReturn<T>> {
55
return promise.then(
66
(res) => [null, res] as const,
7-
(err) => [normalizeError(err), undefined] as const
7+
(err) => [errorNormalize(err), undefined] as const
88
);
99
}

test/error-nomalize.test.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/errorNomalize.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect, test } from 'vitest';
2+
import { errorNormalize } from '../src';
3+
4+
test('errorNormalize', () => {
5+
expect(errorNormalize(1).message).toBe('1');
6+
expect(errorNormalize('1').message).toBe('1');
7+
expect(errorNormalize(null).message).toBe('');
8+
expect(errorNormalize(undefined).message).toBe('');
9+
expect(errorNormalize(true).message).toBe('true');
10+
const err1 = new Error('1');
11+
const err2 = errorNormalize(err1);
12+
expect(err2).toBe(err1);
13+
});
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)