goto-ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

GOTO-TS

goto in typescript/javascript because we've all been missing it and also why not.

    import { Goto } from "goto-ts"

    let a = 1

    const fn = new Goto<number>()
        .label("1",() => {
            console.log("hello 1")
        })
        .label("2",goto => {
            console.log("hello 2")

            if(a++ < 10){
                goto("1")
            }
        })
        .label("3",(_,_return) => {
            console.log("hello 3")
            _return(a)
        })
        .toFunction()

    fn()
        .then(b => b === 10 //true)
    import { withGoto } from "goto-ts"

    const fn = async (x: number) => {
        await withGoto({
            'abc': goto => {
                x++
                goto('cde')
            },
            'bcd': (_,_return) => {
                x++
                _return(null)
            },
            'cde': goto => {
                x++
                goto('bcd')
            }
        })
    
        return x
    }

More to come soon...

Readme

Keywords

Package Sidebar

Install

npm i goto-ts

Weekly Downloads

2

Version

1.0.4

License

MIT

Unpacked Size

18 kB

Total Files

11

Last publish

Collaborators

  • marusdod