npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

binstring

v0.2.1

Published

Convert binary data to and from various string representations

Downloads

9,000

Readme

BinString

JavaScript component to convert to/from strings and byte arrays.

AMD/CommonJS compatible.

Usage

This library exposes a single function that takes a data parameter and an options object. Set options.in and options.out to the format of the input and desired output. Possible values include:

  • hex: Hex-encoded string; two hexadecimal characters per byte
  • binary: Binary-encoded string (ASCII-encoded)
  • utf8: Binary-encoded string (UTF8-encoded)
  • bytes: Byte array; an array of numbers, each representing one byte of data
  • buffer: A Node.js native Buffer object

The default encoding for options.out is a buffer (buffer). The input format is duck-typed if it's an Array (bytes) or Buffer (buffer) or Number object. If it's a string, it's interpreted as binary unless it's prefixed by 0x (then it's hex). If options.in is set, it overrides the automatic duck-typing of the input variable.

var conv = require('binstring');

console.dir(conv('hello', { in:'binary' })); // No output encoding specified, defaults to Buffer; output: Buffer([104,101,108,108,111])
console.dir(conv([104,101,108,108,111], { out:'hex' })); // No input encoding specified, auto-detected as Byte Array; output: 68656c6c6f
console.dir(conv('hello', { in:'binary', out:'hex' })); // output: 68656c6c6f

Test

Unit tests are written in Mocha. To run the test suite, checkout the git repository, and from within the base folder run:

$ npm install --dev
$ ./node_modules/mocha/bin/mocha

References on JavaScript UTF-8 forced encoding

(these sources are also included as PDFs in the repo in case the links go dead)

  • http://ecmanaut.blogspot.com/2006/07/encoding-decoding-utf8-in-javascript.html
  • http://hossa.in/2012/07/20/utf-8-in-javascript.html

License

(MIT License)

Copyright 2014, Brooks Boyd [email protected]