Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonhoGo committed Jul 4, 2024
2 parents ad2ddbf + 04a2bc3 commit c0b2caa
Show file tree
Hide file tree
Showing 40 changed files with 3,849 additions and 215 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Release
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master, next, next-major, alpha, beta, '*.*.*' ]
branches: [master, next, next-major, alpha, beta, '*.*.*']

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand All @@ -28,6 +28,7 @@ jobs:
run: npm ci
- name: Typescript Compile
run: npm run compile
- run: cp package.json build/package.json
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
env:
Expand All @@ -36,8 +37,5 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
with:
extra_plugins: |
@semantic-release/release-notes-generator
@semantic-release/changelog
@semantic-release/git
@semantic-release/npm
@semantic-release/github
12 changes: 12 additions & 0 deletions CHANGELOG.md
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

* 마지막 인자를 받는 함수들의 경로가 수정 됨
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@

**ifify**는 이러한 분기를 최소화하고 변수 타입의 일관성과 좀 더 이해하기 쉽고 가독성이 향상된 코드를 지향하고자 작성되었습니다.

## Usage

### Full arguments function call

```typescript
import {throwIfIsNil} from '@bbros/ifify';

throwIfIsNil(new Error('It is nil'), Something);
```

### Curried last argument function call

!`v1.0.0`에서 해당 함수의 사용 방법이 변경되었습니다.

```typescript
import {throwIfIsNil} from '@bbros/ifify/fp';

Promise.resolve(Something)
.then(throwIfIsNil(new Error('It is nil')))
```

## Example

### Type-guard
Expand Down Expand Up @@ -130,3 +151,8 @@ const user: User = await db.users.findById(userId)

[license-image]: https://img.shields.io/npm/l/@bbros/ifify.svg
[license-url]: https://github.com/boostbrothers/ifify/blob/master/LICENSE

# To-Do

- [x] instanceOf predicate
- [ ] call functions
6 changes: 6 additions & 0 deletions lib/exec-if-exists.ts
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);
};
11 changes: 11 additions & 0 deletions lib/exec-if-is-instanceof.ts
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);
};
6 changes: 6 additions & 0 deletions lib/exec-if-is-nil.ts
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);
};
6 changes: 6 additions & 0 deletions lib/exec-if-is.ts
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);
};
10 changes: 10 additions & 0 deletions lib/exec-if.ts
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);
};
12 changes: 12 additions & 0 deletions lib/fp/exec-if-exists.ts
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);
};
8 changes: 8 additions & 0 deletions lib/fp/exec-if-is-instanceof.ts
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);
11 changes: 11 additions & 0 deletions lib/fp/exec-if-is-nil.ts
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;
};
5 changes: 5 additions & 0 deletions lib/fp/exec-if-is.ts
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);
10 changes: 10 additions & 0 deletions lib/fp/exec-if.ts
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;
};
10 changes: 10 additions & 0 deletions lib/fp/index.ts
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';
10 changes: 10 additions & 0 deletions lib/fp/throw-if-exists.ts
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;
};
10 changes: 10 additions & 0 deletions lib/fp/throw-if-is-instanceof.ts
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;
};
10 changes: 10 additions & 0 deletions lib/fp/throw-if-is-nil.ts
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;
};
};
11 changes: 11 additions & 0 deletions lib/fp/throw-if-is.ts
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);
};
10 changes: 10 additions & 0 deletions lib/fp/throw-if.ts
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;
};
10 changes: 10 additions & 0 deletions lib/index.ts
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';
5 changes: 5 additions & 0 deletions lib/throw-if-exists.ts
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);
};
12 changes: 12 additions & 0 deletions lib/throw-if-is-instanceof.ts
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);
};
5 changes: 5 additions & 0 deletions lib/throw-if-is-nil.ts
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);
};
11 changes: 11 additions & 0 deletions lib/throw-if-is.ts
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);
};
6 changes: 6 additions & 0 deletions lib/throw-if.ts
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);
};
7 changes: 7 additions & 0 deletions lib/type.ts
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;
Loading

0 comments on commit c0b2caa

Please sign in to comment.