Skip to content

Commit

Permalink
chore(release): 4.1.0 [skip ci]
Browse files Browse the repository at this point in the history
# [4.1.0](v4.0.4...v4.1.0) (2022-06-13)

### Features

* treat module imports as records ([20c0dfb](20c0dfb)), closes [#133](#133)
  • Loading branch information
semantic-release-bot committed Jun 13, 2022
1 parent b757759 commit 9d04bd0
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
All notable changes to this project will be documented in this file. Dates are displayed in UTC.

# [4.1.0](https://github.com/RebeccaStevens/deepmerge-ts/compare/v4.0.4...v4.1.0) (2022-06-13)


### Features

* treat module imports as records ([20c0dfb](https://github.com/RebeccaStevens/deepmerge-ts/commit/20c0dfb82e4273b10e5a02ba0e74aada42b9bb7a)), closes [#133](https://github.com/RebeccaStevens/deepmerge-ts/issues/133)

## [4.0.4](https://github.com/RebeccaStevens/deepmerge-ts/compare/v4.0.3...v4.0.4) (2022-06-13)


Expand Down
48 changes: 45 additions & 3 deletions dist/deno/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { isPlainObject } from "https://raw.githubusercontent.com/jonschlinkert/is-plain-object/v5.0.0/is-plain-object.js";

/**
* The different types of objects deepmerge-ts support.
*/
Expand Down Expand Up @@ -27,7 +25,7 @@ export function getObjectType(object: unknown): ObjectType {
return ObjectType.ARRAY;
}

if (isPlainObject(object)) {
if (isRecord(object)) {
return ObjectType.RECORD;
}

Expand Down Expand Up @@ -102,3 +100,47 @@ export function getIterableOfIterables<T>(
},
};
}

const validRecordToStringValues = new Set([
"[object Object]",
"[object Module]",
]);

/**
* Does the given object appear to be a record.
*/
function isRecord(value: object): value is Record<PropertyKey, unknown> {
// All records are objects.
if (!validRecordToStringValues.has(Object.prototype.toString.call(value))) {
return false;
}

const { constructor } = value;

// If has modified constructor.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (constructor === undefined) {
return true;
}

// eslint-disable-next-line prefer-destructuring
const prototype: unknown = constructor.prototype;

// If has modified prototype.
if (
prototype === null ||
typeof prototype !== "object" ||
!validRecordToStringValues.has(Object.prototype.toString.call(prototype))
) {
return false;
}

// If constructor does not have an Object-specific method.
// eslint-disable-next-line sonarjs/prefer-single-boolean-return, no-prototype-builtins
if (!prototype.hasOwnProperty("isPrototypeOf")) {
return false;
}

// Most likely a record.
return true;
}
38 changes: 35 additions & 3 deletions dist/node/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

Object.defineProperty(exports, '__esModule', { value: true });

var isPlainObject = require('is-plain-object');

/**
* Get the type of the given object.
*
Expand All @@ -17,7 +15,7 @@ function getObjectType(object) {
if (Array.isArray(object)) {
return 2 /* ObjectType.ARRAY */;
}
if (isPlainObject.isPlainObject(object)) {
if (isRecord(object)) {
return 1 /* ObjectType.RECORD */;
}
if (object instanceof Set) {
Expand Down Expand Up @@ -77,6 +75,40 @@ function getIterableOfIterables(iterables) {
},
};
}
const validRecordToStringValues = new Set([
"[object Object]",
"[object Module]",
]);
/**
* Does the given object appear to be a record.
*/
function isRecord(value) {
// All records are objects.
if (!validRecordToStringValues.has(Object.prototype.toString.call(value))) {
return false;
}
const { constructor } = value;
// If has modified constructor.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (constructor === undefined) {
return true;
}
// eslint-disable-next-line prefer-destructuring
const prototype = constructor.prototype;
// If has modified prototype.
if (prototype === null ||
typeof prototype !== "object" ||
!validRecordToStringValues.has(Object.prototype.toString.call(prototype))) {
return false;
}
// If constructor does not have an Object-specific method.
// eslint-disable-next-line sonarjs/prefer-single-boolean-return, no-prototype-builtins
if (!prototype.hasOwnProperty("isPrototypeOf")) {
return false;
}
// Most likely a record.
return true;
}

const defaultMergeFunctions = {
mergeMaps: defaultMergeMaps,
Expand Down
38 changes: 35 additions & 3 deletions dist/node/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { isPlainObject } from 'is-plain-object';

/**
* Get the type of the given object.
*
Expand All @@ -13,7 +11,7 @@ function getObjectType(object) {
if (Array.isArray(object)) {
return 2 /* ObjectType.ARRAY */;
}
if (isPlainObject(object)) {
if (isRecord(object)) {
return 1 /* ObjectType.RECORD */;
}
if (object instanceof Set) {
Expand Down Expand Up @@ -73,6 +71,40 @@ function getIterableOfIterables(iterables) {
},
};
}
const validRecordToStringValues = new Set([
"[object Object]",
"[object Module]",
]);
/**
* Does the given object appear to be a record.
*/
function isRecord(value) {
// All records are objects.
if (!validRecordToStringValues.has(Object.prototype.toString.call(value))) {
return false;
}
const { constructor } = value;
// If has modified constructor.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (constructor === undefined) {
return true;
}
// eslint-disable-next-line prefer-destructuring
const prototype = constructor.prototype;
// If has modified prototype.
if (prototype === null ||
typeof prototype !== "object" ||
!validRecordToStringValues.has(Object.prototype.toString.call(prototype))) {
return false;
}
// If constructor does not have an Object-specific method.
// eslint-disable-next-line sonarjs/prefer-single-boolean-return, no-prototype-builtins
if (!prototype.hasOwnProperty("isPrototypeOf")) {
return false;
}
// Most likely a record.
return true;
}

const defaultMergeFunctions = {
mergeMaps: defaultMergeMaps,
Expand Down

0 comments on commit 9d04bd0

Please sign in to comment.