Comparing version 0.2.4 to 0.2.5
@@ -39,3 +39,2 @@ | ||
var Formatter = function(/*String*/ format){ | ||
var tokens = []; | ||
this._mapped = false; | ||
@@ -46,3 +45,3 @@ this._format = format; | ||
Formatter.prototype._re = /\%(?:\(([\w_]+)\)|([1-9]\d*)\$)?([0 +\-\#]*)(\*|\d+)?(\.)?(\*|\d+)?[hlL]?([\%bscdeEfFgGioOuxX])/g; | ||
Formatter.prototype._re = /\%(?:\(([\w_.]+)\)|([1-9]\d*)\$)?([0 +\-\#]*)(\*|\d+)?(\.)?(\*|\d+)?[hlL]?([\%bscdeEfFgGioOuxX])/g; | ||
Formatter.prototype._parseDelim = function(mapping, intmapping, flags, minWidth, period, precision, specifier){ | ||
@@ -131,3 +130,3 @@ if(mapping){ | ||
isObject: true | ||
}, | ||
} | ||
}; | ||
@@ -148,6 +147,15 @@ Formatter.prototype.format = function(/*mixed...*/ filler){ | ||
if(this._mapped){ | ||
if(typeof filler[token.mapping] == 'undefined'){ | ||
// Identify value of property defined in `token.mapping` | ||
var tokens = token.mapping.split('.'); | ||
var value = filler; | ||
for (var j = 0, c = tokens.length; j < c; j++) { | ||
value = value[tokens[j]]; | ||
if (typeof value === 'undefined') { | ||
break | ||
} | ||
} | ||
if(typeof value == 'undefined'){ | ||
throw new Error('missing key ' + token.mapping); | ||
} | ||
token.arg = filler[token.mapping]; | ||
token.arg = value; | ||
}else{ | ||
@@ -154,0 +162,0 @@ if(token.intmapping){ |
{ | ||
"name": "printf", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Full implementation of the `printf` family in pure JS.", | ||
@@ -5,0 +5,0 @@ "keywords": ["printf", "formatting", "sprintf", "format", "output", "print"], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28918
440