Debian Codegraph @

dojox/dtl/filter/misc.js

raw symbols SCIP
1 define([
2 "dojo/_base/lang",
3 "dojo/_base/json", // dojo.toJson
4 "../_base"
5 ], function(lang,json,dd){
6
7 var misc = lang.getObject("filter.misc", true, dd);
8 /*=====
9 misc = {
10 // TODO: summary
11 };
12 =====*/
13
14 lang.mixin(misc, {
15 filesizeformat: function(value){
16 // summary:
17 // Format the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB, 102bytes, etc).
18 value = parseFloat(value);
19 if(value < 1024){
20 return (value == 1) ? value + " byte" : value + " bytes";
21 }else if(value < 1024 * 1024){
22 return (value / 1024).toFixed(1) + " KB";
23 }else if(value < 1024 * 1024 * 1024){
24 return (value / 1024 / 1024).toFixed(1) + " MB";
25 }
26 return (value / 1024 / 1024 / 1024).toFixed(1) + " GB";
27 },
28 pluralize: function(value, arg){
29 // summary:
30 // Returns a plural suffix if the value is not 1, for '1 vote' vs. '2 votes'
31 // description:
32 // By default, 's' is used as a suffix; if an argument is provided, that string
33 // is used instead. If the provided argument contains a comma, the text before
34 // the comma is used for the singular case.
35 arg = arg || 's';
36 if(arg.indexOf(",") == -1){
37 arg = "," + arg;
38 }
39 var parts = arg.split(",");
40 if(parts.length > 2){
41 return "";
42 }
43 var singular = parts[0];
44 var plural = parts[1];
45
46 if(parseInt(value, 10) != 1){
47 return plural;
48 }
49 return singular;
50 },
51 _phone2numeric: { a: 2, b: 2, c: 2, d: 3, e: 3, f: 3, g: 4, h: 4, i: 4, j: 5, k: 5, l: 5, m: 6, n: 6, o: 6, p: 7, r: 7, s: 7, t: 8, u: 8, v: 8, w: 9, x: 9, y: 9 },
52 phone2numeric: function(value){
53 // summary:
54 // Takes a phone number and converts it in to its numerical equivalent
55 var dm = dd.filter.misc;
56 value = value + "";
57 var output = "";
58 for(var i = 0; i < value.length; i++){
59 var chr = value.charAt(i).toLowerCase();
60 (dm._phone2numeric[chr]) ? output += dm._phone2numeric[chr] : output += value.charAt(i);
61 }
62 return output;
63 },
64 pprint: function(value){
65 // summary:
66 // A wrapper around toJson unless something better comes along
67 return json.toJson(value);
68 }
69 });
70
71 return misc;
72 });