Skip to content

Commit

Permalink
Make ttype return boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Jan 3, 2024
1 parent a291dcb commit 60e19c0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/utils/node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* A port of tap's `t.type` that can be used with `node:assert`
* https://github.com/tapjs/tapjs/blob/511019b2ac0fa014370154c3a341a0e632f50b19/src/asserts/src/index.ts#L199
*/
function ttype (plan, obj, klass) {
function ttype (obj, klass) {
const name =
typeof klass === 'function'
? klass.name || '(anonymous constructor)'
: klass

if (obj === klass) {
return plan.ok(1)
return true
}

const tof = typeof obj
Expand All @@ -31,13 +31,13 @@ function ttype (plan, obj, klass) {
(klass === 'array' && Array.isArray(obj)) ||
(type === 'symbol' && klass === Symbol)
) {
return plan.ok(1)
return true
}

// simplest case, it literally is the same thing
if (type === 'object' && klass !== 'object') {
if (typeof klass === 'function') {
return plan.ok(obj instanceof klass)
return obj instanceof klass
}

// check prototype chain for name
Expand All @@ -47,12 +47,12 @@ function ttype (plan, obj, klass) {
for (let p = obj; p; p = Object.getPrototypeOf(p)) {
const ctor = p.constructor && p.constructor.name
if (p === klass || ctor === name) {
return plan.ok(1)
return true
}
}
}

return plan.strictEqual(type, name)
return type === name
}

module.exports = {
Expand Down

0 comments on commit 60e19c0

Please sign in to comment.