| 212 | var tokenRegex = /\{([^\}]+)\}/g, |
| 213 | objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g, // matches .xxxxx or ["xxxxx"] to run over object properties |
| 214 | replacer = function (all, key, obj) { |
| 215 | var res = obj; |
| 216 | key.replace(objNotationRegex, function (all, name, quote, quotedName, isFunc) { |
| 217 | name = name || quotedName; |
| 218 | if (res) { |
| 219 | if (name in res) { |
| 220 | res = res[name]; |
| 221 | } |
| 222 | typeof res == "function" && isFunc && (res = res()); |
| 223 | } |
| 224 | }); |
| 225 | res = (res == null || res == obj ? all : res) + ""; |
| 226 | return res; |
| 227 | }; |
| 228 | return function (str, obj) { |
| 229 | return Str(str).replace(tokenRegex, function (all, key) { |
| 230 | return replacer(all, key, obj); |