MCPcopy
hub / github.com/adobe-webplatform/Snap.svg / replacer

Function replacer

src/svg.js:214–227  ·  view source on GitHub ↗
(all, key, obj)

Source from the content-addressed store, hash-verified

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);

Callers 1

svg.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected