Browse Source

loose instanceof: check constructor function name instead

hk-custom-address
Wei Lu 10 years ago
parent
commit
eb4e8884d9
  1. 2
      src/types.js
  2. 2
      test/types.js

2
src/types.js

@ -26,7 +26,7 @@ module.exports = function enforce(type, value) {
}
default: {
if (value instanceof type) return
if (value.constructor.toString().match(/function (.*?)\(/)[1] === type.name) return
}
}

2
test/types.js

@ -1,7 +1,7 @@
var assert = require('assert')
var enforceType = require('../src/types')
function CustomType() {}
function CustomType() { return "ensure non-greedy match".toUpperCase() }
var types = ['Array', 'Boolean', 'Buffer', 'Number', 'String', CustomType]
var values = [[], true, new Buffer(1), 1234, 'foobar', new CustomType()]

Loading…
Cancel
Save