Is there a sprintf equivalent for node.js

We are looking for output formatting (functionality like sprintf) in node.js, but before I write it myself, I was wondering if there was something like this built-in (I was wasting documents to no avail) or if someone had already written a module.

Thank you very much

+49
printf
Apr 23 '10 at 10:50
source share
4 answers

Now, util.format() has printf -like support.

Example:

 util.format('hello %s', 'world'); // Returns: 'hello world' 
+55
Dec 02 2018-11-12T00:
source share

There are a couple in the npm registry:

+21
Aug 16 '11 at 13:20
source share

Here is the javascript sprintf version:

http://phpjs.org/functions/sprintfโ–บ22

+6
Apr 23 '10 at 10:52
source share

console.log works fine.

 console.log('%d hours', 4); // 4 hours console.log('The %2$s contains %1$d monkeys', 4, 'tree'); // The tree contains 4 monkeys 
+5
Jun 29 '13 at 13:43 on
source share



All Articles