(v)sprintf -


未知
未知

软件简介

Implements both a somewhat stripped down “classic” version of the C sprintf
(no support for width, sign, padding and flags), and a python-like one
employing named parameters.

Why another implementation, when we already have one? well:

  • size : 2262 bytes;
  • features : I wanted named arguments, like in python;
  • license : the existing implementation uses a BSD license, I wanted GPL;
  • and fun , of course.

Usage

`//sprintf
//positional arguments
var classic = $.sprintf(‘%s %d%% %.3f’, ‘string’, 40, 3.141593);
// classic = ‘string 40% 3.142’

//named arguments
var named = $.sprintf(‘%(name)s: %(value)d’, {name: ‘age’, value: 40});
// named = ‘age: 40’

//vsprintf
var classic = $.vsprintf(‘%s %d%% %.3f’, [‘string’, 40, 3.141593]);
// classic = ‘string 40% 3.142’

//named arguments
var named = $.vsprintf(‘%(name)s: %(value)d’, [{name: ‘age’, value: 40}]);
// named = ‘age: 40’`