From 7a52ddeba2a68388b544f529d2d92104420f77b0 Mon Sep 17 00:00:00 2001 From: Shipwreckt Date: Fri, 31 Oct 2025 20:02:14 +0000 Subject: Changed from static to 11ty! --- .../@11ty/eleventy-utils/src/IsPlainObject.js | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 node_modules/@11ty/eleventy-utils/src/IsPlainObject.js (limited to 'node_modules/@11ty/eleventy-utils/src/IsPlainObject.js') diff --git a/node_modules/@11ty/eleventy-utils/src/IsPlainObject.js b/node_modules/@11ty/eleventy-utils/src/IsPlainObject.js new file mode 100644 index 0000000..1d4c752 --- /dev/null +++ b/node_modules/@11ty/eleventy-utils/src/IsPlainObject.js @@ -0,0 +1,24 @@ +/* Prior art: this utility was created for https://github.com/11ty/eleventy/issues/2214 + + * Inspired by implementations from `is-what`, `typechecker`, `jQuery`, and `lodash` + + * `is-what` + * More reading at https://www.npmjs.com/package/is-what#user-content-isplainobject-vs-isanyobject + * if (Object.prototype.toString.call(value).slice(8, -1) !== 'Object') return false; + * return value.constructor === Object && Object.getPrototypeOf(value) === Object.prototype; + + * `typechecker` + * return value !== null && typeof value === 'object' && value.__proto__ === Object.prototype; + + * Notably jQuery and lodash have very similar implementations. + + * For later, remember the `value === Object(value)` trick + */ + +module.exports = function (value) { + if (value === null || typeof value !== "object") { + return false; + } + let proto = Object.getPrototypeOf(value); + return !proto || proto === Object.prototype; +}; -- cgit v1.2.3