0.0.6 • Published 4 years ago
demi-empty v0.0.6
demi-empty
This utility provides different types of empty objects, especially functions with expected result that are repeatedly duplicated in many projects.
The idea is taken from a small utility empty.
Installation
npm install demi-empty
Usage
import empty from 'demi-empty';
Docs
array
An empty array.
empty.array;
// []
func
An empty function that returns nothing (undefined
).
empty.func();
// undefined
funcReturnsArg
A function that returns the first argument.
empty.funcReturnsArg(2);
// 2
empty.funcReturnsArg(1, 2, 3);
// 1
funcReturnsArgs
A function that returns arguments as an array.
empty.funcReturnsArgs();
// []
empty.funcReturnsArgs('a');
// ["a"]
empty.funcReturnsArgs(1, true, 'a');
// [1, true, "a"]
funcReturnsFalse
A function that returns false
.
empty.funcReturnsFalse();
// false
empty.funcReturnsFalse('a');
// false
empty.funcReturnsFalse(true);
// false
funcReturnsNull
A function that returns null
.
empty.funcReturnsNull();
// null
empty.funcReturnsNull('a');
// null
empty.funcReturnsNull(true);
// null
funcReturnsPromiseOfNull
A function that returns a promise of null
.
empty.funcReturnsPromiseOfNull().then(data => console.log(data));
// null
empty.funcReturnsPromiseOfNull('a').then(data => console.log(data));
// null
empty.funcReturnsPromiseOfNull(true).then(data => console.log(data));
// null
funcReturnsThis
A function that returns this
.
const obj = { a: 1, b: 2 };
empty.funcReturnsThis.call(obj);
// {a: 1, b: 2}
funcReturnsTrue
A function that returns true
.
empty.funcReturnsTrue();
// true
empty.funcReturnsTrue('a');
// true
empty.funcReturnsTrue(false);
// true
object
An empty object.
empty.object;
// {}
promiseOfNull
A promise of null
.
empty.promiseOfNull.then(data => console.log(data));
// null