# binstring58

> buffer 2 string and back with options dictionary, wraps base58

Latest version **0.0.6** (published 2016-04-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install binstring58
pnpm add binstring58
yarn add binstring58
bun add binstring58
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2016-04-05 |
| First published | 2016-04-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | leif@chroma.io |
| Maintainers | chroma |

## Links

- npm: https://www.npmjs.com/package/binstring58
- npm.io page: https://npm.io/package/binstring58

## Recent versions

- 0.0.6 (latest) — 2016-04-05
- 0.0.5 — 2016-04-05
- 0.0.4 — 2016-04-05
- 0.0.3 — 2016-04-05
- 0.0.2 — 2016-04-05
- 0.0.1 — 2016-04-05

## README

# example

```
binString = require('binstring58').binString
hex = binString('this is utf', {out: 'hex'})
utf8 = binString('hex', {in:'hex', out: 'utf8'})
```

# source
``` coffee
bs58 = require('bs58')

nestedOptions = (options) ->
  options ?= {}
  nested =
    in:
      sha3: options.sha3 || false
    out:
      sha3: options.sha3 || false
  if options.in then nested.in.in = options.in
  if options.out then nested.out.out = options.out
  nested

isBuffer = (obj) ->
  ! !(obj != null and (obj._isBuffer or obj.constructor and typeof obj.constructor.isBuffer == 'function' and obj.constructor.isBuffer(obj)))

binString = (data, options) ->
  options ?= {}
  if !isBuffer(data)
    if Array.isArray(data)
      data = new Buffer(data)
    else if typeof data == 'number'
      data = new Buffer(data.toString(16), 'hex')
    else if typeof data == 'string'
      if options.in
        if options.in == 'base58' then data = new Buffer(bs58.decode data)
        # else if options.in == 'base91' then data = base91.decode data
        else data = new Buffer(data, options.in)
      else
        if data.slice(0, 2) == '0x'
          data = new Buffer(data.slice(2), 'hex')
        else
          data = new Buffer(data, 'binary')
  switch options.out
    when 'bytes' then bufferToBytes data
    when 'base58' then bs58.encode data
    # when 'base91' then base91.encode data
    when 'hex', 'binary', 'utf8', 'base64' then data.toString(options.out)
    else data

bufferToBytes = (data) ->
  rs = []
  i = 0
  while i < data.length
    rs.push data[i]
    i++
  rs

module.exports =
  nestedOptions: nestedOptions
  binString: binString

```

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