string-format
Advanced tools
Comparing version
{ | ||
"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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
13146
29.73%7
16.67%69
43.75%1
-50%160
34.45%2
Infinity%1
Infinity%