Socket
Socket
Sign inDemoInstall

sprintf

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sprintf

Sprintf() for node.js


Version published
Weekly downloads
119K
increased by16.79%
Maintainers
1
Weekly downloads
 
Created

What is sprintf?

The sprintf npm package is a JavaScript implementation of the sprintf function from the C programming language. It allows for formatted string creation using a format string and a list of arguments. This is useful for creating strings with dynamic content in a structured and readable way.

What are sprintf's main functionalities?

Basic String Formatting

This feature allows you to insert variables into a string using placeholders. In this example, '%s' is a placeholder for a string, and 'world' is the value that gets inserted.

const sprintf = require('sprintf-js').sprintf;
const formattedString = sprintf('Hello %s!', 'world');
console.log(formattedString); // Output: Hello world!

Number Formatting

This feature allows you to format numbers within a string. In this example, '%d' is a placeholder for an integer, and '42' is the value that gets inserted.

const sprintf = require('sprintf-js').sprintf;
const formattedNumber = sprintf('The number is %d.', 42);
console.log(formattedNumber); // Output: The number is 42.

Floating Point Formatting

This feature allows you to format floating-point numbers to a specified number of decimal places. In this example, '%.2f' formats the number to two decimal places.

const sprintf = require('sprintf-js').sprintf;
const formattedFloat = sprintf('The value is %.2f.', 3.14159);
console.log(formattedFloat); // Output: The value is 3.14.

Padding and Alignment

This feature allows you to pad and align strings within a specified width. In this example, '%10s' pads the string 'test' to a total width of 10 characters, aligning it to the right.

const sprintf = require('sprintf-js').sprintf;
const formattedString = sprintf('%10s', 'test');
console.log(formattedString); // Output: '      test'

Other packages similar to sprintf

FAQs

Package last updated on 03 Dec 2014

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