format4js
Java's String.format() compatible string formatting library for JavaScript.
License
Install
Node.js
npm install format4js
;
HTML
Download files and add following into HTML.
Usage
The format4js extends String class to add format() method. You can call format() as static and instance method.
// static method: String.format("fmt", args...)var str = String; // instance method: "fmt".format(args...)var str = "5+5=%d";
If you want to know detail of supported format string syntax, please see JDK Reference.
Limitation
- No Locale support.
- Following conversions are not supported.
- %h, %H
- %tN, %TN
- %tZ, %TZ
- %tc, %Tc
Alternative Interfaces
The format4js behave as jQuery plugin.
// as jQuery pluginvar str = $;
You can also use this library as a standalone.
// as Standalone libraryvar str = mdgw;