Socket
Socket
Sign inDemoInstall

util

Package Overview
Dependencies
1
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    util

Node.JS util module


Version published
Weekly downloads
25M
decreased by-18.71%
Maintainers
1
Install size
46.2 kB
Created
Weekly downloads
 

Package description

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

Readme

Source

util

Build Status

node.js util module as a module

install via npm

npm install util

browser support

This module also works in modern browsers. If you need legacy browser support you will need to polyfill ES5 features.

Keywords

FAQs

Last updated on 20 Dec 2013

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc