Comparing version 1.1.1 to 1.2.0
15
index.js
@@ -12,3 +12,2 @@ function createInterface () { | ||
} else { | ||
// assert that each of the functions are defined on the prototype | ||
var prototype = Object.getPrototypeOf(this) | ||
@@ -31,2 +30,16 @@ var unimplemented = [] | ||
// expose valiate function | ||
Interface.isImplementedBy = function (object) { | ||
var prototype = Object.getPrototypeOf(object) | ||
var length = functionNames.length | ||
while (length--) { | ||
if (typeof prototype[functionNames[length]] !== 'function') { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
return Interface | ||
@@ -33,0 +46,0 @@ } |
{ | ||
"name": "interface", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Enforce an interface on classes", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"coveralls": "^2.11.16", | ||
"eslint": "^3.15.0", | ||
"eslint": "^4.3.0", | ||
"eslint-config-standard": "^6.2.1", | ||
@@ -19,2 +19,3 @@ "eslint-plugin-promise": "^3.4.2", | ||
"scripts": { | ||
"pretest": "npm run lint", | ||
"test": "nyc --reporter=lcov mocha", | ||
@@ -21,0 +22,0 @@ "lint": "eslint .", |
@@ -83,3 +83,2 @@ var expect = require('chai').expect | ||
function MySubSubClass () { | ||
@@ -117,2 +116,22 @@ MyClass.call(this) | ||
}) | ||
describe('validate implementation without being a child of interface', function () { | ||
var MyInterface = new Interface('methodA') | ||
it('should return false for bad child', function () { | ||
class BadChild {} | ||
expect(MyInterface.isImplementedBy(new BadChild())).to.be.false | ||
}) | ||
it('should return true for good child', function () { | ||
class GoodChild extends MyInterface { | ||
methodA () { | ||
return true | ||
} | ||
} | ||
expect(MyInterface.isImplementedBy(new GoodChild())).to.be.true | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8573
9
152