divlook / ifjs

A nice conditional statement (incomplete)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README

Auto Release CI

A nice conditional statement

Install

v1.0.0 이전까지는 github 패키지 사용 예정

# npm login --scope=@divlook --registry=https://npm.pkg.github.com
npm install @divlook/ifjs

# yarn npm login --scope=@divlook --registry=https://npm.pkg.github.com
yarn add @divlook/ifjs

Usage

Default

import { Condition } from '@divlook/ifjs'

const condition = new Condition()

condition.and(() => false)
condition.or(() => false)

await condition.is.false() // true

Chaining

import { Condition } from '@divlook/ifjs'

await new Condition(() => true)
    .and(() => 0 === '0')
    .or(() => 1 === 2)
    .is.true() // false

Sub Condition

import { Condition } from '@divlook/ifjs'

const condition = new Condition()
    .and(sub => {
        const subCondition = sub()
        return subCondition
            .and(() => false)
            .or(() => false)
            .is.true()
    })
    .or(sub => {
        return sub(() => true)
            .or(() => false)
            .is.true()
    })

condition.and(() => false)

await condition.is.false()

Async

import { Condition } from '@divlook/ifjs'

const condition = new Condition(() => {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve(true)
        }, 2000)
    })
})

await condition.is.true()

About

A nice conditional statement (incomplete)

License:MIT License


Languages

Language:TypeScript 100.0%