Code Monkey home page Code Monkey logo

flatiron.utile's Introduction

utile Build Status

A drop-in replacement for util with some additional advantageous functions

Motivation

Javascript is definitely a "batteries not included language" when compared to languages like Ruby or Python. Node.js has a simple utility library which exposes some basic (but important) functionality:

$ node
> var util = require('util');
> util.
(...)

util.debug                 util.error                 util.exec                  util.inherits              util.inspect
util.log                   util.p                     util.print                 util.pump                  util.puts

When one considers their own utility library, why ever bother requiring util again? That is the approach taken by this module. To compare:

$ node
> var utile = require('./lib')
> utile.
(...)

utile.async                 utile.capitalize            utile.clone                 utile.cpr                   utile.createPath            utile.debug
utile.each                  utile.error                 utile.exec                  utile.file                  utile.filter                utile.find
utile.inherits              utile.log                   utile.mixin                 utile.mkdirp                utile.p                     utile.path
utile.print                 utile.pump                  utile.puts                  utile.randomString          utile.requireDir            uile.requireDirLazy
utile.rimraf

As you can see all of the original methods from util are there, but there are several new methods specific to utile. A note about implementation: no node.js native modules are modified by utile, it simply copies those methods.

Methods

The utile modules exposes some simple utility methods:

  • .each(obj, iterator): Iterate over the keys of an object.
  • .mixin(target [source0, source1, ...]): Copies enumerable properties from source0 ... sourceN onto target and returns the resulting object.
  • .clone(obj): Shallow clones the specified object.
  • .capitalize(str): Capitalizes the specified str.
  • .randomString(length): randomString returns a pseudo-random ASCII string (subset) the return value is a string of length ⌈bits/6βŒ‰ of characters from the base64 alphabet.
  • .filter(obj, test): return an object with the properties that test returns true on.
  • .args(arguments): Converts function arguments into actual array with special callback, cb, array, and last properties. Also supports optional argument contracts. See the example for more details.
  • .requireDir(directory): Requires all files and directories from directory, returning an object with keys being filenames (without trailing .js) and respective values being return values of require(filename).
  • .requireDirLazy(directory): Lazily requires all files and directories from directory, returning an object with keys being filenames (without trailing .js) and respective values (getters) being return values of require(filename).
  • .format([string] text, [array] formats, [array] replacements): Replace formats in text with replacements. This will fall back to the original util.format command if it is called improperly.

Packaged Dependencies

In addition to the methods that are built-in, utile includes a number of commonly used dependencies to reduce the number of includes in your package.json. These modules are not eagerly loaded to be respectful of startup time, but instead are lazy-loaded getters on the utile object

Installation

Installing npm (node package manager)

  curl http://npmjs.org/install.sh | sh

Installing utile

  [sudo] npm install utile

Tests

All tests are written with vows and should be run with npm:

  $ npm test

License: MIT

flatiron.utile's People

Contributors

indexzero avatar pksunkara avatar mmalecki avatar dominictarr avatar marak avatar southern avatar cpsubrian avatar coderarity avatar jcrugzz avatar jfhbrook avatar tiankongldp avatar chjj avatar timoxley avatar rrichardson avatar

Watchers

James Cloos avatar Brenton House avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.