From b1dc2112aa3a0084229a1531424084e222748c00 Mon Sep 17 00:00:00 2001 From: Chau Tran Date: Sun, 14 Feb 2021 14:33:34 -0600 Subject: [PATCH] refactor(classes): use isDateConstructor and isPrimitiveConstructor from core --- packages/classes/src/lib/utils/index.ts | 2 -- packages/classes/src/lib/utils/instantiate.util.ts | 9 ++++++--- .../classes/src/lib/utils/is-date-constructor.util.ts | 8 -------- .../src/lib/utils/is-primitive-constructor.util.ts | 10 ---------- .../lib/utils/specs/is-date-constructor.util.spec.ts | 9 --------- .../utils/specs/is-primitive-constructor.util.spec.ts | 11 ----------- 6 files changed, 6 insertions(+), 43 deletions(-) delete mode 100644 packages/classes/src/lib/utils/is-date-constructor.util.ts delete mode 100644 packages/classes/src/lib/utils/is-primitive-constructor.util.ts delete mode 100644 packages/classes/src/lib/utils/specs/is-date-constructor.util.spec.ts delete mode 100644 packages/classes/src/lib/utils/specs/is-primitive-constructor.util.spec.ts diff --git a/packages/classes/src/lib/utils/index.ts b/packages/classes/src/lib/utils/index.ts index 8d577f8b3..378040a0d 100644 --- a/packages/classes/src/lib/utils/index.ts +++ b/packages/classes/src/lib/utils/index.ts @@ -1,4 +1,2 @@ export * from './instantiate.util'; -export * from './is-primitive-constructor.util'; -export * from './is-date-constructor.util'; export * from './is-class.util'; diff --git a/packages/classes/src/lib/utils/instantiate.util.ts b/packages/classes/src/lib/utils/instantiate.util.ts index 4fd8d2bd1..f166d6b01 100644 --- a/packages/classes/src/lib/utils/instantiate.util.ts +++ b/packages/classes/src/lib/utils/instantiate.util.ts @@ -1,9 +1,12 @@ -import { isDefined, isEmpty } from '@automapper/core'; +import { + isDateConstructor, + isDefined, + isEmpty, + isPrimitiveConstructor, +} from '@automapper/core'; import type { Dictionary } from '@automapper/types'; import type { ClassInstanceStorage, ClassMetadataStorage } from '../storages'; import type { Constructible } from '../types'; -import { isDateConstructor } from './is-date-constructor.util'; -import { isPrimitiveConstructor } from './is-primitive-constructor.util'; /** * Recursively instantiate a model with its metadata diff --git a/packages/classes/src/lib/utils/is-date-constructor.util.ts b/packages/classes/src/lib/utils/is-date-constructor.util.ts deleted file mode 100644 index 9d1e56f89..000000000 --- a/packages/classes/src/lib/utils/is-date-constructor.util.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Check if value is a Date constructor - * - * @param {Function} value - */ -export function isDateConstructor(value: unknown): boolean { - return value === Date; -} diff --git a/packages/classes/src/lib/utils/is-primitive-constructor.util.ts b/packages/classes/src/lib/utils/is-primitive-constructor.util.ts deleted file mode 100644 index ec9285ca9..000000000 --- a/packages/classes/src/lib/utils/is-primitive-constructor.util.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Check if value is a String/Number/Boolean constructor - * - * @param {Function} value - */ -export function isPrimitiveConstructor(value: unknown): boolean { - return ( - value === String || value === Number || value === Boolean || value === Array - ); -} diff --git a/packages/classes/src/lib/utils/specs/is-date-constructor.util.spec.ts b/packages/classes/src/lib/utils/specs/is-date-constructor.util.spec.ts deleted file mode 100644 index fa7517c18..000000000 --- a/packages/classes/src/lib/utils/specs/is-date-constructor.util.spec.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { isDateConstructor } from '../is-date-constructor.util'; - -describe('isDateConstructor', () => { - it('should work', () => { - expect(isDateConstructor(Date)).toEqual(true); - expect(isDateConstructor(String)).toEqual(false); - expect(isDateConstructor(Number)).toEqual(false); - }); -}); diff --git a/packages/classes/src/lib/utils/specs/is-primitive-constructor.util.spec.ts b/packages/classes/src/lib/utils/specs/is-primitive-constructor.util.spec.ts deleted file mode 100644 index 9be0ef551..000000000 --- a/packages/classes/src/lib/utils/specs/is-primitive-constructor.util.spec.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { isPrimitiveConstructor } from '../is-primitive-constructor.util'; - -describe('isPrimitiveConstructor', () => { - it('should work', () => { - expect(isPrimitiveConstructor(String)).toEqual(true); - expect(isPrimitiveConstructor(Number)).toEqual(true); - expect(isPrimitiveConstructor(Boolean)).toEqual(true); - expect(isPrimitiveConstructor(Array)).toEqual(true); - expect(isPrimitiveConstructor(Date)).toEqual(false); - }); -});