Skip to content

Commit

Permalink
use isPlainObject function
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisblossom committed May 21, 2019
1 parent 901affd commit 57d2cd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ new CleanWebpackPlugin({
//
// Use !negative patterns to exclude files
//
// default: disabled
// default: []
cleanAfterEveryBuildPatterns: ['static*.*', '!static1.js'],

// Allow clean patterns outside of process.cwd()
Expand Down
12 changes: 11 additions & 1 deletion src/clean-webpack-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ export interface Options {
dangerouslyAllowCleanPatternsOutsideProject?: boolean;
}

// Copied from https://github.com/sindresorhus/is-plain-obj/blob/97480673cf12145b32ec2ee924980d66572e8a86/index.js
function isPlainObject(value: unknown): boolean {
if (Object.prototype.toString.call(value) !== '[object Object]') {
return false;
}

const prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.getPrototypeOf({});
}

class CleanWebpackPlugin {
private readonly dry: boolean;
private readonly verbose: boolean;
Expand All @@ -75,7 +85,7 @@ class CleanWebpackPlugin {
private outputPath: string;

constructor(options: Options = {}) {
if (Object.prototype.toString.call(options) !== "[object Object]") {
if (isPlainObject(options) === false) {
throw new Error(`clean-webpack-plugin only accepts an options object. See:
https://github.com/johnagan/clean-webpack-plugin#options-and-defaults-optional`);
}
Expand Down

0 comments on commit 57d2cd4

Please sign in to comment.