
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
basic-functions
Advanced tools
Collection of functions that return specific values (noop, true, false, echo, etc)
A Simple module which contains common functions to save you time, code, and memory
npm install basic-functions
or
npm install -g basic-functions
Then import the module into your program:
var just = require('basic-functions')
An simply reference the stored functions
just.undefined() //undefined
just.null() //null
just.true() //true
//or just.True()
just.false() //false
//or just.False()
just.zero() //0
//or just[0], just['0'], just.Zero
just.one() //1
//or just[1], just['1'], just.One
just.NaN() //NaN
//or just.nan()
just.Infinity() //Infinity
//or just.infinity()
just._Infinity() //-Infinity
//or just._infinity()
just.Array() //[]
//or just.array()
just.Object() //{}
//or just.object()
just.String() //{}
//or just.string()
just.Function() //function(){}
//or just.function()
just.this() //this
//more detailed example of how 'this' can be used
var obj = {},
f = just.this.bind( obj );
f() === obj; //true
Does nothing
var fn = just.noop;
//or just.noOp
fn() //undefined
Returns the result of invoking the first input argument
Functionvar fn = just.call;
//or just.run
function arrFn(){
return ['a','b','c'];
}
fn( arrFn ) //['a','b','c']
Returns the result of invoking the first input argument with args as the arguments
var fn = just.call.with( 5, 10 );
//or just.run.with( 5, 10 )
function add( a, b ){
return a + b;
}
function multiply( a, b ){
return a * b;
}
fn( add ) //15
fn( multiply ) //50
Returns the result of invoking fn with the input arguments as the arguments
var fn = just.call.fn( add );
//or just.run.fn( add )
fn( 5, 10 ) //15
Returns the result of invoking fn with args as the arguments
var fn = just.call.fn( add ).with( 5, 10 );
//or just.run.fn( add ).with( 5, 10 )
fn() //15
fn( 25, 100 ) //15
Returns the result of invoking the first input argument that is a Function
var fn = just.call.firstFn;
//or just.run.firstFn
function numFn(){
return 10;
}
function strFn(){
return 'hi';
}
fn( false, numFn, strFn ) //10
Returns the result of invoking the first input argument that is a Function with args as the arguments
var fn = just.call.firstFn.with( 5, 10 );
//or just.run.firstFn.with( 5, 10 )
fn( [], add, multiply ) //15
Returns the result of invoking the nth input argument
Note: Index starts at 0
var fn = just.call.nth(1);
//or just.run.nth(1)
fn( false, numFn, strFn ) //10
Returns the result of invoking the nth input argument with args as the arguments
var fn = just.call.nth(1).with( 5, 10 );
//or just.run.nth(1).with( 5, 10 )
fn( [], add, multiply ) //15
Returns the result of invoking the nth input argument that is a Function
Note: Index starts at 0
var fn = just.call.nth(1).fn;
//or just.run.nth(1).fn
fn( false, numFn, strFn ) //'hi'
Returns the result of invoking the nth input argument that is a Function with args as the arguments
var fn = just.call.nth(1).fn.with( 5, 10 );
//or just.run.nth(1).fn.with( 5, 10 )
fn( [], add, multiply ) //50
Returns the result of invoking the property key in the first input argument
var numObj = {
fn : numFn
},
strObj = {
fn : strFn
},
fn = just.call.key('fn');
//or just.run.key('fn')
fn( numObj ) //10
fn( strObj ) //'hi'
Returns the result of invoking the property key in the first input argument with args as the arguments
var multObj = {
fn : multiply
},
addObj = {
fn : add
},
fn = just.call.key('fn').with( 5, 10 );
//or just.run.key('fn').with( 5, 10 )
fn( multObj ) //50
fn( addObj ) //15
Returns the result of invoking the property key in this with the input arguments as the arguments
var fn = just.call.key('fn').inThis.bind( addObj );
//or just.run.key('fn').inThis.bind( addObj )
fn( 5, 10 ) //15
Returns the result of invoking the property key in this with args as the arguments
var fn = just.call.key('fn').inThis.with( 5, 10 );
//or just.run.key('fn').inThis.with( 5, 10 ).bind( addObj )
fn() //15
fn( 25, 100 ) //15
Returns the result of invoking the property key in the nth input argument
var fn = just.call.key('fn').inNth(1);
//or just.run.key('fn').inNth(1)
fn( false, numObj, strObj ) //10
Returns the result of invoking the property key in the nth input argument with args as the arguments
var fn = just.call.key('fn').inNth(1).with( 5, 10 );
//or just.run.key('fn').inNth(1).with( 5, 10 )
fn( [], addObj, multObj ) //15
Returns the result of invoking the property key in the nth input argument of type type
var fn = just.call.key('fn').inNth(1).ofType( Object );
//or just.run.key('fn').inNth(1).ofType( Object )
fn( false, numObj, strObj ) //'hi'
Returns the result of invoking the property key in the nth input argument of type type with args as the arguments
//can also use strings for the type
var fn = just.call.key('fn').inNth(1).ofType( 'object' ).with( 5, 10 );
//or just.run.key('fn').inNth(1).ofType( 'object' ).with( 5, 10 )
fn( [], addObj, multObj ) //50
Returns a new instance of the first input argument
Functionvar fn = just.instantiate;
//or just.new
fn( Array ) //[]
Returns a new instance of the first input argument with args as the arguments
var fn = just.instantiate.with( 'abc' );
//or just.new.with( 'abc' )
fn( Array ) //['abc']
Returns a new instance of fn with the input arguments as the arguments
var fn = just.instantiate.fn( Array );
//or just.new.fn( Array )
fn( 5 ) //[5]
Returns a new instance of fn with args as the arguments
var fn = just.instantiate.fn( Array ).with( 5, 10 );
//or just.new.fn( Array ).with( 5, 10 )
fn() //[5, 10]
fn( 25, 100 ) //[5, 10]
Returns a new instance of the first input argument that is a Function
var fn = just.instantiate.firstFn;
//or just.new.firstFn
fn( 100, Array, String ) //[]
Returns a new instance of the first input argument that is a Function with args as the arguments
var fn = just.instantiate.firstFn.with( true );
//or just.new.firstFn.with( true )
fn( 100, Array, String ) //[ true ]
Returns a new instance of the nth input argument
Note: Index starts at 0
var fn = just.instantiate.nth(1);
//or just.new.nth(1)
fn( 100, Array, String ) //[]
Returns a new instance of the nth input argument with args as the arguments
var fn = just.instantiate.nth(1).with( true );
//or just.new.nth(1).with( true )
fn( 100, Array, String ) //[ true ]
Returns a new instance of the nth input argument that is a Function
Note: Index starts at 0
var fn = just.instantiate.nth(1).fn;
//or just.new.nth(1).fn
fn( 100, Array, String ) //''
Returns a new instance of the nth input argument that is a Function with args as the arguments
var fn = just.instantiate.nth(1).fn.with( true );
//or just.new.nth(1).fn.with( true )
fn( 100, Array, String ) //'true'
Returns a new instance of the property key in the first input argument
var arrObj = {
fn : Array
},
strObj = {
fn : String
},
fn = just.instantiate.key('fn');
//or just.new.key('fn')
fn( arrObj ) //[]
fn( strObj ) //''
Returns a new instance of the property key in the first input argument with args as the arguments
var fn = just.instantiate.key('fn').with( true );
//or just.new.key('fn').with( true )
fn( arrObj ) //[ true ]
Returns a new instance of the property key in this with the input arguments as the arguments
var fn = just.instantiate.key('fn').inThis.bind( arrObj );
//or just.new.key('fn').inThis.bind( arrObj )
fn() //[]
fn( 'hi' ) //[ 'hi' ]
Returns a new instance of the property key in this with args as the arguments
var fn = just.instantiate.key('fn').inThis.with( true ).bind( arrObj );
//or just.new.key('fn').inThis.with( true ).bind( arrObj )
fn() //[ true ]
fn( 'hi' ) //[ true ]
Returns a new instance of the property key in the nth input argument
var fn = just.instantiate.key('fn').inNth(1);
//or just.new.key('fn').inNth(1)
fn( 100, arrObj, strObj ) //[]
Returns a new instance of the property key in the nth input argument with args as the arguments
var fn = just.instantiate.key('fn').inNth(1).with( true );
//or just.new.key('fn').inNth(1).with( true )
fn( 100, arrObj, strObj ) //[ true ]
Returns a new instance of the property key in the nth input argument of type type
var fn = just.instantiate.key('fn').inNth(1).ofType( Object );
//or just.new.key('fn').inNth(1).ofType( Object )
fn( 100, arrObj, strObj ) //''
Returns a new instance of the property key in the nth input argument of type type with args as the arguments
var fn = just.instantiate.key('fn').inNth(1).ofType( 'object' ).with( true );
//or just.new.key('fn').inNth(1).ofType( 'object' ).with( true );
fn( 100, arrObj, strObj ) //'true'
Throws the first input argument
var fn = just.throw;
//or just.error
fn( new Error ) //throws Error
Throws fn
var fn = just.throw.error( new TypeError );
//or just.error.error( new TypeError )
fn() //throws TypeError
Throws the first input argument that is an instanceof Error
var fn = just.throw.firstError;
//or just.error.firstError
fn( {}, new Error, new TypeError ) //throws Error
Throws the nth input argument
Note: Index starts at 0
var fn = just.throw.nth(1);
//or just.error.nth(1)
fn( {}, new Error, new TypeError ) //throws Error
Throws the nth input argument that is an instanceof Error
Note: Index starts at 0
var fn = just.throw.nth(1).error;
//or just.error.nth(1).error
fn( {}, new Error, new TypeError ) //throws TypeError
Throws the property key in the first input argument
var errObj = {
err : new Error
},
typeErrObj = {
err : new TypeError
},
fn = just.throw.key('err');
//or just.error.key('err')
fn( errObj ) //throws Error
fn( typeErrObj ) //throws TypeError
Throws the property key in this
var fn = just.throw.key('err').inThis.bind( errObj );
//or just.error.key('err').inThis.bind( errObj )
fn() //throws Error
Throws the property key in the nth input argument
var fn = just.throw.key('err').inNth(1);
//or just.error.key('err').inNth(1)
fn( 'hi', errObj, typeErrObj ) //throws Error
Throws the property key in the nth input argument of type type
var fn = just.throw.key('err').inNth(1).ofType( Object );
//or just.error.key('err').inNth(1).ofType( Object )
fn( 'hi', errObj, typeErrObj ) //throws TypeError
Returns the first input argument
var fn = just.echo;
//or just.return
fn( 10 ) //10
Returns v
var fn = just.echo.value( 10 );
//or just.return.value( 10 )
fn() //10
fn( true ) //10
Returns the nth input argument
Note: Index starts at 0
var fn = just.echo.nth(1);
//or just.return.nth(1)
fn( 'hi', 100, 'there' ) //100
Returns the nth input argument of type type
Note: Index starts at 0
var fn = just.echo.nth(1).ofType('string');
//or just.return.nth(1).ofType('string')
fn( 'hi', 100, 'there' ) //'there'
Returns the property key in the first input argument
var obj = {
str : 'hi',
num : 100
},
fn = just.echo.key('str');
//or just.return.key('str')
fn( obj ) //'hi'
Returns the property key in this
var fn = just.echo.key('str').inThis.bind( obj );
//or just.return.key('str').inThis.bind( obj )
fn() //'hi'
Returns the property key in the nth input argument
var fn = just.echo.key('num').inNth(1);
//or just.return.key('num').inNth(1)
fn( 'hi', obj ) //100
Returns the property key in the nth input argument of type type
var fn = just.echo.key('str').inNth(1).ofType( Object );
//or just.return.key('str').inNth(1).ofType( Object )
fn( 'hi', {}, obj ) //'hi'
FAQs
Collection of functions that return specific values (noop, true, false, echo, etc)
We found that basic-functions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.