function-x

1.0.1 • Public • Published

function-x.js

Extensions to JavaScript Function type

API

// Wraps the target function in an argument types checking function
// The argsTypeInfo variadic argument specifies expected types of the arguments, respectively by position. 
// Where an argument can have multiple types, the corresponding argsTypeInfo element is an array of the allowed types
// Use 'any' for an argument that can be of any type
function expecting(...argsTypeInfo)

// Wraps the target function in an return value type checking function
// The typeNames variadic argument specifies allowed types of the return value.
function returning(...typeNames)

Example

require ("function-x");

var fx = function(str, num){
	return Array(num).join(str);
}.expecting("string", "number");

console.log(fx("hello ", 2)); // prints "hello"
console.log(fx(1, 2)); // throws error since first argument should be string instead of number

Readme

Keywords

none

Package Sidebar

Install

npm i function-x

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • prmph