Comparing version 1.1.0 to 1.2.0
export { default as generators } from './src/generators'; | ||
export { default as getters } from './src/getters'; | ||
export { default as doo } from './src/doo'; | ||
export { | ||
@@ -4,0 +6,0 @@ isUn, |
{ | ||
"name": "aleppo", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "General node functions, useful for any project.", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "mocha --compilers js:babel-core/register test" | ||
"test": "mocha --compilers js:babel-core/register --require babel-polyfill test" | ||
}, | ||
@@ -42,5 +42,7 @@ "repository": { | ||
"babel-core": "6.24.1", | ||
"babel-polyfill": "6.23.0", | ||
"babel-preset-es2015": "6.24.1", | ||
"chai": "3.5.0", | ||
"chai-as-promised": "6.0.0", | ||
"chai-iterator": "1.1.4", | ||
"eslint": "3.19.0", | ||
@@ -47,0 +49,0 @@ "eslint-config-airbnb-base": "11.1.3", |
@@ -25,28 +25,51 @@ # Overview | ||
```javascript | ||
isUn(input) //tests for undefined. | ||
isNull(input) //tests for null. | ||
isValid(input) //tests for not being undefined or null. | ||
isObj(input) //tests for object. | ||
isBool(input) //tests for Boolean. | ||
isNum(input) //tests for number. | ||
isStr(input) //tests for string. | ||
isFn(input) //tests for function. | ||
isSymb(input) //tests for symbol. | ||
isArr(input) //tests for array. | ||
isZeroLength(input) //tests for zero length. | ||
isStrEmpty(input) //tests if string is empty. | ||
isArrEmpty(input) //tests if array is empty.. | ||
isUn(...inputs) //tests for undefineds. | ||
isNull(...inputs) //tests for nulls. | ||
isValid(...inputs) //tests for not being undefineds or nulls. | ||
isObj(...inputs) //tests for objects. | ||
isBool(...inputs) //tests for Booleans. | ||
isNum(...inputs) //tests for numbers. | ||
isStr(...inputs) //tests for strings. | ||
isFn(...inputs) //tests for functions. | ||
isSymb(...inputs) //tests for symbols. | ||
isArr(...inputs) //tests for arrays. | ||
isZeroLength(...inputs) //tests for zero length. | ||
isStrEmpty(...inputs) //tests if strings are empty. | ||
isArrEmpty(...inputs) //tests if arrays are empty. | ||
``` | ||
* IS-functions can deal with one argument or multiple arguments. | ||
example: | ||
```javascript | ||
isZeroLength('hi', 'test', 'i am here'); // returns false. | ||
isNum(1,2,4,5,7,8,1000); // returns true. | ||
``` | ||
# doo: resolve multiple arguments with multiple functions in one call. | ||
```javascript | ||
import doo from 'aleppo' | ||
doo.iterator([...funcs],[...args]) //returns iterator object of results. | ||
doo.array([...funcs],[...args]) //returns array of results. | ||
doo.object([...funcs],[...args]) //returns array of objects [{func: 'Function name', result: 'result of the function'}] | ||
``` | ||
# Generators: | ||
```javascript | ||
import generators from 'aleppo' | ||
``` | ||
1. **Numbers**: | ||
```javascript | ||
const numbers = generators.numbers; | ||
const numbers = generators.numbers | ||
numbers.getRandom(min, max, type) //returns random number in given range. | ||
// type: is string. By default will apply for integer random number. for arbitrary value just pass 'any'. | ||
``` | ||
* full credit for this function goes to | ||
[Ionuț G. Stan](https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range). | ||
# Getters: | ||
```javascript | ||
import getters from 'aleppo' | ||
``` | ||
@@ -59,2 +82,4 @@ 1. **object**: | ||
``` | ||
2. **delay**: | ||
@@ -71,3 +96,3 @@ ```javascript | ||
* ```w/week/weeks```: returns delay in weeks. | ||
* ```mo/mos/months``` : returns delay in months. | ||
* ```mo/mos/month/months``` : returns delay in months. | ||
* ```m/minute/minutes```: returns delay in minutes. | ||
@@ -79,6 +104,9 @@ * ```s/second/seconds``` : returns delay in seconds. | ||
```javascript | ||
wait(option).then(() => console.log('Hello!')) // returns promise. | ||
import wait from 'aleppo' | ||
wait(option) // returns promise. | ||
// wait('20s').then(() => console.log('Hello!')); // 'Hello! will be printed after 20 seconds' | ||
``` | ||
* options allowed in wait are the same in delay function. | ||
* options allowed in wait are the same in delay function. | ||
* full credit for this function goes to | ||
[Eric Elliott](https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-promise-27fc71e77261). | ||
@@ -85,0 +113,0 @@ # Tests |
@@ -1,2 +0,1 @@ | ||
// credit to: https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range\ | ||
@@ -3,0 +2,0 @@ // verfying parameters should be before calling this func. |
@@ -1,22 +0,30 @@ | ||
// returns true for valid typeof | ||
// multiple arguments | ||
// typeof functions | ||
const isUn = candidate => typeof candidate === 'undefined'; | ||
const isNull = candidate => candidate === null; | ||
const isValid = candidate => !isUn(candidate) && !isNull(candidate); | ||
const isObj = candidate => typeof candidate === 'object'; | ||
const isBool = candidate => typeof candidate === 'boolean'; | ||
const isNum = candidate => typeof candidate === 'number'; | ||
const isStr = candidate => typeof candidate === 'string'; | ||
const isFn = candidate => typeof candidate === 'function'; | ||
const isSymb = candidate => typeof candidate === 'symbol'; | ||
import oneArg from './oneArg'; | ||
import doo from '../doo'; | ||
// typeof functions for multiples args// | ||
const isUn = (...candidates) => !(doo.array([oneArg.isUn], [...candidates]).includes(false)); | ||
const isNull = (...candidates) => !(doo.array([oneArg.isNull], [...candidates]).includes(false)); | ||
const isValid = (...candidates) => !(doo.array([oneArg.isValid], [...candidates]).includes(false)); | ||
const isObj = (...candidates) => !(doo.array([oneArg.isObj], [...candidates]).includes(false)); | ||
const isBool = (...candidates) => !(doo.array([oneArg.isBool], [...candidates]).includes(false)); | ||
const isNum = (...candidates) => !(doo.array([oneArg.isNum], [...candidates]).includes(false)); | ||
const isStr = (...candidates) => !(doo.array([oneArg.isStr], [...candidates]).includes(false)); | ||
const isFn = (...candidates) => !(doo.array([oneArg.isFn], [...candidates]).includes(false)); | ||
const isSymb = (...candidates) => !(doo.array([oneArg.isSymb], [...candidates]).includes(false)); | ||
// mixed | ||
const isArr = candidate => Array.isArray(candidate); | ||
const isZeroLength = candidate => candidate.length === 0; | ||
const isArr = (...candidates) => | ||
!(doo.array([oneArg.isArr], [...candidates]).includes(false)); | ||
const isStrEmpty = str => isUn(str) || isNull(str) || isZeroLength(str.trim()); | ||
const isArrEmpty = array => isArr(array) && isZeroLength(array); | ||
const isZeroLength = (...candidates) => | ||
!(doo.array([oneArg.isZeroLength], [...candidates]).includes(false)); | ||
const isStrEmpty = (...candidates) => | ||
!(doo.array([isValid, isStr, isZeroLength], [...candidates]).includes(false)); | ||
const isArrEmpty = (...candidates) => isArr(...candidates) && isZeroLength(...candidates); | ||
export { | ||
@@ -23,0 +31,0 @@ isUn, |
@@ -22,32 +22,66 @@ /* eslint-env mocha */ | ||
describe('is', () => { | ||
describe('should return true', () => { | ||
it('1-tests undefined as undefined', () => expect(isUn(undefined)).to.be.true); | ||
it('2-tests null as null', () => expect(isNull(null)).to.be.true); | ||
it('3-tests "welcome" as valid', () => expect(isValid('welcome')).to.be.true); | ||
it('4-tests {boo : foo} as object', () => expect(isObj({ boo: 'foo' })).to.be.true); | ||
it('5-tests true as boolean', () => expect(isBool(true)).to.be.true); | ||
it('6-tests 3 as number', () => expect(isNum(3)).to.be.true); | ||
it('7-tests hello as string', () => expect(isStr('hello')).to.be.true); | ||
it('8-tests ()=> 4 as function', () => expect(isFn(() => 4)).to.be.true); | ||
it('9-tests [10, 6, 8] as array', () => expect(isArr([10, 6, 8])).to.be.true); | ||
it('10-tests "" as zero length', () => expect(isZeroLength('')).to.be.true); | ||
it('11-tests " " as empty string', () => expect(isStrEmpty(' ')).to.be.true); | ||
it('12-tests [] empty array', () => expect(isArrEmpty([])).to.be.true); | ||
describe('multiple arguments', () => { | ||
describe('should return true', () => { | ||
it('1-tests undefined as undefined', () => expect(isUn(undefined, undefined, undefined)).to.be.true); | ||
it('2-tests null,null as null', () => expect(isNull(null, null)).to.be.true); | ||
it('3-tests "welcome", "to", "club" as valid', () => expect(isValid('welcome', 'to', 'club')).to.be.true); | ||
it('4-tests {boo : foo}, { baz: doo } as object', () => expect(isObj({ boo: 'foo' }, { baz: 'doo' })).to.be.true); | ||
it('5-tests true, false as boolean', () => expect(isBool(true, false)).to.be.true); | ||
it('6-tests 3,7,8,9,10 as number', () => expect(isNum(3, 7, 8, 9, 10)).to.be.true); | ||
it('7-tests hello, bye as string', () => expect(isStr('hello', 'bye')).to.be.true); | ||
it('8-tests ()=> 4 , ()=> "hello" as function', () => expect(isFn(() => 4, () => 'hello')).to.be.true); | ||
it('9-tests [10, 6, 8], ["a", "b", "c"] as array', () => expect(isArr([10, 6, 8], ['a', 'b', 'c'])).to.be.true); | ||
it('10-tests "","","","" as zero length', () => expect(isZeroLength('', '', '', '')).to.be.true); | ||
it('11-tests "","","","" as empty string', () => expect(isStrEmpty('', '', '', '', '')).to.be.true); | ||
it('12-tests [], [],[] empty array', () => expect(isArrEmpty([], [], [])).to.be.true); | ||
}); | ||
describe('should return false', () => { | ||
it('1-tests 3, 3, undefined as undefined', () => expect(isUn(3, 3, undefined)).to.be.false); | ||
it('2-tests hello, world as null', () => expect(isNull('hello', 'world')).to.be.false); | ||
it('3-tests null,8 as valid', () => expect(isValid(null, 8)).to.be.false); | ||
it('4-tests undefined, 78 as valid', () => expect(isValid(undefined, 78)).to.be.false); | ||
it('5-tests ()=> 4, { num: 1 } as object', () => expect(isObj(() => 4, { num: 1 })).to.be.false); | ||
it('6-tests null,true as boolean', () => expect(isBool(null, true)).to.be.false); | ||
it('7-tests hello, 3 as number', () => expect(isNum('hello', 3)).to.be.false); | ||
it('8-tests 3,5,6,"yes" as string', () => expect(isStr(3, 5, 6, 'yes')).to.be.false); | ||
it('9-tests {boo : foo} as function', () => expect(isFn({ boo: 'foo' })).to.be.false); | ||
it('10-tests {foo: 123} as array', () => expect(isArr({ foo: 123 })).to.be.false); | ||
it('11-tests "what?" as zero length', () => expect(isZeroLength('what?')).to.be.false); | ||
it('12-tests "hell0" as empty string', () => expect(isStrEmpty('hell')).to.be.false); | ||
it('13-tests [5] empty array', () => expect(isArrEmpty([5])).to.be.false); | ||
}); | ||
}); | ||
describe('should return false', () => { | ||
it('1-tests 3 as undefined', () => expect(isUn(3)).to.be.false); | ||
it('2-tests hello as null', () => expect(isNull('hello')).to.be.false); | ||
it('3-tests null as valid', () => expect(isValid(null)).to.be.false); | ||
it('4-tests undefined as valid', () => expect(isValid(undefined)).to.be.false); | ||
it('5-tests ()=> 4 as object', () => expect(isObj(() => 4)).to.be.false); | ||
it('6-tests null as boolean', () => expect(isBool(null)).to.be.false); | ||
it('7-tests hello 3 as number', () => expect(isNum('hello')).to.be.false); | ||
it('8-tests 3 as string', () => expect(isStr(3)).to.be.false); | ||
it('9-tests {boo : foo} as function', () => expect(isFn({ boo: 'foo' })).to.be.false); | ||
it('10-tests {foo: 123} as array', () => expect(isArr({ foo: 123 })).to.be.false); | ||
it('11-tests "what?" as zero length', () => expect(isZeroLength('what?')).to.be.false); | ||
it('12-tests "hell0" as empty string', () => expect(isStrEmpty('hell')).to.be.false); | ||
it('13-tests [5] empty array', () => expect(isArrEmpty([5])).to.be.false); | ||
describe('single argument', () => { | ||
describe('should return true', () => { | ||
it('1-tests undefined as undefined', () => expect(isUn(undefined, undefined, undefined)).to.be.true); | ||
it('2-tests null as null', () => expect(isNull(null, null, null)).to.be.true); | ||
it('3-tests "welcome" as valid', () => expect(isValid('welcome')).to.be.true); | ||
it('4-tests {boo : foo} as object', () => expect(isObj({ boo: 'foo' })).to.be.true); | ||
it('5-tests true as boolean', () => expect(isBool(true)).to.be.true); | ||
it('6-tests 3 as number', () => expect(isNum(3)).to.be.true); | ||
it('7-tests hello as string', () => expect(isStr('hello')).to.be.true); | ||
it('8-tests ()=> 4 as function', () => expect(isFn(() => 4)).to.be.true); | ||
it('9-tests [10, 6, 8] as array', () => expect(isArr([10, 6, 8])).to.be.true); | ||
it('10-tests "" as zero length', () => expect(isZeroLength('')).to.be.true); | ||
it('11-tests "" as empty string', () => expect(isStrEmpty('')).to.be.true); | ||
it('12-tests [] empty array', () => expect(isArrEmpty([])).to.be.true); | ||
}); | ||
describe('should return false', () => { | ||
it('1-tests 3 as undefined', () => expect(isUn(3)).to.be.false); | ||
it('2-tests hello as null', () => expect(isNull('hello')).to.be.false); | ||
it('3-tests null as valid', () => expect(isValid(null)).to.be.false); | ||
it('4-tests undefined as valid', () => expect(isValid(undefined)).to.be.false); | ||
it('5-tests ()=> 4 as object', () => expect(isObj(() => 4)).to.be.false); | ||
it('6-tests null as boolean', () => expect(isBool(null)).to.be.false); | ||
it('7-tests hello 3 as number', () => expect(isNum('hello')).to.be.false); | ||
it('8-tests 3 as string', () => expect(isStr(3)).to.be.false); | ||
it('9-tests {boo : foo} as function', () => expect(isFn({ boo: 'foo' })).to.be.false); | ||
it('10-tests {foo: 123} as array', () => expect(isArr({ foo: 123 })).to.be.false); | ||
it('11-tests "what?" as zero length', () => expect(isZeroLength('what?')).to.be.false); | ||
it('12-tests "hell0" as empty string', () => expect(isStrEmpty('hell')).to.be.false); | ||
it('13-tests [5] empty array', () => expect(isArrEmpty([5])).to.be.false); | ||
}); | ||
}); | ||
}); |
25061
32
526
118
11