{"_id":"stringformat","_rev":"56703","name":"stringformat","description":"Simple format method for String","dist-tags":{"latest":"0.0.5"},"maintainers":[{"name":"jcayzac","email":"julien.cayzac@gmail.com"}],"time":{"modified":"2021-06-03T10:17:16.000Z","created":"2012-02-19T09:22:29.013Z","0.0.5":"2012-02-22T10:05:31.627Z","0.0.4":"2012-02-19T12:00:35.462Z","0.0.3":"2012-02-19T11:44:07.692Z","0.0.2":"2012-02-19T09:35:37.866Z","0.0.1":"2012-02-19T09:22:29.013Z"},"users":{"fgribreau":true},"author":{"name":"Julien Cayzac","email":"julien.cayzac@gmail.com","url":"http://julien.cayzac.name/"},"repository":{"type":"git","url":"git://github.com/jcayzac/stringformat.js.git"},"versions":{"0.0.5":{"name":"stringformat","description":"Simple format method for String","homepage":"https://github.com/jcayzac/stringformat.js","keywords":["string","format","template","util","functional","server","client","browser"],"author":{"name":"Julien Cayzac","email":"julien.cayzac@gmail.com","url":"http://julien.cayzac.name/"},"repository":{"type":"git","url":"git://github.com/jcayzac/stringformat.js.git"},"main":"index.js","version":"0.0.5","engines":{"node":">=0.4"},"devDependencies":{"mocha":"0.12.1"},"scripts":{"test":"node_modules/mocha/bin/mocha --ui exports --reporter list test.js"},"_npmUser":{"name":"jcayzac","email":"julien.cayzac@gmail.com"},"_id":"stringformat@0.0.5","dependencies":{},"optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.0-3","_nodeVersion":"v0.6.10","_defaultsLoaded":true,"dist":{"shasum":"83c2fecbd766dd456f942e4f6af8061bffd87f12","size":4735,"noattachment":false,"key":"/stringformat/-/stringformat-0.0.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/stringformat/download/stringformat-0.0.5.tgz"},"maintainers":[{"name":"jcayzac","email":"julien.cayzac@gmail.com"}],"directories":{},"publish_time":1329905131627,"_cnpm_publish_time":1329905131627,"_hasShrinkwrap":false,"deprecated":"This package has been rendered useless by string literals, and may present unknown vulnerabilities. Please stop depending on it."},"0.0.4":{"name":"stringformat","description":"Simple format method for String","homepage":"https://github.com/jcayzac/stringformat.js","keywords":["string","format","template","util","functional","server","client","browser"],"author":{"name":"Julien Cayzac","email":"julien.cayzac@gmail.com"},"repository":{"type":"git","url":"git://github.com/jcayzac/stringformat.js.git"},"main":"index.js","version":"0.0.4","devDependencies":{"mocha":"*"},"scripts":{"test":"node_modules/mocha/bin/mocha --ui exports --reporter list test.js"},"_npmUser":{"name":"jcayzac","email":"julien.cayzac@gmail.com"},"_id":"stringformat@0.0.4","dependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.0-3","_nodeVersion":"v0.6.10","_defaultsLoaded":true,"dist":{"shasum":"52f2a25b13df3d7f0aa145cae7e8bce835450c49","size":4574,"noattachment":false,"key":"/stringformat/-/stringformat-0.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/stringformat/download/stringformat-0.0.4.tgz"},"maintainers":[{"name":"jcayzac","email":"julien.cayzac@gmail.com"}],"directories":{},"publish_time":1329652835462,"_cnpm_publish_time":1329652835462,"_hasShrinkwrap":false,"deprecated":"This package has been rendered useless by string literals, and may present unknown vulnerabilities. Please stop depending on it."},"0.0.3":{"name":"stringformat","description":"Simple format method for String","homepage":"https://github.com/jcayzac/stringformat.js","keywords":["string","format","template","util","functional","server","client","browser"],"author":{"name":"Julien Cayzac","email":"julien.cayzac@gmail.com"},"repository":{"type":"git","url":"git://github.com/jcayzac/stringformat.js.git"},"main":"index.js","version":"0.0.3","devDependencies":{"mocha":"*"},"scripts":{"test":"node_modules/mocha/bin/mocha --ui exports --reporter list test.js"},"_npmUser":{"name":"jcayzac","email":"julien.cayzac@gmail.com"},"_id":"stringformat@0.0.3","dependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.0-3","_nodeVersion":"v0.6.10","_defaultsLoaded":true,"dist":{"shasum":"feb5e11a90acf3ddde780e633266d3037003d665","size":4564,"noattachment":false,"key":"/stringformat/-/stringformat-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/stringformat/download/stringformat-0.0.3.tgz"},"maintainers":[{"name":"jcayzac","email":"julien.cayzac@gmail.com"}],"directories":{},"publish_time":1329651847692,"_cnpm_publish_time":1329651847692,"_hasShrinkwrap":false,"deprecated":"This package has been rendered useless by string literals, and may present unknown vulnerabilities. Please stop depending on it."},"0.0.2":{"name":"stringformat","description":"Simple format method for String","homepage":"https://github.com/jcayzac/stringformat.js","keywords":["string","format","template","util","functional","server","client","browser"],"author":{"name":"Julien Cayzac","email":"julien.cayzac@gmail.com"},"repository":{"type":"git","url":"git://github.com/jcayzac/stringformat.js.git"},"main":"index.js","version":"0.0.2","devDependencies":{"mocha":"*"},"_npmUser":{"name":"jcayzac","email":"julien.cayzac@gmail.com"},"_id":"stringformat@0.0.2","dependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.0-3","_nodeVersion":"v0.6.10","_defaultsLoaded":true,"dist":{"shasum":"fabaf856743c7efaf3254cf1c9572cdaa88cd91d","size":4112,"noattachment":false,"key":"/stringformat/-/stringformat-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/stringformat/download/stringformat-0.0.2.tgz"},"maintainers":[{"name":"jcayzac","email":"julien.cayzac@gmail.com"}],"directories":{},"publish_time":1329644137866,"_cnpm_publish_time":1329644137866,"_hasShrinkwrap":false,"deprecated":"This package has been rendered useless by string literals, and may present unknown vulnerabilities. Please stop depending on it."},"0.0.1":{"name":"stringformat","description":"Simple format method for String","homepage":"https://github.com/jcayzac/stringformat.js","keywords":["string","format","template","util","functional","server","client","browser"],"author":{"name":"Julien Cayzac","email":"julien.cayzac@gmail.com"},"repository":{"type":"git","url":"git://github.com/jcayzac/stringformat.js.git"},"main":"index.js","version":"0.0.1","devDependencies":{"mocha":"*"},"_npmUser":{"name":"jcayzac","email":"julien.cayzac@gmail.com"},"_id":"stringformat@0.0.1","dependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.0-3","_nodeVersion":"v0.6.10","_defaultsLoaded":true,"dist":{"shasum":"aa67e6cee7ab987f5303bae30bbfb5a5bf571583","size":4111,"noattachment":false,"key":"/stringformat/-/stringformat-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/stringformat/download/stringformat-0.0.1.tgz"},"maintainers":[{"name":"jcayzac","email":"julien.cayzac@gmail.com"}],"directories":{},"publish_time":1329643349013,"_cnpm_publish_time":1329643349013,"_hasShrinkwrap":false,"deprecated":"This package has been rendered useless by string literals, and may present unknown vulnerabilities. Please stop depending on it."}},"readme":"# StringFormat\n## Description\nThis module provides a simple function that can be used to format strings,\nusing replacements such as {0}, {foo}, etc.\n\n## Features\n* Node/browser compatible.\n* Order-independent replacements, so that format strings can be localized.\n    * Example: `Hello {firstname} {lastname}` in English, `こんにちは、{lastname}{firstname}さん` in Japanese.\n* Can pass one or several objects, and use property names instead of numbers.\n* Support modifiers to output values as integers or JSON.\n* Opt-in `String.prototype` extension (using `extendString()`)\n\n## Install\n\n```\nnpm install stringformat\n```\n\n## API\n### format(*format string*, *parameters*...)\nReturns a new string formatted according to *format string*.\n\n#### Example usage:\n```js\nvar $ = require('stringformat')\nconsole.log($.format(\"Hello, {0}!\", \"World\"))\n```\n\n…would output `Hello, World!` to the console.\n\n### extendString([*methodName*])\nInstalls the module as `String.prototype.methodName`.\nIf omitted, *methodName* defaults to **format**.\n\n#### Example usage:\n```js\nvar $ = require('stringformat')\n\n$.extendString('coolFormat')\nconsole.log(\"Hello, {0}!\".coolFormat(\"World\"))\n```\n\n…would output `Hello, World!` to the console.\n\n## Format strings syntax\n### Basic replacements\nThe most simple replacements look like `{0}`, `{1}` and so on.\nThe number is the index of the parameter.\n\n```js\n\"Hello, {1}! I feed {0} today!\".format(\"great\", \"World\")\n'Hello, World! I feed great today!'\n```\n\nYou can also use functions:\n\n```js\n\"Hello, {1}! I feed {0} today!\".format(\"great\", function() { return \"World\" })\n'Hello, World! I feed great today!'\n```\n\n```js\nvar x = 0\n\"{0} {0} {0}…\".format(function() { return ++x })\n'1 2 3…'\n```\n\nIf a replacement cannot be resolved, the method does nothing:\n\n```js\n\"Hello, {1}! I feed {0} today!\".format(\"great\")\n'Hello, {1}! I feed great today!'\n```\n\n### Padding\nIf you can to pad the result, for instance to print a list of values, you can do it like this:\n\n```js\n\"User name: [{0:20}]\".format(\"Bob Harris\")\n'User name: [          Bob Harris]'\n```\n\n…this gives you a replaced content that is at least 20 characters wide. Positive integers mean the value will get right-aligned. To align it to the left, use a negative value:\n\n```js\n\"User name: [{0:-20}]\".format(\"Bob Harris\")\n'User name: [Bob Harris          ]'\n```\n\n### The JSON modifier\nIf you want to output a JSON version of the value, you can use it with the **j** modifier.\nCompare the output above with the one below:\n\n```js\n\"User name: {0:j}\".format(\"Bob Harris\")\n'User name: \"Bob Harris\"'\n```\n\nOf course you can use objects slightly more complex than a string:\n\n```js\n\"User name: {0:j}\".format({foo:{bar:1}})\n'User name: {\"foo\":{\"bar\":1}}'\n```\n\n…or even a function:\n\n```js\n\"User name: {0:j}\".format(function() { return {foo:{bar:1}} })\n'User name: {\"foo\":{\"bar\":1}}'\n```\n\n### The integer modifier\nIf you want to output integer values only, use the **i** modifier.\nFloating values will get rounded, and values that are not numbers will output `NaN`.\n\n```js\n\"value = {0:i}\".format(12.5)\n'value = 13'\n```\n\n```js\n\"[value:{0:4i}]\".format(12.5)\n'[value:  13]'\n```\n\n```js\n\"[value:{0:4i}]\".format(\"foo\")\n'[value: NaN]'\n```\n\n```js\n\"[value:{0:4i}]\".format()\n'[value: NaN]'\n```\n\n```js\n\"[value:{0:4i}]\".format(function() { var undef; return undef })\n'[value: NaN]'\n```\n\nAs an exception to the rule mentioned above,\n\n> If a replacement cannot be resolved, the method does nothing\n\n…if the integer modifier is specified, unresolved replacements will result in a `NaN`\nbeing outputted.\n\n### Named properties\nYou can also use names instead of indexes.\n\n```js\n\"[{foo:-4i}]\".format({foo:1})\n'[1   ]'\n```\n\n```js\n\"[{foo.bar:-4i}]\".format({foo:{bar:1}})\n'[1   ]'\n```\n\n```js\n\"The string {0:j} is {length}-character long\".format(\"Hello, World!\")\n'The string \"Hello, World!\" is 13-character long'\n```\n\n```js\nvar Foo = function() {\n\tthis.foo = 1\n}\n\"[{foo:-4i}]\".format(new Foo)\n'[1   ]'\n```\n\n```js\nvar Foo = function() {\n\tthis.foo = 1\n}\nFoo.prototype.bar = function() { return this.foo + 1 }\n\"[{bar:-4i}]\".format(new Foo)\n'[2   ]'\n```\n\nIf you specify a property as `foo.bar.baz` and `baz` is a function,\n`this` will be equal to `foo.bar` when it gets called.\n\n### Accessing properties from multiple objects\nEach replacement can be prefixed with an object index followed by a pipe symbol.\n\n```js\n\"[{0|foo.bar:4}] [{1|foo.bar:4}]\".format({foo:{bar:4}}, {foo:{bar:8}})\n'[   4] [   8]'\n```\n\n### Escaping\nReplacement specifiers can be escaped by doubling the opening and closing braces:\n\n```js\n\"{{0}} is [{0}]\".format(1)\n'{0} is [1]'\n```\n\n## License\n(The MIT License)\n\nCopyright (c) 2012 Julien Cayzac <julien.cayzac@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_attachments":{},"homepage":"https://github.com/jcayzac/stringformat.js"}