Socket
Socket
Sign inDemoInstall

fast-format

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-format

A fast, simple string formatter like util.format() method in Node.js


Version published
Weekly downloads
20
decreased by-37.5%
Maintainers
1
Weekly downloads
 
Created
Source

fast-format

Circle CI

This is a string formatter like util.format() method in Node.js, supports just only %s placeholder but accordingly faster than that. It will be one of the best solution if need a speed rather than complex formatting.

Usage

Same as util.format() method.

format(formatString[, ...])

If use one formatting repeatedly, recommended to compile the formatString in advance.

format.compile(formatString)

Example

let s = format('%s, %s!', 'Hello', 'world');
console.log(s);     // => 'Hello, world!'
let f = format.compile('%s, %s!');
let s1 = f('Hello', 'world');
console.log(s1);    // => 'Hello, world!'
let s2 = f('Howdy', 'World');
console.log(s2);    // => 'Howdy, World!'

Benchmark

// Bench 1
let s = Date.now();
for (let i = 0, len = 100000000; i < len; i++) {
    format('i = %s, len = %s', i, len);
}
console.log(Date.now() - s);
// Bench 2
let s = Date.now();
let f = format.compile('i = %s, len = %s');
for (let i = 0, len = 100000000; i < len; i++) {
    f(i, len);
}
console.log(Date.now() - s);

environment1: Core i7 2.2GHz + Node.js v6.9.5

moduletimebench
fast-format12,388 msec2
fast-format22,039 msec1
util.format28,659 msec1

environment2: Core i7 2.2GHz + Google Chrome 56.0.2924.87

moduletimebench
fast-format12,898 msec2
fast-format22,705 msec1
util.format99,103 msec1

The util.format() method was converted with Browserify to run on the browser.

Installation

via npm

npm install fast-format --save

via Bower

bower install fast-format

directly (in case of the browser)

<script src="/path/to/fast-format.min.js"></script>

Browser Support

Google Chrome, Firefox, Safari, Opera, Microsoft Edge and IE 6+

License

MIT

Keywords

FAQs

Package last updated on 05 Feb 2017

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