add simple string formating
This commit is contained in:
parent
666750c855
commit
19170e6925
|
@ -1174,6 +1174,16 @@ Encoding functions
|
|||
Format functions
|
||||
================================================================================
|
||||
*/
|
||||
Ox.format = function (s, args) {
|
||||
/* Python(ish) string formatting:
|
||||
* >>> format('{0}', ['zzz'])
|
||||
* "zzz"
|
||||
* >>> format('{x}', {x: 1})
|
||||
* "1"
|
||||
*/
|
||||
var re = /\{([^}]+)\}/g;
|
||||
return s.replace(re, function(_, match){ return args[match]; });
|
||||
}
|
||||
|
||||
Ox.formatDate = function() {
|
||||
/*
|
||||
|
@ -1890,4 +1900,4 @@ Ox.isUndefined = function(val) {
|
|||
true
|
||||
*/
|
||||
return typeof val == "undefined";
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user