moderndash
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -24,2 +24,3 @@ /** | ||
type GenericFunction<TFunc extends (...args: any) => any> = (...args: Parameters<TFunc>) => ReturnType<TFunc>; | ||
type GenericObject = Record<RecordKey, unknown>; | ||
@@ -818,3 +819,17 @@ /** | ||
declare function isPlainObject(value: unknown): value is object; | ||
/** | ||
* Checks if the value is a plain object. | ||
* | ||
* @example | ||
* isPlainObject({}) // => true | ||
* isPlainObject({ a: 1 }) // => true | ||
* isPlainObject(null) // => false | ||
* isPlainObject('1') // => false | ||
* isPlainObject([]) // => false | ||
* isPlainObject(new Function()) // => false | ||
* isPlainObject(new Date()) // => false | ||
* @param value - The value to check | ||
* @returns Boolean indicating if the value is a plain object | ||
*/ | ||
declare function isPlainObject(value: unknown): value is GenericObject; | ||
@@ -821,0 +836,0 @@ /** |
@@ -30,2 +30,7 @@ // src/array/chunk.ts | ||
// src/validate/isPlainObject.ts | ||
function isPlainObject(value) { | ||
return value?.constructor === Object; | ||
} | ||
// src/validate/isEqual.ts | ||
@@ -35,12 +40,12 @@ function isEqual(a, b) { | ||
return true; | ||
if (Array.isArray(a) && Array.isArray(b)) { | ||
return isSameArray(a, b); | ||
} | ||
if (a instanceof Date && b instanceof Date) { | ||
return a.getTime() === b.getTime(); | ||
} | ||
if (Array.isArray(a) && Array.isArray(b)) { | ||
return isSameArray(a, b); | ||
} | ||
if (a instanceof RegExp && b instanceof RegExp) { | ||
return a.toString() === b.toString(); | ||
} | ||
if (isObject(a) && isObject(b)) { | ||
if (isPlainObject(a) && isPlainObject(b)) { | ||
return isSameObject(a, b); | ||
@@ -50,12 +55,9 @@ } | ||
} | ||
function isObject(value) { | ||
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]"; | ||
} | ||
function isSameObject(value1, value2) { | ||
const keys1 = Object.keys(value1); | ||
const keys2 = Object.keys(value2); | ||
function isSameObject(a, b) { | ||
const keys1 = Object.keys(a); | ||
const keys2 = Object.keys(b); | ||
if (!isEqual(keys1, keys2)) | ||
return false; | ||
for (const key of keys1) { | ||
if (!isEqual(value1[key], value2[key])) | ||
if (!isEqual(a[key], b[key])) | ||
return false; | ||
@@ -65,7 +67,7 @@ } | ||
} | ||
function isSameArray(value1, value2) { | ||
if (value1.length !== value2.length) | ||
function isSameArray(a, b) { | ||
if (a.length !== b.length) | ||
return false; | ||
for (const [i, element] of value1.entries()) { | ||
if (!isEqual(element, value2[i])) | ||
for (const [i, element] of a.entries()) { | ||
if (!isEqual(element, b[i])) | ||
return false; | ||
@@ -647,7 +649,2 @@ } | ||
// src/validate/isPlainObject.ts | ||
function isPlainObject(value) { | ||
return value !== null && typeof value === "object" && value.constructor === Object; | ||
} | ||
// src/validate/isUrl.ts | ||
@@ -654,0 +651,0 @@ function isUrl(str) { |
@@ -51,3 +51,3 @@ { | ||
}, | ||
"version": "0.6.1" | ||
"version": "0.7.0" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
189676
2181