1.2.2 • Published 11 months ago

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

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

qb-utf8-from-str-tiny

npm downloads bitHound Dependencies dev dependencies code analysis

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

module.exports = function (s) {
  for (var i = 0, enc = encodeURIComponent(s), a = []; i < enc.length;) {
    if (enc[i] === '%') {
      a.push(parseInt(enc.substr(i + 1, 2), 16))
      i += 3
    } else {
      a.push(enc.charCodeAt(i++))
    }
  }
  return a
}

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-from-str-tiny

Example

npm install qb-utf8-from-str-tiny

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

API

utf8-from-str (s)

  • s: a javascript string to convert to an array of integer bytes (integers in the range 0..255) in UTF-8 format
1.2.2

11 months ago

1.2.1

7 years ago

1.2.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago