@pronix/hyper-flow
TypeScript icon, indicating that this package has built-in type declarations

1.5.2 • Public • Published

HyperFlow.js

Framework for building progressive console applications on node.js platform

Getting started

$ yarn add @pronix/hyper-flow
#or
$ npm i @pronix/hyper-flow
const { Hyper, HyperContext } = require('@pronix/hyper-flow')
// or
// import { Hyper, HyperContext } from '@pronix/hyper-flow''

const app = new Hyper()
const ctx = new HyperContext()

ctx.on('/', () => console.log('hello'))

app.next(ctx)
app.listen()

Documentation 📄

using

at first, you need to create application

import { Hyper } from '@pronix/hyper-flow'

const app = new Hyper()

next you need to create ctx - this is the object that will process the commands, you can create more than one context and then you can change current context in runtime

import { Hyper, HyperContext, utils } from '@pronix/hyper-flow'

const app = new Hyper()

const ctx1 = new HyperContext(utils.marker('ctx1'))
const ctx2 = new HyperContext(utils.marker('ctx2'))

ctx1
    .on('/next', () => app.next(ctx2))
    .on('/back', () => app.back())
    .on('/', () => console.log(utils.renderCommands(ctx1.cmds)))

ctx2
    .on('/next', () => app.next(ctx1))
    .on('/back', () => app.back())
    .nothing('', ' ')

app
    .next(ctx1)
    .listen()

also you can use async code in your program, it will works, because the readline is async

const app = new Hyper()

const ctx = new HyperContext()
const ctx2 = new HyperContext()


ctx.on('/', () => {
    console.log('hello')
    app.next(ctx2)
})

ctx2
    .on('/', () => console.log('end'))
    .on('/ask', () => {
        // question must be a sync call ->
        const response = question('what is your name?')
        // processing response
        console.log(response)
    })
    .default((ctx, cmd) => {
        console.log(cmd)
    })

app.next(ctx)

// you can use async side-effects ->
setTimeout(() => {
    console.log('async call')
}, 3000)

app.listen()

marker is a tool, which writes the text in comand line befor every command, it is a string

import { error } from "@pronix/hyper-flow";

ctx.marker = 'ctx1:\\> '

ctx
    .on('/', () => console.log('hello'))
    
    .on('/error', () => console.log(error('error handler', 1)))
    
    .on('exit', () => process.exit(0))
    .on('/exit', ctx => ctx.run('exit'))

app
    .defaultContext
    .on('/info', () => console.log('info: ...'))
    .nothing('')

app
    .next(ctx)
    .listen()

stop word:

ctx
    .on('/', () => console.log('hello world'))

app.next(ctx)

app.stopWord = 'stop'

app.listen()

for developing

setup ⚙️

$ git clone http://github.com/pronix575/hyper-flow
$ cd hyper-flow

$ yarn setup
# or
$ npm setup

build 🛠

$ yarn build

start 🚀

$ yarn start

developing 🧱

$ yarn dev:build
$ yarn dev:start

Package Sidebar

Install

npm i @pronix/hyper-flow

Weekly Downloads

30

Version

1.5.2

License

MIT

Unpacked Size

52 kB

Total Files

45

Last publish

Collaborators

  • pronix