🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

string-format

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-format - npm Package Compare versions

Comparing version

to
0.2.0

README.md

28

package.json
{
"name" : "string-format",
"description" : "Adds a `format` method to `String.prototype`. Inspired by Python's `str.format()`.",
"keywords" : ["string", "formatting", "language", "util"],
"homepage" : "https://bitbucket.org/davidchambers/string-format",
"bugs" : "https://bitbucket.org/davidchambers/string-format/issues",
"repository" : {"type": "hg", "url": "https://bitbucket.org/davidchambers/string-format"},
"author" : "David Chambers <dc@hashify.me>",
"main" : "string-format.js",
"version" : "0.1.0"
"name": "string-format",
"description": "Adds a `format` method to `String.prototype`. Inspired by Python's `str.format()`.",
"keywords": ["string", "formatting", "language", "util"],
"homepage": "https://github.com/davidchambers/string-format",
"bugs": "https://github.com/davidchambers/string-format/issues",
"repository": {
"type": "git",
"url": "https://github.com/davidchambers/string-format"
},
"author": "David Chambers <dc@hashify.me>",
"main": "string-format.js",
"version": "0.2.0",
"devDependencies": {
"coffee-script": "1.3.x",
"jessie": "0.4.x"
},
"scripts": {
"test": "node_modules/jessie/bin/jessie spec"
}
}

@@ -0,4 +1,5 @@

// Generated by CoffeeScript 1.3.3
(function() {
var format, lookup,
__slice = Array.prototype.slice;
var format, lookup, resolve,
__slice = [].slice;

@@ -20,16 +21,22 @@ format = String.prototype.format = function() {

return this.replace(/([{}])\1|[{](.*?)(?:!(.+?))?[}]/g, function(match, literal, key, transformer) {
var fn, value, _ref, _ref2, _ref3;
if (literal) return literal;
var fn, value, _ref, _ref1, _ref2;
if (literal) {
return literal;
}
if (key.length) {
explicit = true;
if (implicit) throw error('implicit', 'explicit');
if (implicit) {
throw error('implicit', 'explicit');
}
value = (_ref = lookup(args, key)) != null ? _ref : '';
} else {
implicit = true;
if (explicit) throw error('explicit', 'implicit');
value = (_ref2 = args[idx++]) != null ? _ref2 : '';
if (explicit) {
throw error('explicit', 'implicit');
}
value = (_ref1 = args[idx++]) != null ? _ref1 : '';
}
value = value.toString();
if (fn = format.transformers[transformer]) {
return (_ref3 = fn.call(value)) != null ? _ref3 : '';
return (_ref2 = fn.call(value)) != null ? _ref2 : '';
} else {

@@ -43,12 +50,26 @@ return value;

var match;
if (!/^(\d+)([.]|$)/.test(key)) key = '0.' + key;
if (!/^(\d+)([.]|$)/.test(key)) {
key = '0.' + key;
}
while (match = /(.+?)[.](.+)/.exec(key)) {
object = object[match[1]];
object = resolve(object, match[1]);
key = match[2];
}
return object[key];
return resolve(object, key);
};
resolve = function(object, key) {
var value;
value = object[key];
if (typeof value === 'function') {
return value.call(object);
} else {
return value;
}
};
format.transformers = {};
format.version = '0.2.0';
}).call(this);

Sorry, the diff of this file is not supported yet