Skip to content

Commit 9d04bd0

Browse files
chore(release): 4.1.0 [skip ci]
# [4.1.0](v4.0.4...v4.1.0) (2022-06-13) ### Features * treat module imports as records ([20c0dfb](20c0dfb)), closes [#133](#133)
1 parent b757759 commit 9d04bd0

4 files changed

Lines changed: 122 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog
22
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
33

4+
# [4.1.0](https://github.com/RebeccaStevens/deepmerge-ts/compare/v4.0.4...v4.1.0) (2022-06-13)
5+
6+
7+
### Features
8+
9+
* treat module imports as records ([20c0dfb](https://github.com/RebeccaStevens/deepmerge-ts/commit/20c0dfb82e4273b10e5a02ba0e74aada42b9bb7a)), closes [#133](https://github.com/RebeccaStevens/deepmerge-ts/issues/133)
10+
411
## [4.0.4](https://github.com/RebeccaStevens/deepmerge-ts/compare/v4.0.3...v4.0.4) (2022-06-13)
512

613

dist/deno/utils.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { isPlainObject } from "https://raw.githubusercontent.com/jonschlinkert/is-plain-object/v5.0.0/is-plain-object.js";
2-
31
/**
42
* The different types of objects deepmerge-ts support.
53
*/
@@ -27,7 +25,7 @@ export function getObjectType(object: unknown): ObjectType {
2725
return ObjectType.ARRAY;
2826
}
2927

30-
if (isPlainObject(object)) {
28+
if (isRecord(object)) {
3129
return ObjectType.RECORD;
3230
}
3331

@@ -102,3 +100,47 @@ export function getIterableOfIterables<T>(
102100
},
103101
};
104102
}
103+
104+
const validRecordToStringValues = new Set([
105+
"[object Object]",
106+
"[object Module]",
107+
]);
108+
109+
/**
110+
* Does the given object appear to be a record.
111+
*/
112+
function isRecord(value: object): value is Record<PropertyKey, unknown> {
113+
// All records are objects.
114+
if (!validRecordToStringValues.has(Object.prototype.toString.call(value))) {
115+
return false;
116+
}
117+
118+
const { constructor } = value;
119+
120+
// If has modified constructor.
121+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
122+
if (constructor === undefined) {
123+
return true;
124+
}
125+
126+
// eslint-disable-next-line prefer-destructuring
127+
const prototype: unknown = constructor.prototype;
128+
129+
// If has modified prototype.
130+
if (
131+
prototype === null ||
132+
typeof prototype !== "object" ||
133+
!validRecordToStringValues.has(Object.prototype.toString.call(prototype))
134+
) {
135+
return false;
136+
}
137+
138+
// If constructor does not have an Object-specific method.
139+
// eslint-disable-next-line sonarjs/prefer-single-boolean-return, no-prototype-builtins
140+
if (!prototype.hasOwnProperty("isPrototypeOf")) {
141+
return false;
142+
}
143+
144+
// Most likely a record.
145+
return true;
146+
}

dist/node/index.cjs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

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

5-
var isPlainObject = require('is-plain-object');
6-
75
/**
86
* Get the type of the given object.
97
*
@@ -17,7 +15,7 @@ function getObjectType(object) {
1715
if (Array.isArray(object)) {
1816
return 2 /* ObjectType.ARRAY */;
1917
}
20-
if (isPlainObject.isPlainObject(object)) {
18+
if (isRecord(object)) {
2119
return 1 /* ObjectType.RECORD */;
2220
}
2321
if (object instanceof Set) {
@@ -77,6 +75,40 @@ function getIterableOfIterables(iterables) {
7775
},
7876
};
7977
}
78+
const validRecordToStringValues = new Set([
79+
"[object Object]",
80+
"[object Module]",
81+
]);
82+
/**
83+
* Does the given object appear to be a record.
84+
*/
85+
function isRecord(value) {
86+
// All records are objects.
87+
if (!validRecordToStringValues.has(Object.prototype.toString.call(value))) {
88+
return false;
89+
}
90+
const { constructor } = value;
91+
// If has modified constructor.
92+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
93+
if (constructor === undefined) {
94+
return true;
95+
}
96+
// eslint-disable-next-line prefer-destructuring
97+
const prototype = constructor.prototype;
98+
// If has modified prototype.
99+
if (prototype === null ||
100+
typeof prototype !== "object" ||
101+
!validRecordToStringValues.has(Object.prototype.toString.call(prototype))) {
102+
return false;
103+
}
104+
// If constructor does not have an Object-specific method.
105+
// eslint-disable-next-line sonarjs/prefer-single-boolean-return, no-prototype-builtins
106+
if (!prototype.hasOwnProperty("isPrototypeOf")) {
107+
return false;
108+
}
109+
// Most likely a record.
110+
return true;
111+
}
80112

81113
const defaultMergeFunctions = {
82114
mergeMaps: defaultMergeMaps,

dist/node/index.mjs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { isPlainObject } from 'is-plain-object';
2-
31
/**
42
* Get the type of the given object.
53
*
@@ -13,7 +11,7 @@ function getObjectType(object) {
1311
if (Array.isArray(object)) {
1412
return 2 /* ObjectType.ARRAY */;
1513
}
16-
if (isPlainObject(object)) {
14+
if (isRecord(object)) {
1715
return 1 /* ObjectType.RECORD */;
1816
}
1917
if (object instanceof Set) {
@@ -73,6 +71,40 @@ function getIterableOfIterables(iterables) {
7371
},
7472
};
7573
}
74+
const validRecordToStringValues = new Set([
75+
"[object Object]",
76+
"[object Module]",
77+
]);
78+
/**
79+
* Does the given object appear to be a record.
80+
*/
81+
function isRecord(value) {
82+
// All records are objects.
83+
if (!validRecordToStringValues.has(Object.prototype.toString.call(value))) {
84+
return false;
85+
}
86+
const { constructor } = value;
87+
// If has modified constructor.
88+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
89+
if (constructor === undefined) {
90+
return true;
91+
}
92+
// eslint-disable-next-line prefer-destructuring
93+
const prototype = constructor.prototype;
94+
// If has modified prototype.
95+
if (prototype === null ||
96+
typeof prototype !== "object" ||
97+
!validRecordToStringValues.has(Object.prototype.toString.call(prototype))) {
98+
return false;
99+
}
100+
// If constructor does not have an Object-specific method.
101+
// eslint-disable-next-line sonarjs/prefer-single-boolean-return, no-prototype-builtins
102+
if (!prototype.hasOwnProperty("isPrototypeOf")) {
103+
return false;
104+
}
105+
// Most likely a record.
106+
return true;
107+
}
76108

77109
const defaultMergeFunctions = {
78110
mergeMaps: defaultMergeMaps,

0 commit comments

Comments
 (0)