Socket
Socket
Sign inDemoInstall

utile

Package Overview
Dependencies
4
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

utile


Version published
Maintainers
1
Install size
139 kB
Created

Package description

What is utile?

The 'utile' npm package is a utility library that provides a collection of useful functions for various common tasks in Node.js development. It includes features for deep cloning, merging objects, asynchronous flow control, and more.

What are utile's main functionalities?

Deep Cloning

The 'clone' function allows you to create a deep copy of an object, ensuring that nested objects are also cloned rather than referenced.

const utile = require('utile');
const obj = { a: 1, b: { c: 2 } };
const clone = utile.clone(obj);
console.log(clone); // { a: 1, b: { c: 2 } }

Merging Objects

The 'mixin' function merges properties from one or more objects into a target object, with later objects overwriting properties of earlier ones.

const utile = require('utile');
const obj1 = { a: 1, b: 2 };
const obj2 = { b: 3, c: 4 };
const merged = utile.mixin(obj1, obj2);
console.log(merged); // { a: 1, b: 3, c: 4 }

Asynchronous Flow Control

The 'async.parallel' function allows you to run multiple asynchronous tasks in parallel and collect their results once all tasks have completed.

const utile = require('utile');
const tasks = [
  function (callback) { setTimeout(() => callback(null, 'one'), 200); },
  function (callback) { setTimeout(() => callback(null, 'two'), 100); }
];
utile.async.parallel(tasks, function (err, results) {
  console.log(results); // ['one', 'two']
});

Other packages similar to utile

Readme

Source

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.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.

Remark: The util.inspect method is not exposed in utile until this issue is resolved.

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.

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
Author: Nodejitsu Inc.
Contributors: Charlie Robbins, Dominic Tarr
License: MIT

FAQs

Last updated on 08 Dec 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc