Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

String.Extras substitutePath proto that can work with deep object pro…

…perties like .susbtitute
  • Loading branch information...
commit 3517a0297a8af255aa23dabadfeeff88ed090dbf 1 parent e63a0cd
@DimitarChristoff authored
Showing with 21 additions and 1 deletion.
  1. +21 −1 Source/Types/String.Extras.js
View
22 Source/Types/String.Extras.js
@@ -141,7 +141,27 @@ String.implement({
if (trail) string += trail;
}
return string;
- }
+ },
+
+ substitutePath: function(object, regexp) {
+ return String(this).replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name) {
+ if (match.charAt(0) == '\\') return match.slice(1);
+ if (object[name] != null) return object[name];
+
+ var retStr = "",
+ path = name.split('.'),
+ length = path.length,
+ sub = object;
+
+ if (length <= 1)
+ return retStr;
+
+ for (var i = 0; i < length; i++) {
+ if(!(sub = sub[path[i]])) return retStr;
+ }
+ return sub;
+ });
+ }
});
Please sign in to comment.
Something went wrong with that request. Please try again.