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

gumyen

v0.0.6

Published

Reasonably transparent handling of text encodings

Downloads

14

Readme

gumyen

Guess My Encoding. Small module that originated as a scratch to a personal itch around opening files which may be utf8/16, but which is now a more useful (though still small) utility for dealing with these encodings.

caveats

Currently this is optimised for the (rather specific) case of determining the encoding of XML and JSON files which may be any of UTF8/16-LE/16-BE. Gumyen works by reading the first 10 octets of a file and then (a) checking for a byte order mark, then if not found (b) checking for '{' encoded in utf16le or be as the first character of the file, and then (c) the string <?xml in each of the three encodings utf8, utf16le, utf16be. Additionally has utilities for stripping UTF BOM from buffers, strings and files, and writing strings and buffers to files with prepended BOMs.

usage

var gumyen = require('gumyen')

gumyen.encoding(filename, function(err, encoding) {
  // encoding is 'utf8', 'utf16le', 'utf16be'
});

var encoding = encodingSync(filename);
// sync version of above

gumyen.readFileWithDetectedEncoding(filename, function(err, data, encoding) {
  // encoding is 'utf8', 'utf16le', 'utf16be'
  // data is string contents of file
  // removes BOM
});

var data = gumyen.readFileWithDetectedEncodingSync(filename);
// sync version of above

var clean = gumyen.removeBOM(stringOrBuffer);

gumyen.writeFile(filename, data, options, function(err) {
  // wraps fs.writeFile, writes with BOM appropriate to encoding given in options
  // if options.writeBOM is truthy. data can be string or buffer
});

gumyen.writeFileSync(filename, data, options); {
// sync version of above

var bufferWithBOM = gumyen.addBOM(buffer, encoding);

dependencies

if you're wanting to work with utf16be, you'll need a module such as iconv-lite

install

npm install gumyen

test

npm test