Skip to content

Commit

Permalink
fix(core): adjust isDefined
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Jan 3, 2021
1 parent c0a406d commit 6187453
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/classes/src/lib/utils/instantiate.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function instantiate<TModel extends Dictionary<TModel>>(

// if is String, Number, Boolean, assign valueAtKey or undefined
if (isPrimitiveConstructor(metaResult)) {
instance[key] = isDefined(valueAtKey) ? valueAtKey : undefined;
instance[key] = isDefined(valueAtKey, true) ? valueAtKey : undefined;
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/utils/is-defined.util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isDefined(value: unknown): boolean {
return value != null;
export function isDefined(value: unknown, strict = false): boolean {
return strict ? value !== undefined : value != null;
}
1 change: 1 addition & 0 deletions packages/core/src/lib/utils/specs/is-defined.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isDefined } from '@automapper/core';
describe('isDefined', () => {
it('should return properly', () => {
expect(isDefined(null)).toEqual(false);
expect(isDefined(null, true)).toEqual(true);
expect(isDefined(undefined)).toEqual(false);
expect(isDefined('foo')).toEqual(true);
expect(isDefined(String)).toEqual(true);
Expand Down

0 comments on commit 6187453

Please sign in to comment.