Skip to content

A πŸŽ‰πŸŽ‰Type Definition Wrapper πŸŽ‰ πŸŽ‰ for Javascript that enforces types during runtime.

License

Notifications You must be signed in to change notification settings

RobusGauli/typemyjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TYPE MY JS

A type enforcer for javascript. It can be used to provide a runtime type checking of the attributes and function parameters.

import Types, { wrapWithType } from 'typemyjs'

const AreaType = {
  length: Types.NumberType({
      range: [0, 100]
      }),
  width: Types.NumberType(),
  calculateArea: Types.FunctionType({
    requiredAttributes: {
      length: a => a,
      width: a => a,
      }})
}

class Area {
  constructor(length, breadth) {
    this.length = length;
    this.breadth = breadth;
  }
  calculateArea() {
    return this.length * this.breadth;
  }
}

Area = wrapWithType(AreaType)(Area);

// voila

Documentation coming sooon.

Under Development

About

A πŸŽ‰πŸŽ‰Type Definition Wrapper πŸŽ‰ πŸŽ‰ for Javascript that enforces types during runtime.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages