Skip to content

Commit

Permalink
Clean up isPlainObject, add permalink to original implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed Apr 29, 2024
1 parent 4dbae05 commit 456545b
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions packages/integration/src/processVanillaFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,29 @@ import type { IdentifierOption } from './types';

const originalNodeEnv = process.env.NODE_ENV;

// Copied from https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore/blob/51f83bd3db728fd7ee177de1ffc253fdb99c537f/README.md#_isplainobject
function isPlainObject(value: unknown) {
if (typeof value !== 'object' || value === null) return false;
if (typeof value !== 'object' || value === null) {
return false;
}

if (Object.prototype.toString.call(value) !== '[object Object]') {
return false;
}

if (Object.prototype.toString.call(value) !== '[object Object]') return false;
const prototype = Object.getPrototypeOf(value);
if (prototype === null) {
return true;
}

const proto = Object.getPrototypeOf(value);
if (proto === null) return true;
const constructor =
Object.prototype.hasOwnProperty.call(prototype, 'constructor') &&
prototype.constructor;

const Ctor =
Object.prototype.hasOwnProperty.call(proto, 'constructor') &&
proto.constructor;
return (
typeof Ctor === 'function' &&
Ctor instanceof Ctor &&
Function.prototype.call(Ctor) === Function.prototype.call(value)
typeof constructor === 'function' &&
constructor instanceof constructor &&
Function.prototype.call(constructor) === Function.prototype.call(value)
);
}

Expand Down

0 comments on commit 456545b

Please sign in to comment.