npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

w-converhp

v1.0.40

Published

An operator for hapi in nodejs and browser.

Downloads

28

Readme

w-converhp

An operator for hapi in nodejs and browser.

language npm version license gzip file size npm download npm download jsdelivr download

Documentation

To view documentation or get support, visit docs.

Parts

w-converhp includes 2 parts:

  • w-converhp-server: for nodejs server
  • w-converhp-client: for nodejs and browser client

Installation

Using npm(ES6 module):

Note: w-converhp-server is mainly dependent on @hapi/hapi and @hapi/inert.

Note: w-converhp-client is mainly dependent on form-data.

npm i w-converhp

Example for w-converhp-server:

Link: [dev source code]

import WConverhpServer from 'w-converhp/dist/w-converhp-server.umd.js'

let opt = {
    port: 8080,
    apiName: 'api',
}

//new
let wo = new WConverhpServer(opt)

wo.on('open', function() {
    console.log(`Server[port:${opt.port}]: open`)

    //broadcast
    let n = 0
    setInterval(() => {
        n += 1
        let o = {
            text: `server broadcast hi(${n})`,
            data: new Uint8Array([66, 97, 115]), //support Uint8Array data
        }
        wo.broadcast(o, function (prog) {
            console.log('broadcast prog', prog)
        })
    }, 1000)

})
wo.on('error', function(err) {
    console.log(`Server[port:${opt.port}]: error`, err)
})
wo.on('clientChange', function(num) {
    console.log(`Server[port:${opt.port}]: now clients: ${num}`)
})
wo.on('clientEnter', function(clientId, data) {
    console.log(`Server[port:${opt.port}]: client enter: ${clientId}`)

    //deliver
    wo.deliver(clientId, `server deliver hi(${clientId})`)

})
wo.on('clientLeave', function(clientId, data) {
    console.log(`Server[port:${opt.port}]: client leave: ${clientId}`)
})
wo.on('execute', function(func, input, pm) {
    //console.log(`Server[port:${opt.port}]: execute`, func, input)
    console.log(`Server[port:${opt.port}]: execute`, func)

    try {

        if (func === 'add') {

            //save
            if (_.get(input, 'p.d.u8a', null)) {
                // fs.writeFileSync(input.p.d.name, Buffer.from(input.p.d.u8a))
                // console.log('writeFileSync input.p.d.name', input.p.d.name)
            }

            let r = {
                ab: input.p.a + input.p.b,
                v: [11, 22.22, 'abc', { x: '21', y: 65.43, z: 'test中文' }],
                file: {
                    name: 'zdata.b2',
                    u8a: new Uint8Array([66, 97, 115]),
                    //u8a: new Uint8Array(fs.readFileSync('C:\\Users\\Administrator\\Desktop\\z500mb.7z')),
                },
            }
            pm.resolve(r)
        }
        else {
            console.log('invalid func')
            pm.reject('invalid func')
        }

    }
    catch (err) {
        console.log('execute error', err)
        pm.reject('execute error')
    }

})
wo.on('broadcast', function(data) {
    console.log(`Server[port:${opt.port}]: broadcast`, data)
})
wo.on('deliver', function(data) {
    console.log(`Server[port:${opt.port}]: deliver`, data)
})

// Server running at: http://localhost:8080
// Server[port:8080]: open
// Server[port:8080]: execute add
// Server[port:8080]: broadcast client nodejs[port:8080] broadcast hi
// Server[port:8080]: deliver client nodejs[port:8080] deliver hi
// Server[port:8080]: client enter: [random key]
// Server[port:8080]: now clients: 1
// broadcast prog 100
// Server[port:8080]: execute add
// Server[port:8080]: broadcast client web broadcast hi
// Server[port:8080]: deliver client web deliver hi
// Server[port:8080]: client enter: [random key]
// Server[port:8080]: now clients: 2
// broadcast prog 100

Example for w-converhp-client:

Link: [dev source code]

import WConverhpClient from 'w-converhp/dist/w-converhp-client.umd.js'

let opt = {
    url: 'http://localhost:8080',
    apiName: 'api',
}

//new
let wo = new WConverhpClient(opt)

wo.on('open', function() {
    console.log('client nodejs[port:8080]: open')
})
wo.on('openOnce', function() {
    console.log('client nodejs[port:8080]: openOnce')

    //p
    let name = 'zdata.b1'
    let p = {
        a: 12,
        b: 34.56,
        c: 'test中文',
        d: {
            name: name,
            u8a: new Uint8Array([66, 97, 115]),
            //u8a: new Uint8Array(fs.readFileSync('C:\\Users\\Administrator\\Desktop\\'+name)),
        }
    }

    //execute
    wo.execute('add', { p },
        function (prog, p, m) {
            console.log('client nodejs[port:8080]: execute: prog', prog, p, m)
        })
        .then(function(r) {
            console.log('client nodejs[port:8080]: execute: add', r)
        })
        .catch(function(err) {
            console.log('client nodejs[port:8080]: execute: catch', err)
        })

    //broadcast
    wo.broadcast('client nodejs[port:8080] broadcast hi', function (prog) {
        console.log('client nodejs[port:8080]: broadcast: prog', prog)
    })
        .catch(function(err) {
            console.log('client nodejs[port:8080]: broadcast: catch', err)
        })

    //deliver
    wo.deliver('client nodejs[port:8080] deliver hi', function (prog) {
        console.log('client nodejs[port:8080]: deliver: prog', prog)
    })
        .catch(function(err) {
            console.log('client nodejs[port:8080]: deliver: catch', err)
        })

})
wo.on('close', function() {
    console.log('client nodejs[port:8080]: close')
})
wo.on('error', function(err) {
    console.log('client nodejs[port:8080]: error', err)
})
wo.on('reconn', function() {
    console.log('client nodejs[port:8080]: reconn')
})
wo.on('broadcast', function(data) {
    console.log('client nodejs[port:8080]: broadcast', data)
})
wo.on('deliver', function(data) { 
    console.log('client nodejs[port:8080]: deliver', data)
})

// client nodejs[port:8080]: open
// client nodejs[port:8080]: openOnce
// client nodejs[port:8080]: execute: add {
//   ab: 46.56,
//   v: [ 11, 22.22, 'abc', { x: '21', y: 65.43, z: 'test中文' } ],
//   file: { name: 'zdata.b2', u8a: Uint8Array [ 66, 97, 115 ] }
// }
// client nodejs[port:8080]: deliver { mode: 'deliver', data: 'server deliver hi([random key])' }
// client nodejs[port:8080]: broadcast { text: 'server broadcast hi(1)', data: Uint8Array [ 66, 97, 115 ] }
// client nodejs[port:8080]: broadcast { text: 'server broadcast hi(2)', data: Uint8Array [ 66, 97, 115 ] }

In a browser(UMD module):

Note: w-converhp-client does't depend on any package.

[Necessary] Add script for w-converhp-client.

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/w-converhp-client.umd.js"></script>

Example for w-converhp-client:

Link: [dev source code]


let opt = {
    url: 'http://localhost:8080',
}

//new
let WConverhpClient=window['w-converhp-client']
let wo = new WConverhpClient(opt)

wo.on('open', function() {
    console.log('client web: open')
})
wo.on('openOnce', function() {
    console.log('client web: openOnce')

    //p
    let name = 'zdata.b1'
    let p = {
        a: 12,
        b: 34.56,
        c: 'test中文',
        d: {
            name: name,
            u8a: new Uint8Array([66, 97, 115]),
            //u8a: new Uint8Array(fs.readFileSync('C:\\Users\\Administrator\\Desktop\\'+name)),
        }
    }

    //execute
    wo.execute('add', { p:p },
        function (prog, p, m) {
            console.log('client web: execute: prog', prog, p, m)
        })
        .then(function(r) {
            console.log('client web: execute: add', r)
        })
        .catch(function (err) {
            console.log('client web: execute: catch', err)
        })

    //broadcast
    wo.broadcast('client web broadcast hi', function (prog) {
        console.log('client web: broadcast: prog', prog)
    })
        .catch(function (err) {
            console.log('client web: broadcast: catch', err)
        })

    //deliver
    wo.deliver('client web deliver hi', function (prog) {
        console.log('client web: deliver: prog', prog)
    })
        .catch(function (err) {
            console.log('client web: deliver: catch', err)
        })

})
wo.on('close', function() {
    console.log('client web: close')
})
wo.on('error', function(err) {
    console.log('client web: error', err)
})
wo.on('reconn', function() {
    console.log('client web: reconn')
})
wo.on('broadcast', function(data) {
    console.log('client web: broadcast', data)
})
wo.on('deliver', function(data) { 
    console.log('client web: deliver', data)
})
wo.on('handler', function(data) {
    // console.log(`Server[port:${opt.port}]: handler`, data)
})

// client web: open
// client web: openOnce
// client web: execute: add {
//   ab: 46.56,
//   v: [ 11, 22.22, 'abc', { x: '21', y: 65.43, z: 'test中文' } ],
//   file: { name: 'zdata.b2', u8a: Uint8Array [ 66, 97, 115 ] }
// }
// client web: deliver { mode: 'deliver', data: 'server deliver hi([random key])' }
// client web: broadcast { text: 'server broadcast hi(1)', data: Uint8Array [ 66, 97, 115 ] }
// client web: broadcast { text: 'server broadcast hi(2)', data: Uint8Array [ 66, 97, 115 ] }