Skip to content

madogiwa/format4js

Repository files navigation

format4js

npm version Build Status

Java's String.format() compatible string formatting library for JavaScript.

License

MIT License

Install

Node.js

npm install format4js
require('format4js');

HTML

Download files and add following into HTML.

<script src="format4js.js"></script>

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.format("5+5=%d", 10);

// instance method: "fmt".format(args...)
var str = "5+5=%d".format(10);

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 plugin
var str = $.format('5+5=%d', 10);

You can also use this library as a standalone.

// as Standalone library
var str = mdgw.format('5+5=%d', 10);

About

Java's String.format() compatible string formatting library for JavaScript.

Resources

Stars

Watchers

Forks

Packages

No packages published