diff src/implab/text/format.js @ 34:27e8e9e38e07 default tip

Слияние
author nickolay
date Wed, 05 Jun 2019 20:44:15 +0300
parents 8af8e840dd49 1dc2fd263b90
children
line wrap: on
line diff
--- a/src/implab/text/format.js	Wed Jun 05 17:44:17 2019 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-define([
-    "../safe",
-    "./format-compile",
-    "dojo/number",
-    "dojo/date/locale",
-    "dojo/_base/array" ], function(safe, compile, number, date, array) {
-
-    // {short,medium,full,long}-{date,time}
-    var convert = function(value, pattern) {
-        if (!pattern)
-            return value.toString();
-
-        if (pattern.toLocaleLowerCase() == "json") {
-            var cache = [];
-            return JSON.stringify(value, function(k, v) {
-                if (!safe.isPrimitive(v)) {
-                    var id = array.indexOf(cache, v);
-                    if (id >= 0)
-                        return "@ref-" + id;
-                    else
-                        return v;
-                } else {
-                    return v;
-                }
-            },2);
-        }
-
-        if (safe.isNumber(value)) {
-            var nopt = {};
-            if (pattern.indexOf("!") === 0) {
-                nopt.round = -1;
-                pattern = pattern.substr(1);
-            }
-            nopt.pattern = pattern;
-            return number.format(value, nopt);
-        } else if (value instanceof Date) {
-            var m = pattern.match(/^(\w+)-(\w+)$/);
-            if (m)
-                return date.format(value, {
-                    selector : m[2],
-                    formatLength : m[1]
-                });
-            else if (pattern == "iso")
-                return value.toISOString();
-            else
-                return date.format(value, {
-                    selector : "date",
-                    datePattern : pattern
-                });
-        } else {
-            return value.toString(pattern);
-        }
-    };
-
-    function formatter(format) {
-        var data;
-
-        if (arguments.length <= 1)
-            return format;
-
-        data = Array.prototype.slice.call(arguments, 1);
-
-        var template = compile(format);
-
-        return template(function(name, pattern) {
-            var value = data[name];
-            return !safe.isNull(value) ? convert(value, pattern) : "";
-        });
-    }
-
-    formatter.compile = function(format) {
-        var template = compile(format);
-
-        return function() {
-            var data = arguments;
-
-            return template(function(name, pattern) {
-                var value = data[name];
-                return !safe.isNull(value) ? convert(value, pattern) : "";
-            });
-        };
-    };
-
-    formatter.convert = convert;
-
-    return formatter;
-});
\ No newline at end of file