Skip to content

Commit

Permalink
✨ Add B.join, B.isNil, B.instanceOf
Browse files Browse the repository at this point in the history
  • Loading branch information
KsRyY committed Jan 28, 2020
1 parent 1d64a8c commit def5cbd
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/helpers/isEmpty.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import every from './every'
import F from './F'
import functionalIf from './functionalIf'
import functionalSwitch from './functionalSwitch'
import instanceOf from './instanceOf'
import isNil from './isNil'
import join from './join'
import multiply from './multiply'
import not from './not'
import nth from './nth'
Expand All @@ -34,6 +37,9 @@ export {
every,
functionalIf,
functionalSwitch,
instanceOf,
isNil,
join,
multiply,
not,
nth,
Expand Down
25 changes: 25 additions & 0 deletions src/instanceOf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Test if the the second argument is an instance of the first argument. (curried)
* ```js
* instanceOf(Number)(new Number(1)) //=> true
* instanceOf(Number)(1) //=> false
* ```
*/
function instanceOf(a: any): (b: any) => boolean
/**
* Test if the the second argument is an instance of the first argument.
* ```js
* instanceOf(Number, new Number(1)) //=> true
* instanceOf(Number, 1) //=> false
* ```
*/
function instanceOf(a: any, b: any): boolean
function instanceOf(a: any, b?: any): boolean | ((b: any) => boolean) {
if (typeof b !== 'undefined') {
return b instanceof a
}

return b => instanceOf(a, b)
}

export default instanceOf
14 changes: 14 additions & 0 deletions src/isNil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Test if a value is `null` or `undefined`
* ```js
* isEmpty(null) //=> true
* isEmpty(undefined) //=> true
* isEmpty(0) //=> false
* isEmpty(false) //=> false
* isEmpty(1) //=> false
* ```
*/
const isEmpty = (operand: any): boolean =>
operand === null || operand === undefined

export default isEmpty
35 changes: 35 additions & 0 deletions src/join.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Test if the the second argument is an instance of the first argument. (curried)
* ```js
* instanceOf(Number)(new Number(1)) //=> true
* instanceOf(Number)(1) //=> false
* ```
*/
function join(list: Array<number | string>): (seperator: string) => string
/**
* Test if the the second argument is an instance of the first argument.
* ```js
* instanceOf(Number, new Number(1)) //=> true
* instanceOf(Number, 1) //=> false
* ```
*/
function join(list: Array<number | string>, seperator: string): string
function join(
list: Array<number | string>,
seperator?: string
): string | ((seperator: string) => string) {
if (typeof seperator !== undefined) {
let result = ''

// eslint-disable-next-line unicorn/no-for-loop, @typescript-eslint/prefer-for-of
for (let i = 0; i < list.length; i++) {
result += `${list[i]}${seperator as string}`
}

return result.slice(0, -1)
}

return seperator => join(list, seperator)
}

export default join

0 comments on commit def5cbd

Please sign in to comment.