mol-proto
Advanced tools
Comparing version 0.1.14 to 0.1.15
@@ -18,2 +18,3 @@ 'use strict'; | ||
* - [unPrefix](#unPrefix) | ||
* - [format](#format) | ||
*/ | ||
@@ -30,3 +31,4 @@ var stringMethods = module.exports = { | ||
hashCode: hashCode, | ||
unPrefix: unPrefix | ||
unPrefix: unPrefix, | ||
format: format | ||
}; | ||
@@ -188,1 +190,24 @@ | ||
} | ||
/** | ||
* Regex used to identify format vars | ||
* @type {RegExp} | ||
*/ | ||
var formatRegexp = /\$[0-9]+|\$\$/g; | ||
/** | ||
* String formatting utility to swap out tokens for variables. | ||
* @param {String} this The string to be formatted | ||
* @param {Array} args The values to be formatted | ||
* @return {String} The formatted string | ||
*/ | ||
function format() { // , ... arguments | ||
var str = this; | ||
var args = arguments; | ||
return str.replace(formatRegexp, function(item) { | ||
if (item == '$$') return '$'; | ||
item = item.slice(1); | ||
return args[item - 1]; | ||
}); | ||
}; |
@@ -101,2 +101,3 @@ 'use strict'; | ||
* - [unPrefix](proto_string.js.html#unPrefix) | ||
* - [format](proto_string.js.html#format) | ||
*/ | ||
@@ -103,0 +104,0 @@ var stringMethods = require('./proto_string'); |
{ | ||
"name": "mol-proto", | ||
"version": "0.1.14", | ||
"version": "0.1.15", | ||
"description": "ES5 object manipulation library for node and modern browsers", | ||
@@ -5,0 +5,0 @@ "main": "lib/proto.js", |
@@ -126,2 +126,3 @@ proto | ||
* [unPrefix](http://milojs.github.io/proto/proto_string.js.html#unPrefix) | ||
* [format](http://milojs.github.io/proto/proto_string.js.html#format) | ||
@@ -128,0 +129,0 @@ * [__Number functions__](http://milojs.github.io/proto/proto_number.js.html) |
@@ -103,2 +103,7 @@ 'use strict'; | ||
}); | ||
it('should define format function', function() { | ||
assert.equal(_.format('foo$1and$2bar$1', 'x', 'y'), 'fooxandybarx') | ||
assert.equal(_.format('this $1 is a $$ test', 'yo'), 'this yo is a $ test') | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
198149
4939
141
10