Coder Social home page Coder Social logo

esprintf's Introduction

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

esprintf's People

Contributors

simonschick avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.