1.2.2 • Published 11 months ago

qb-utf8-to-str-tiny v1.2.2

Weekly downloads
6
License
ISC
Repository
github
Last release
11 months ago

qb-utf8-to-str-tiny

npm downloads bitHound Dependencies dev dependencies code analysis

Tiny script for converting utf-8 to string based upon decodeURIComponent().
Runs in nodejs and in browser. Not efficient for large strings.

module.exports = function utf8_to_str (src, off, lim) {
  lim = lim == null ? src.length : lim
  for (var i = off || 0, s = ''; i < lim; i++) {
    var h = src[i].toString(16)
    if (h.length < 2) h = '0' + h
    s += '%' + h
  }
  return decodeURIComponent(s)
}

That's it. That's the code.

Complies with the 100% test coverage and minimum dependency requirements of qb-standard .

Install

npm install qb-utf8-to-str-tiny

Example

npm install qb-utf8-to-str-tiny

node
> var utf2str = require('qb-utf8-to-str-tiny')
> utf2str([ 103,195,174,100,100,195,177,117,112,240,144,130,131,33 ])
'gîddñup𐂃!'

API

utf8_to_str (src, off, lim)

  • src: an array or typed-array containing bytes or unsigned integers in UTF-8 format.

  • off: an inclusive byte offset where to start conversion

  • lim: an exclusive byte offset where to stop conversion

1.2.2

11 months ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago