add simple string formating
This commit is contained in:
parent
df324f8efa
commit
fae9a7e541
1 changed files with 11 additions and 1 deletions
|
@ -1174,6 +1174,16 @@ Encoding functions
|
||||||
Format 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() {
|
Ox.formatDate = function() {
|
||||||
/*
|
/*
|
||||||
|
@ -1890,4 +1900,4 @@ Ox.isUndefined = function(val) {
|
||||||
true
|
true
|
||||||
*/
|
*/
|
||||||
return typeof val == "undefined";
|
return typeof val == "undefined";
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue