summaryrefslogtreecommitdiffstats
path: root/js/vendor/angular-ui/modules/filters/format/format.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/vendor/angular-ui/modules/filters/format/format.js')
-rw-r--r--js/vendor/angular-ui/modules/filters/format/format.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/js/vendor/angular-ui/modules/filters/format/format.js b/js/vendor/angular-ui/modules/filters/format/format.js
new file mode 100644
index 000000000..cedd3fb84
--- /dev/null
+++ b/js/vendor/angular-ui/modules/filters/format/format.js
@@ -0,0 +1,34 @@
+
+/**
+ * A replacement utility for internationalization very similar to sprintf.
+ *
+ * @param replace {mixed} The tokens to replace depends on type
+ * string: all instances of $0 will be replaced
+ * array: each instance of $0, $1, $2 etc. will be placed with each array item in corresponding order
+ * object: all attributes will be iterated through, with :key being replaced with its corresponding value
+ * @return string
+ *
+ * @example: 'Hello :name, how are you :day'.format({ name:'John', day:'Today' })
+ * @example: 'Records $0 to $1 out of $2 total'.format(['10', '20', '3000'])
+ * @example: '$0 agrees to all mentions $0 makes in the event that $0 hits a tree while $0 is driving drunk'.format('Bob')
+ */
+angular.module('ui.filters').filter('format', function(){
+ return function(value, replace) {
+ if (!value) {
+ return value;
+ }
+ var target = value.toString(), token;
+ if (replace === undefined) {
+ return target;
+ }
+ if (!angular.isArray(replace) && !angular.isObject(replace)) {
+ return target.split('$0').join(replace);
+ }
+ token = angular.isArray(replace) && '$' || ':';
+
+ angular.forEach(replace, function(value, key){
+ target = target.split(token+key).join(value);
+ });
+ return target;
+ };
+});