New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

jsdoc-contracts

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsdoc-contracts

latest
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

Simple design by contracts system expressed using jsdoc.

Installation

$ npm install -g jsdoc-contracts

Usage

In your code:

/**
 * Decrement a number by a given amount which defaults to 1
 * 
 * @param {Number} i   Number to be decremented
 * @param {Number} [n] How much to take away from i, defaults to 1
 * @pre i > 0
 * 
 * @returns {Number}
 * @post ##out## > 0
 */
function dec(i, n) {
   n = n || 1;
   return i - n;
}

Would generate:

function dec(i, n) {
    if (!(typeof i === "number")) {
        throw new Error(...);
    } else if (n !== undefined && !(typeof n === "number")) {
        throw new Error(...);
    } else if (!(i > 0)) {
        throw new Error(...);
    } else {
        n = n || 1;
        {
            var ___return = i - n;
            if (!(typeof ___return === "number")) {
                throw new Error(...);
            } else if (!(___return > 0)) {
                throw new Error(...);
            } else {
                return ___return;
            }
        }
    }
}

To do the transformation execute the following after installing

$ contracts <file>
$ contracts <file> > out.js

FAQs

Package last updated on 24 Mar 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts