# nv-buf-utf8

> nv-buf-utf8 =============== - nv-buf-utf8 - a utf8 step-decoder, input one-byte each time. return-code-point-if-success , return-undefined-if-in-waiting-more-bytes

Latest version **1.0.7** (published 2023-06-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install nv-buf-utf8
pnpm add nv-buf-utf8
yarn add nv-buf-utf8
bun add nv-buf-utf8
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2023-06-18 |
| First published | 2022-08-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ihgazni2 |

## Links

- npm: https://www.npmjs.com/package/nv-buf-utf8
- npm.io page: https://npm.io/package/nv-buf-utf8

## Recent versions

- 1.0.7 (latest) — 2023-06-18
- 1.0.4 — 2023-04-02
- 1.0.3 — 2023-04-01
- 1.0.2 — 2022-08-14
- 1.0.1 — 2022-08-14

## README

nv-buf-utf8
===============
- nv-buf-utf8    
- a utf8 step-decoder, input one-byte each time.  return-code-point-if-success  , return-undefined-if-in-waiting-more-bytes
- support two-modes: auto-recover AND throw-error
- can observe state : [ 'INIT', 'U1', 'U2', 'U3', 'U4', 'ERROR' ]
- its for remote decode , normally USELESS

install
=======
- npm install nv-buf-utf8 

usage
=====

         const {decd} = require("nv-buf-utf8");
         const {Mach} = decd.mach;
         

    
example
-------

                var mach = new Mach()

                var buf = Buffer.from("我你");
                /*
                > "我".codePointAt(0)
                25105
                > "你".codePointAt(0)
                20320
                > 
                */

                > mach.input(buf[0])
                undefined
                > mach.input(buf[1])
                undefined
                > mach
                Mach(7) [{"cursor":5,"state":"U3","data":[230,136],"err_byte":0}] [
                    5, 19, 0, 230,
                  136,  0, 0
                ]
                > mach.input(buf[2])
                25105
                > 
                > mach
                Mach(7) [{"cursor":3,"state":"INIT","data":[],"err_byte":0}] [
                  3, 16, 0, 0,
                  0,  0, 0
                ]
                > 
                > mach.input(buf[3])
                undefined
                > mach.input(buf[4])
                undefined
                > mach.input(buf[5])
                20320
                > 
                > mach.input(buf[0])
                undefined
                > mach
                Mach(7) [{"cursor":4,"state":"U3","data":[230],"err_byte":0}] [
                  4, 19, 0, 230,
                  0,  0, 0
                ]
                > mach.lefted_
                [ 230 ]
                > mach.input(buf[1])
                undefined
                > mach.lefted_
                [ 230, 136 ]
                > mach.input(buf[2])
                25105
                > mach.lefted_
                []
                > 



METHODS
=======

decode
------

                decd.mach.mach.cursor_                  decd.mach.mach.dict
                decd.mach.mach.disable_auto_recover     decd.mach.mach.enable_auto_recover      decd.mach.mach.err_byte_
                decd.mach.mach.input                    decd.mach.mach.is_auto_recover_enabled  decd.mach.mach.is_err
                decd.mach.mach.is_init                  decd.mach.mach.is_u2                    decd.mach.mach.is_u3
                decd.mach.mach.is_u4                    decd.mach.mach.lefted_                  decd.mach.mach.reset
                decd.mach.mach.state_code_              decd.mach.mach.state_name_



                 mach: {
                    STATES: [ 'INIT', 'U1', 'U2', 'U3', 'U4', 'ERROR' ],
                    ERRORS: {
                      in_error_must_reset: 'in_error_must_reset',
                      fst_byte_invalid: 'first byte must be <0xxxxxxx> OR <110xxxxx> OR <1110xxxx> OR <11110xxx>',
                      follow_byte_invalid: 'follow byte must be <10xxxxxx>'
                    },
                    Mach: [class Mach extends Uint8Array] { ALGN_OFFSET: 3 },
                    auto_recover_mach: Mach(7) [{"cursor":3,"state":"INIT","data":[],"err_byte":0}] [
                      3, 16, 0, 0,
                      0,  0, 0
                    ],
                    mach: Mach(7) [{"cursor":3,"state":"INIT","data":[],"err_byte":0}] [
                      3, 0, 0, 0,
                      0, 0, 0
                    ]
                  }


API
====

decode
------

                > decd.def
                {
                  is_u1_head: [Function: is_u1_head],
                  is_u2_head: [Function: is_u2_head],
                  is_u3_head: [Function: is_u3_head],
                  is_u4_head: [Function: is_u4_head],
                  is_follow: [Function: is_follow],
                  u2_to_code: [Function: u2_to_code],
                  u3_to_code: [Function: u3_to_code],
                  u4_to_code: [Function: u4_to_code],
                  barr_to_code: [Function: barr_to_code]
                }
                >  



LICENSE
=======
- ISC

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