# w-converhp

> An operator for hapi in nodejs and browser.

Latest version **2.1.2** (published 2026-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install w-converhp
pnpm add w-converhp
yarn add w-converhp
bun add w-converhp
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2026-09-18 |
| First published | 2019-12-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | yuda-lyu |
| Maintainers | semisphere |
| Keywords | package, tool, operator, hapi, nodejs, browser |

## Links

- npm: https://www.npmjs.com/package/w-converhp
- Repository: https://github.com/yuda-lyu/w-converhp
- Homepage: https://github.com/yuda-lyu/w-converhp#readme
- Issues: https://github.com/yuda-lyu/w-converhp/issues
- npm.io page: https://npm.io/package/w-converhp

## Dependencies (4)

- [axios](https://npm.io/package/axios.md) ^1.20.0
- [wsemi](https://npm.io/package/wsemi.md) ^1.9.1
- [@hapi/hapi](https://npm.io/package/@hapi/hapi.md) ^21.4.10
- [@hapi/inert](https://npm.io/package/@hapi/inert.md) ^7.1.2

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.1.2 (latest) — 2026-09-18
- 2.1.1 — 2026-09-18
- 2.0.89 — 2026-09-12
- 2.0.88 — 2026-09-05
- 2.0.87 — 2026-09-02
- 2.0.86 — 2026-09-01
- 2.0.85 — 2026-08-26
- 2.0.84 — 2026-08-21
- 2.0.83 — 2026-08-19
- 2.0.82 — 2026-08-18
- 2.0.81 — 2026-08-18
- 2.0.80 — 2026-08-18
- 2.0.79 — 2026-08-18
- 2.0.78 — 2026-08-08
- 2.0.77 — 2026-08-07
- … 109 more at https://npm.io/package/w-converhp/versions

## README

# w-converhp
An operator for hapi in nodejs and browser.

![language](https://img.shields.io/badge/language-JavaScript-orange.svg) 
[![npm version](http://img.shields.io/npm/v/w-converhp.svg?style=flat)](https://npmjs.org/package/w-converhp) 
[![license](https://img.shields.io/npm/l/w-converhp.svg?style=flat)](https://npmjs.org/package/w-converhp) 
[![npm download](https://img.shields.io/npm/dt/w-converhp.svg)](https://npmjs.org/package/w-converhp) 
[![npm download](https://img.shields.io/npm/dm/w-converhp.svg)](https://npmjs.org/package/w-converhp)
[![jsdelivr download](https://img.shields.io/jsdelivr/npm/hm/w-converhp.svg)](https://www.jsdelivr.com/package/npm/w-converhp)

## Documentation
To view documentation or get support, visit [docs](https://yuda-lyu.github.io/w-converhp/WConverhpServer.html).

## 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):
```alias
npm i w-converhp
```

#### Example for w-converhp-server in nodejs:
> **Link:** [[dev source code](https://github.com/yuda-lyu/w-converhp/blob/master/srv.mjs)]
```alias
import fs from 'fs'
import _ from 'lodash-es'
import w from 'wsemi'
import WConverhpServer from './src/WConverhpServer.mjs'

let ms = []

let opt = {
    port: 8080,
    apiName: 'api',
    pathStaticFiles: '.', //要存取專案資料夾下web.html, 故不能給dist
    sizeMsg: 100 * 1024 * 1024, //單次請求本體上限, 預設100mb, 適用於除切片(/slc)外之各API; 切片單次上限為sizeSlice, 大檔案總大小不受限, 請改用upload
    verifyConn: async ({ apiType, authorization, headers, query }) => {
        console.log('verifyConn', `apiType[${apiType}]`, `authorization[${authorization}]`)
        let token = w.strdelleft(authorization, 7) //刪除Bearer
        if (!w.isestr(token)) {
            return false
        }
        // await w.delay(3000)
        return true
    },
}

//new
let wo = new WConverhpServer(opt)

wo.on('execute', (func, input, pm) => {
    // console.log(`Server[port:${opt.port}]: execute`, func, input)
    console.log(`Server[port:${opt.port}]: execute`, func)

    try {

        if (func === 'add') {

            if (_.get(input, 'p.d.u8a', null)) {
                console.log('input.p.d.u8a', input.p.d.u8a)
                ms.push({ 'input.p.d.u8a': input.p.d.u8a })
            }

            let r = {
                _add: input.p.a + input.p.b,
                _data: [11, 22.22, 'abc', { x: '21', y: 65.43, z: 'test中文' }],
                _bin: {
                    name: 'zdata.b2',
                    u8a: new Uint8Array([52, 66, 97, 115]),
                },
            }

            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('upload', (input, pm) => {
    console.log(`Server[port:${opt.port}]: upload`, input)

    try {
        ms.push({ 'receive and return': input })
        let output = input
        pm.resolve(output)
    }
    catch (err) {
        console.log('upload error', err)
        pm.reject('upload error')
    }

})
wo.on('download', (input, pm) => {
    console.log(`Server[port:${opt.port}]: download`, input)

    let streamRead = null
    try {
        ms.push({ 'download': input })

        //fp
        let fp = `./test/1mb.7z`

        //check, 檔案存在才往下

        //fileSize
        let stats = fs.statSync(fp)
        let fileSize = stats.size

        //streamRead
        streamRead = fs.createReadStream(fp)

        //filename
        let filename = `1mb中文.7z` //測試支援中文

        //fileType
        let fileType = 'application/x-7z-compressed'

        //output
        let output = {
            streamRead,
            filename,
            fileSize,
            fileType,
        }

        pm.resolve(output)
    }
    catch (err) {
        console.log('download error', err)
        // try {
        //     streamRead.destroy() //若fs.createReadStream早於fs.statSync執行, 但fs.statSync發生錯誤時, stream得要destroy
        // }
        // catch (err) {}
        pm.reject('download error')
    }

})
wo.on('error', (err) => {
    console.log(`Server[port:${opt.port}]: error`, err)
})
wo.on('handler', (data) => {
    // console.log(`Server[port:${opt.port}]: handler`, data)
})

setTimeout(() => {
    console.log('ms', ms)
    // console.log('ms', JSON.stringify(ms))
    wo.stop()
}, 3000)

```

#### Example for w-converhp-client in nodejs:
> **Link:** [[dev source code](https://github.com/yuda-lyu/w-converhp/blob/master/scla.mjs)]
```alias
import WConverhpClient from './src/WConverhpClient.mjs'

let ms = []

let opt = {
    url: 'http://localhost:8080',
    apiName: 'api',
    getToken: () => {
        return 'token-for-test'
    },
}

//new
let wo = new WConverhpClient(opt)

wo.on('error', (err) => {
    console.log(`error`, err)
})

function downloadLargeFile() {
    let core = async() => {

        await wo.download('id-for-file',
            function ({ prog, p, m }) {
                // console.log('client web: download: prog', prog, p, m)
                if (m === 'download') {
                    console.log('client web: download: prog', prog)
                }
            },
            {
                fdDownload: './', //於後端nodejs環境才能提供
            })
            .then(function(res) {
                console.log('client web: download: then', res)
                ms.push({ 'download output': res })
            })
            .catch(function (err) {
                console.log('client web: download: catch', err)
            })

        console.log('ms', ms)

    }
    core()
}

downloadLargeFile()

```

### In a browser(UMD module):

Add script for w-converhp-client.
```alias
<script src="https://cdn.jsdelivr.net/npm/w-converhp@2.1.2/dist/w-converhp-client.umd.js"></script>
```

#### Example for w-converhp-client in browser:
> **Link:** [[dev source code](https://github.com/yuda-lyu/w-converhp/blob/master/web.html)]
```alias

let opt = {
    url: 'http://localhost:8080',
    apiName: 'api',
}

//new
let WConverhpClient=window['w-converhp-client']
let wo = new WConverhpClient(opt)

async function execute(name, u8a){

    //p
    let p = {
        a: 12,
        b: 34.56,
        c: 'test中文',
        d: {
            name: name,
            u8a,
        },
    }
    console.log('p',p)

    //execute
    await wo.execute('add', { p },
        function ({ prog, p, m }) {
            console.log('client web: execute: prog', prog, p, m)
        })
        .then(function(r) {
            console.log('client web: execute: add', r)
            wsemi.downloadFileFromU8Arr(r._bin.name,r._bin.u8a)
        })
        .catch(function (err) {
            console.log('client web: execute: catch', err)
        })

}

function executeWithU8a() {
    let core = async()=>{

        //u8a
        let u8a = new Uint8Array([66, 97, 115])
        console.log('executeWithU8a u8a', u8a)
    
        //execute
        await execute('zdata.b1', u8a)

    }
    core()
}

function executeWithFile() {
    let core = async()=>{

        //execute會把整個檔案讀入伺服器記憶體再處理, 上限由伺服器opt.sizeMsg決定(預設100mb), 更大的檔案請改用uploadLargeFile(切片上傳)
        let msg = await wsemi.domShowInputAndGetFiles({ sizeMbLimit: 100 }) //100mb
        console.log('domShowInputAndGetFiles msg',msg)

        //check
        if(Object.keys(msg.errs).length > 0){
            console.log('errs',msg.errs)
            return
        }

        //check
        if(msg.files.length===0){
            return 
        }

        //file
        let file = msg.files[0]
        console.log('file',file)

        //blob2u8arr
        let u8a = await wsemi.blob2u8arr(file)
        console.log('executeWithFile u8a',u8a)
        
        //execute
        await execute(file.name,u8a)

    }
    core()
}

function uploadLargeFile(){
    let core = async()=>{

        let msg = await wsemi.domShowInputAndGetFiles({ sizeMbLimit: 100*1000 }) //100g
        console.log('domShowInputAndGetFiles msg',msg)

        //check
        if(Object.keys(msg.errs).length > 0){
            console.log('errs',msg.errs)
            return
        }

        //check
        if(msg.files.length===0){
            return 
        }

        //file
        let file = msg.files[0]
        console.log('file',file)

        //upload
        await wo.upload(file.name, file,
            function ({ prog, p, m }) {
                console.log('client web: upload: prog', prog, p, m)
            })
            .then(function(res) {
                console.log('client web: upload: then', res)
            })
            .catch(function (err) {
                console.log('client web: upload: catch', err)
            })

    }
    core()
}

```

---
_Source: https://npm.io/package/w-converhp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
