From cac034c0310831ce02518f5476a57c15d593d4d8 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Thu, 11 Nov 2010 14:46:45 -0800 Subject: [PATCH] add package.json and readme --- LICENSE | 18 ++++++++++++++++++ Readme.md | 37 +++++++++++++++++++++++++++++++++++++ format.js => lib/index.js | 15 +-------------- package.json | 22 ++++++++++++++++++++++ 4 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 LICENSE create mode 100644 Readme.md rename format.js => lib/index.js (82%) create mode 100644 package.json diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c37eb40 --- /dev/null +++ b/LICENSE @@ -0,0 +1,18 @@ +Copyright 2010 Sami Samhuri. All rights reserved. +Permission 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: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE 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. diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..b19cb8e --- /dev/null +++ b/Readme.md @@ -0,0 +1,37 @@ +format +====== + +printf and sprintf for JavaScript + + +Installation +============ + +npm install format + + +Usage +===== + + var Format = require('format') + , printf = Format.printf + , format = Format.format // aliased as sprintf as well + + // Print 'hello world' + printf('%s world', 'hello') + + var what = 'life, the universe, and everything' + format('%d is the answer to %s', 42, what) + // => '42 is the answer to life, the universe, and everything' + +Supported format specifiers: b, c, d, f, o, s, x, and X. + +See `man 3 printf` or `man 1 printf` for details. + + +License +======= + +Copyright 2010 Sami Samhuri sami.samhuri@gmail.com + +MIT (see included [LICENSE](/samsonjs/format/blob/master/LICENSE)) diff --git a/format.js b/lib/index.js similarity index 82% rename from format.js rename to lib/index.js index fc588e6..8047c12 100644 --- a/format.js +++ b/lib/index.js @@ -6,24 +6,10 @@ // ISC license // -exports.extendNativeStrings = function() { - String.prototype.printf = function(/* ... */) { - var args = [].slice.call(arguments); - if (args[0] !== this) args.unshift(this); - console.log(exports.format.apply(this, args)); - }; - String.prototype.format = function(/* ... */) { - var args = [].slice.call(arguments); - if (args[0] !== this) args.unshift(this); - return exports.format.apply(this, args); - }; -}; - exports.printf = function(/* ... */) { console.log(exports.format.apply(this, arguments)); }; -exports.sprintf = exports.format exports.format = function(format) { var argIndex = 1 // skip initial format argument , args = [].slice.call(arguments) @@ -88,3 +74,4 @@ exports.format = function(format) { } return result; }; +exports.sprintf = exports.format; diff --git a/package.json b/package.json new file mode 100644 index 0000000..8911cc7 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ "name" : "format" +, "description" : "printf and sprintf for JavaScript" +, "version" : "0.1.0" +, "homepage" : "http://samhuri.net/node/format" +, "author" : "Sami Samhuri " +, "repository" : + { "type" : "git" + , "url" : "http://github.com/samsonjs/format.git" + } +, "bugs" : + { "mail" : "sami.samhuri+format@gmail.com" + , "web" : "http://github.com/samsonjs/format/issues" + } +, "directories" : { "lib" : "./lib" } +, "main" : "./lib/index" +, "engines" : { "node" : ">=0.3.0" } +, "licenses" : + [ { "type" : "MIT" + , "url" : "http://github.com/samsonjs/format/raw/master/LICENSE" + } + ] +} \ No newline at end of file