-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
3,849 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# [1.0.0](https://github.com/boostbrothers/ifify/compare/v0.0.3...v1.0.0) (2022-06-16) | ||
|
||
|
||
### Features | ||
|
||
* instanceof 함수들 추가 ([c2243e3](https://github.com/boostbrothers/ifify/commit/c2243e37448b2b4fa7931800cbbaf2d663d82edf)) | ||
* 마지막 인자를 커리로 받는 fp 모음을 분리 ([c3b9cf5](https://github.com/boostbrothers/ifify/commit/c3b9cf5f1545cfbce155df479e431b199bc420be)) | ||
|
||
|
||
### BREAKING CHANGES | ||
|
||
* 마지막 인자를 받는 함수들의 경로가 수정 됨 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {Promisable} from './type'; | ||
import execIfExists from './fp/exec-if-exists'; | ||
|
||
export default <T>(fn: (value: T) => Promisable<T>, value: T) => { | ||
return execIfExists(fn)(value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import {ClassType, Promisable} from './type'; | ||
import execIfIsInstanceof from './fp/exec-if-is-instanceof'; | ||
|
||
export default <T>( | ||
typeofClass: ClassType, | ||
fn: (instance: T) => Promisable<T>, | ||
instance: T | ||
) => { | ||
return execIfIsInstanceof(typeofClass, fn)(instance); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {Promisable} from './type'; | ||
import execIf from './fp/exec-if-is-nil'; | ||
|
||
export default <T>(fn: () => Promisable<T>, value: T | null | undefined) => { | ||
return execIf(fn)(value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {Promisable} from './type'; | ||
import execIfIs from './fp/exec-if-is'; | ||
|
||
export default <T>(other: unknown, fn: (v: T) => Promisable<T>, value: T) => { | ||
return execIfIs(other, fn)(value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {Predicate, Promisable} from './type'; | ||
import execIf from './fp/exec-if'; | ||
|
||
export default <T>( | ||
predicate: Predicate<T>, | ||
fn: (v: T) => Promisable<T>, | ||
value: T | ||
) => { | ||
return execIf(predicate, fn)(value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {Promisable} from '../type'; | ||
|
||
export default <T>(fn: (value: T) => Promisable<T>) => | ||
(value: T) => { | ||
if (value === null) { | ||
return null; | ||
} else if (value === undefined) { | ||
return undefined; | ||
} | ||
|
||
return fn(value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import {ClassType, Promisable} from '../type'; | ||
import execIf from './exec-if'; | ||
|
||
export default <T>( | ||
typeofClass: ClassType, | ||
fn: (instance: T) => Promisable<T> | ||
) => execIf(instance => instance instanceof typeofClass, fn); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Promisable} from '../type'; | ||
|
||
export default <T>(fn: () => Promisable<T>) => | ||
(value: T | null | undefined) => { | ||
// eslint-disable-next-line eqeqeq | ||
if (value == null) { | ||
return fn(); | ||
} | ||
|
||
return value; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {Promisable} from '../type'; | ||
import execIf from './exec-if'; | ||
|
||
export default <T>(other: unknown, fn: (v: T) => Promisable<T>) => | ||
execIf(v => v === other, fn); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {Predicate, Promisable} from '../type'; | ||
|
||
export default <T>(predicate: Predicate<T>, fn: (v: T) => Promisable<T>) => | ||
(value: T) => { | ||
if (predicate(value)) { | ||
return fn(value); | ||
} | ||
|
||
return value; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export {default as execIfExists} from './exec-if-exists'; | ||
export {default as execIfIsInstanceOf} from './exec-if-is-instanceof'; | ||
export {default as execIfIsNil} from './exec-if-is-nil'; | ||
export {default as execIfIs} from './exec-if-is'; | ||
export {default as execIf} from './exec-if'; | ||
export {default as throwIfExists} from './throw-if-exists'; | ||
export {default as throwIfIsInstanceOf} from './throw-if-is-instanceof'; | ||
export {default as throwIfIsNil} from './throw-if-is-nil'; | ||
export {default as throwIfIs} from './throw-if-is'; | ||
export {default as throwIf} from './throw-if'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default <V>(err: Error) => | ||
(value: V | null | undefined): null | undefined => { | ||
if (value === null) { | ||
return null; | ||
} else if (value === undefined) { | ||
return undefined; | ||
} | ||
|
||
throw err; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {ClassType} from '../type'; | ||
|
||
export default <T>(typeOfClass: ClassType, err: Error) => | ||
(instance: T): T => { | ||
if (instance instanceof typeOfClass) { | ||
throw err; | ||
} | ||
|
||
return instance; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default <T>(err: Error) => { | ||
return (value: T | null | undefined): T => { | ||
// eslint-disable-next-line eqeqeq | ||
if (value == null) { | ||
throw err; | ||
} | ||
|
||
return value; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import throwIf from './throw-if'; | ||
|
||
/** | ||
* | ||
* @param other The other value to compare. | ||
* @param err Error message | ||
* @param value The value to compare. | ||
*/ | ||
export default <T>(other: unknown, err: Error) => { | ||
return throwIf<T>(v => v === other, err); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {Predicate, Returns} from '../type'; | ||
|
||
export default <T>(predicate: Predicate<T>, err: Error): Returns<T> => | ||
(value: T): T => { | ||
if (predicate(value)) { | ||
throw err; | ||
} | ||
|
||
return value; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export {default as execIfExists} from './exec-if-exists'; | ||
export {default as execIfIsInstanceOf} from './exec-if-is-instanceof'; | ||
export {default as execIfIsNil} from './exec-if-is-nil'; | ||
export {default as execIfIs} from './exec-if-is'; | ||
export {default as execIf} from './exec-if'; | ||
export {default as throwIfExists} from './throw-if-exists'; | ||
export {default as throwIfIsInstanceOf} from './throw-if-is-instanceof'; | ||
export {default as throwIfIsNil} from './throw-if-is-nil'; | ||
export {default as throwIfIs} from './throw-if-is'; | ||
export {default as throwIf} from './throw-if'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import throwIfExists from './fp/throw-if-exists'; | ||
|
||
export default <T>(err: Error, value: T) => { | ||
return throwIfExists<T>(err)(value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {ClassType} from './type'; | ||
import throwIfIsInstanceOf from './fp/throw-if-is-instanceof'; | ||
|
||
/** | ||
* | ||
* @param typeofClass The other instance to compare. | ||
* @param err Error message | ||
* @param instance The instance to compare. | ||
*/ | ||
export default <T>(typeofClass: ClassType, err: Error, instance: T): T => { | ||
return throwIfIsInstanceOf<T>(typeofClass, err)(instance); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import throwIfIsNil from './fp/throw-if-is-nil'; | ||
|
||
export default <T>(err: Error, value: T | null | undefined): T => { | ||
return throwIfIsNil<T>(err)(value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import throwIfIs from './fp/throw-if-is'; | ||
|
||
/** | ||
* | ||
* @param other The other value to compare. | ||
* @param err Error message | ||
* @param value The value to compare. | ||
*/ | ||
export default <T>(other: unknown, err: Error, value: T) => { | ||
return throwIfIs<T>(other, err)(value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {Predicate} from './type'; | ||
import throwIf from './fp/throw-if'; | ||
|
||
export default <T>(predicate: Predicate<T>, err: Error, value: T): T => { | ||
return throwIf(predicate, err)(value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type ClassType = new (...args: any[]) => any; | ||
|
||
export type Returns<T> = (value: T) => T; | ||
|
||
export type Promisable<T> = T | PromiseLike<T>; | ||
|
||
export type Predicate<Value> = (v: Value) => boolean; |
Oops, something went wrong.