From fae9a7e54174bd0b6d348b93f74325ea89784e0b Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 25 Nov 2010 12:47:42 +0100 Subject: [PATCH] add simple string formating --- build/js/ox.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/build/js/ox.js b/build/js/ox.js index 9cb3b94c..3c5a4522 100644 --- a/build/js/ox.js +++ b/build/js/ox.js @@ -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"; -}; \ No newline at end of file +};