JavaScript Code Contract Libraries?

后端 未结 4 789
花落未央
花落未央 2021-02-01 08:11

I am just starting up a new web application and I want to implement some form of contract\'esque style validation in my JavaScript. I did some quick googling, and came across Js

4条回答
  •  深忆病人
    2021-02-01 08:56

    I also have thrown together my idea of type contracts, which does what I want. A little late, I think, but I'll recommend it nevertheless for people willing to look at it: https://github.com/lindem/FirstContract

    It's a WIP, but I needed something like it.

    function bmi (weight, height) {
        return weight / height * height;
    }
    
    var c = require("firstcontract").c
        /* 
         * contract applies to function taking two non-negative numbers,
         * returning a negative number: 
         */
        , contract = c(["R+0", "R+0"], "R+0")
        , cbmi = contract(bmi)
        ;
    

    it was created so that I can add and remove it without changing the function monitored itself and provides just a clamp around the function. It's commonjs and on npm.

提交回复
热议问题