Skip to content

Instantly share code, notes, and snippets.

@joepie91
Last active January 27, 2018 13:26
Show Gist options
  • Save joepie91/7a709e3b0eafb0c19f67ae38636c8a58 to your computer and use it in GitHub Desktop.
Save joepie91/7a709e3b0eafb0c19f67ae38636c8a58 to your computer and use it in GitHub Desktop.
Useful modules on NPM

Essential utilities

  • default-value: Returns either the value that's passed in, or a 'default value' if there isn't one. Useful for dealing with options.

Working with data

Type checking

  • is-array: Checks whether a value is an array.
  • is-stream: Checks whether a value is a stream of some sort.
  • type-of-is: Various utilities for checking and determining types.

Arrays

  • in-array: Checks whether an array contains a particular value.
  • arr-flatten: Turns nested arrays into a single 'flat' array.
  • arr-union: Combines a list of arrays, ensuring only unique values
  • assure-array: Wraps a value in an array if it isn't already one.
  • array-unique: Removes duplicate values from an array.

Objects

  • xtend: Combines multiple objects into one, without modifying any of the originals.
  • object.pick: Returns a copy of an object, containing only the specified properties.
  • object.omit: Returns a copy of an object, containing everything except for the specified properties.

Strings

Promises

ES6 Promises

(Seriously though, you should probably be using Bluebird instead. It's more robust and has these things built in.)

Control flow

  • promise-task-queue: A configurable task queue that supports Promises, with support for rate limiting and concurrency control.
  • promise-while-loop: An asynchronous while-loop implementation with full support for Promises.

Strange promisification cases

  • promise-simple-callback: Promisifies a function that expects a callback with a single (result) argument, rather than the usual (err, result) style callbacks.

Security

Password hashing

You should use either of the following two. Note that while scrypt is newer and thus less tested, bcrypt has a limit of around 72 characters for the password. Do not use pure-JavaScript implementations! If you are having trouble installing these, refer to this page.

Random values

Don't use Math.random, or anything based on it! In most cases (API keys, reset tokens, lottery numbers, ...) you actually need cryptographically secure random values, and Math.random can't provide these.

The only case in which you want to use Math.random, is when you need a lot of random numbers very quickly and it doesn't matter whether they are predictable - for example, when spawning monsters in a game at random locations.

Cryptographical tokens

Streams

Custom streams

  • through2: Easily create custom streams, including object streams.

Common transform streams

  • dev-null: Writable stream that throws away whatever you put into it, without looking at it. Useful for 'draining' a stream.
  • through2-sink: Stream that calls a callback for every write, and then throws away the data.
  • through2-spy: Stream that calls a callback for every write, and then passes through the original data.

Other streaming usecases

  • stream-combiner2: Represents a series of streams that pipe into each other, as a single stream. Useful for abstracting out pipelines.
  • combined-stream2: Provides a single Readable stream that automatically concatenates the contents of multiple other streams or Buffers, in order.
  • concat-stream: Buffers up a stream, and calls a callback with the concatenated result when the stream has finished.

Stream utilities

  • stream-length: Attempts to obtain the total length of a stream, without reading out its contents.

Multimedia

Browser codecs

  • aac: Pure-JS AAC decoder for browsers.
  • alac: Pure-JS ALAC decoder for browsers.
  • broadway-player: Pure-JS H.264 decoder for browsers. This is an unofficial build of Broadway.js, and may be moved in the future.
  • flac.js: Pure-JS FLAC decoder for browsers.
  • hls.js: HLS polyfill for browsers that do not natively support it.
  • mp3: Pure-JS MP3 decoder for browsers.
  • opus.js: An Emscripten-compiled Opus decoder that works in the browser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment