diff --git a/index.js b/index.js index 132db41..2008ce5 100644 --- a/index.js +++ b/index.js @@ -62,6 +62,7 @@ is.symbol = x => typeof x === 'symbol'; is.array = Array.isArray; is.function = x => typeof x === 'function'; +is.class = x => typeof x === 'function' && /^\s*class\s+/.test(x.toString()); is.buffer = Buffer.isBuffer; is.object = x => { @@ -130,7 +131,7 @@ is.plainObject = x => { // eslint-disable-next-line no-return-assign return getObjectType(x) === 'Object' && (prototype = Object.getPrototypeOf(x), prototype === null || - prototype === Object.getPrototypeOf({})); + prototype === Object.getPrototypeOf({})); }; is.iterable = x => !is.null(x) && !is.undefined(x) && typeof x[Symbol.iterator] === 'function'; diff --git a/test.js b/test.js index 7868637..da809d0 100644 --- a/test.js +++ b/test.js @@ -6,6 +6,7 @@ const isNode8orHigher = Number(process.versions.node.split('.')[0]) >= 8; const PromiseSubclassFixture = class extends Promise {}; const ErrorSubclassFixture = class extends Error {}; +const ClassFixture = class A {}; const types = new Map([ ['undefined', undefined], @@ -28,6 +29,9 @@ const types = new Map([ [1, 2], new Array(2) ]], + ['class', [ + new ClassFixture() + ]], ['function', [ function foo() {}, // eslint-disable-line func-names function () {}, @@ -130,6 +134,10 @@ test('is.array', t => { testType(t, 'array'); }); +test('is.class', t => { + testType(t, 'function'); +}); + test('is.function', t => { testType(t, 'function'); });