Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

util

Package Overview
Dependencies
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

util

Node.JS util module

  • 0.10.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
37M
increased by10.95%
Maintainers
3
Weekly downloads
 
Created

What is util?

The 'util' package is a core Node.js module that provides utilities for programmatic use in JavaScript. It includes a collection of helper functions for various tasks such as formatting strings, inspecting objects, and using inheritance.

What are util's main functionalities?

format

Formats a string using placeholders and returns it. Similar to printf in C.

const util = require('util');
console.log(util.format('%s:%s', 'foo', 'bar', 'baz')); // 'foo:bar baz'

inspect

Returns a string representation of an object for debugging purposes, with options to show hidden properties and control the depth of inspection.

const util = require('util');
console.log(util.inspect({ foo: 'bar' }, { showHidden: false, depth: null }));

inherits

Allows one constructor to inherit the prototype methods from another, a utility for implementing object-oriented inheritance.

const util = require('util');
function Base() {}
function Derived() {}
util.inherits(Derived, Base);

promisify

Converts a callback-based function to a function that returns a promise, facilitating the use of async/await.

const util = require('util');
const fs = require('fs');
const readFileAsync = util.promisify(fs.readFile);
readFileAsync('example.txt', 'utf8').then(console.log).catch(console.error);

Other packages similar to util

Keywords

FAQs

Package last updated on 03 Jun 2018

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc