1.3.0 • Published 8 years ago

esprintf v1.3.0

Weekly downloads
4
License
BSD-2-Clause
Repository
github
Last release
8 years ago

esprintf

NPM

Build Status Dependencies Coverage Status npm version

Requirements & Installation

Just run npm install esprintf

Usage

The following formatters are supported:

  • b Binary
  • d & i Decimial
  • u Unsigned int
  • o Octal
  • x Lowercase hexadecimal
  • X Uppercase hexadecimal
  • f Floating point number using locale
  • F Floating point number
  • e Expontential representation using locale
  • E Expontential representation
  • g Shortest of both f and e
  • G Shortest of both F and E
  • a Lowercase hexadecimal floating point
  • A Uppercase hexadecimal floating point
  • c Character
  • s String
  • j JSON

All regular sprintf operations are supported:

  • Padding/Truncation length and content specification
  • Dynamic length and precision
  • Forced prefix/sign
  • Left justification

Furthermore this function supports index based and associative replacement:

Please see the tests for more info.

Please note that mixing regular and index based replacement is possible but NOT recommended as it's messy, mixing regular or index based with associate replacement is NOT possible.

JSON formatting special:

I added JSON formatting for convenience reasons(because I could), in order to use prettyfied json you need to pass the padding specifier eg.

console.log(esprintf('%\'\tj', {
	hello: 'world'
}));

Will result in:

{
	"hello":	"world"
}

It also supports template strings:

esprintf`%.2${42.4242}f`;

Will result in:

42.42

1.3.0

8 years ago

1.1.1

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago