mirror of
https://github.com/samsonjs/format.git
synced 2026-03-25 08:45:53 +00:00
s/sys.puts/console.log/ and add sprintf alias
This commit is contained in:
parent
a7a1043d59
commit
1470dc414d
1 changed files with 6 additions and 11 deletions
17
format.js
17
format.js
|
|
@ -6,32 +6,27 @@
|
|||
// ISC license
|
||||
//
|
||||
|
||||
var sys = require('sys');
|
||||
|
||||
function $args(args) {
|
||||
return Array.prototype.slice.call(args);
|
||||
}
|
||||
|
||||
exports.extendNativeStrings = function() {
|
||||
String.prototype.printf = function(/* ... */) {
|
||||
var args = $args(arguments);
|
||||
var args = [].slice.call(arguments);
|
||||
if (args[0] !== this) args.unshift(this);
|
||||
sys.puts(exports.format.apply(this, args));
|
||||
console.log(exports.format.apply(this, args));
|
||||
};
|
||||
String.prototype.format = function(/* ... */) {
|
||||
var args = $args(arguments);
|
||||
var args = [].slice.call(arguments);
|
||||
if (args[0] !== this) args.unshift(this);
|
||||
return exports.format.apply(this, args);
|
||||
};
|
||||
};
|
||||
|
||||
exports.printf = function(/* ... */) {
|
||||
sys.puts(exports.format.apply(this, arguments));
|
||||
console.log(exports.format.apply(this, arguments));
|
||||
};
|
||||
|
||||
exports.sprintf = exports.format
|
||||
exports.format = function(format) {
|
||||
var argIndex = 1 // skip initial format argument
|
||||
, args = $args(arguments)
|
||||
, args = [].slice.call(arguments)
|
||||
, i = 0
|
||||
, n = format.length
|
||||
, result = ''
|
||||
|
|
|
|||
Loading…
Reference in a new issue