@aikidosec/firewall
Version:
Zen by Aikido is an embedded Application Firewall that autonomously protects Node.js apps against common and critical attacks, provides rate limiting, detects malicious traffic (including bots), and more.
43 lines (42 loc) • 1.69 kB
JavaScript
;
/**
* Grabbed from https://github.com/jonschlinkert/is-plain-object
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPlainObject = isPlainObject;
function isObject(o) {
return Object.prototype.toString.call(o) === "[object Object]";
}
/**
* This function examines an object to check if it's a plain object.
* @param o The object you want to examine
* @returns True when it is a plain object, otherwise false
* @example
* isPlainObject(Object.create({})) // Returns true
* @example
* isPlainObject({ foo: "bar" }) // Returns true
* @example
* isPlainObject(new Foo()) // Returns false
*/
function isPlainObject(o) {
if (isObject(o) === false)
return false;
// Prototype of the instance itself (e.g. Object.prototype for `{}`)
const objectPrototype = Object.getPrototypeOf(o);
// Constructor found on the object's prototype chain.
// Reading it from the prototype avoids issues when `o` has its own `constructor` key.
const constructorFromPrototype = objectPrototype === null || objectPrototype === void 0 ? void 0 : objectPrototype.constructor;
if (constructorFromPrototype === undefined) {
return true;
}
// Check the constructor's prototype to distinguish plain objects from custom class instances.
const constructorPrototype = constructorFromPrototype.prototype;
if (isObject(constructorPrototype) === false)
return false;
// Its constructor does not have an Object-specific method
if (Object.prototype.hasOwnProperty.call(constructorPrototype, "isPrototypeOf") === false) {
return false;
}
// Most likely a plain Object
return true;
}