Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

interface

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interface - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

21

index.js

@@ -15,7 +15,7 @@ function createInterface () {

functionNames.forEach(function (functionName) {
if (typeof prototype[functionName] !== 'function') {
unimplemented.push(functionName)
for (var i = 0; i < functionNames.length; i++) {
if (typeof prototype[functionNames[i]] !== 'function') {
unimplemented.push(functionNames[i])
}
})
}

@@ -30,14 +30,15 @@ // throw error if there are unimplemented functions

// expose valiate function
// expose validate function
Interface.isImplementedBy = function (object) {
var prototype = Object.getPrototypeOf(object)
var valid = true
var length = functionNames.length
while (length--) {
if (typeof prototype[functionNames[length]] !== 'function') {
return false
for (var i = 0; i < functionNames.length; i++) {
if (typeof prototype[functionNames[i]] !== 'function') {
valid = false
break
}
}
return true
return valid
}

@@ -44,0 +45,0 @@

{
"name": "interface",
"version": "1.2.0",
"version": "1.2.1",
"description": "Enforce an interface on classes",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -44,3 +44,3 @@ # Interface-js

```js
let instance = new MyClass()
const instance = new MyClass()
// throws a new error with the message:

@@ -63,3 +63,3 @@ // 'The following function(s) need to be implemented for class MyClass: myMethodB'

let instance = new MySubClass()
const instance = new MySubClass()
// still throws an error with the message:

@@ -74,3 +74,3 @@ // 'The following function(s) need to be implemented for class MyClass: myMethodB'

var MyInterface = new Interface('myMethodA', 'myMethodB', 'myMethodC')
const MyInterface = new Interface('myMethodA', 'myMethodB', 'myMethodC')

@@ -102,1 +102,26 @@ function MyClass () {

```
You can also enforce that arbitrary objects match an interface by using
the `isImplementedBy` method.
```js
const MyInterface = new Interface('myMethod')
class MyClass {
myMethod () {
// some implementation
}
}
class MyOtherClass {
myOtherMethod () {
// some implementation
}
}
const instanceA = new MyClass()
const instanceB = new MyOtherClass()
MyInterface.isImplementedBy(instanceA) // returns true
MyInterface.isImplementedBy(instanceB) // returns false
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc