mirror of
https://github.com/samsonjs/format.git
synced 2026-03-25 08:45:53 +00:00
add package.json and readme
This commit is contained in:
parent
1470dc414d
commit
cac034c031
4 changed files with 78 additions and 14 deletions
18
LICENSE
Normal file
18
LICENSE
Normal file
|
|
@ -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.
|
||||
37
Readme.md
Normal file
37
Readme.md
Normal file
|
|
@ -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))
|
||||
|
|
@ -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;
|
||||
22
package.json
Normal file
22
package.json
Normal file
|
|
@ -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 <sami.samhuri@gmail.com>"
|
||||
, "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"
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in a new issue