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

dfn

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dfn

Dynamic Function Definition, using map pattern guard something.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

dfn

Dynamic Function Definition, using map pattern guard something.

Build Status Coverage Status

install

npm i dfn --save

example

var dfn = require('dfn');
var defFun = dfn.defFun;
var special = dfn.special;
var guard = dfn.guard;

var fun = defFun();
special(fun, [1, 2], 5);
guard(fun, (x) => x < 0, (x) => -1 * x);

console.log(fun(1, 2)); // 5
console.log(fun(-3)); // 3

create a function

var dfn = require('dfn');
var defFun = dfn.defFun;
var fun = defFun();

special case

You can set a special case for a function.

  • special(fun, args, ret)
var dfn = require('dfn');
var defFun = dfn.defFun;
var special = dfn.special;
var fun = defFun();

special(fun, [1, 2], 5);

console.log(fun(1, 2)); // 5

guard

You can set a guard for function

  • guard(fun, condition, expression)

When arguments satisfy condition (a function), function fun will get result from expression (a function).

var dfn = require('dfn');
var defFun = dfn.defFun;
var guard = dfn.guard;

var fun = defFun();
guard(fun, (x) => x < 0, (x) => -1 * x);

console.log(fun(-3)); // 3

default

You can set default expression for function.

When there is no special case or condition, default function will execute.

def(fun, defFun)

var dfn = require('dfn');

var fun = defFun();
guard(fun, (x) => x < 0, (x) => -1 * x);
def(fun, (x) => x * x);

console.log(fun(3)); // 9

Keywords

function

FAQs

Package last updated on 23 May 2016

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