From 19170e692548d96bf1368793c0871d87c53b1934 Mon Sep 17 00:00:00 2001 From: j 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 9cb3b94..3c5a452 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 +};