1.1.31 • Published 5 years ago
@greedyenders/interface v1.1.31
Interfaces in JS
My attempt to invent TypeScript - like Interfaces in commonJS.
Those can be applied to objects to get a type - stable Proxy version.
TBD:
- Get type stability on arrays to work
Add interfaces for functions
I.E. Check types on function parameters and it's return value
Usage expample :
var interf = new Interface ({
a1: Number,
a2: 42,
a3: String,
a4: '',
a5: 'str',
a6: Object,
a7: Array,
a8: [String, Number],
a9: ['str', 42],
a10: [Function],
a11: Function,
a12: NaN,
a13: null,
a14: Symbol,
'a15_': 'Not required'
})
var obj = {
a1: 1,
a2: 42,
a3: 'string',
a4: '',
a5: 'str',
a6: {a:1, b:''},
a7: [1,2,3],
a8: '',
a9: 42,
a10: [()=>{},()=>{},()=>{}],
a11: ()=>{},
a12: NaN,
a13: null,
a14: Symbol()
}
interf.isImplementedBy(obj) // true
interf.applyTo(obj) // Proxy