blob: 1ded27ed9e1fac9d7469b36a23c01661e65dbf4a [file] [log] [blame]
Scott Baker999edc62014-06-18 15:40:56 -07001// Try Mongo
2//
3// Copyright (c) 2009 Kyle Banker
4// Licensed under the MIT licence.
5// http://www.opensource.org/licenses/mit-license.php
6
Scott Baker38e2cea2014-06-18 19:02:37 -07007// extending array like this is breaking datatables
8
9/*Array.prototype.include = function(value) {
Scott Baker999edc62014-06-18 15:40:56 -070010 for(var i=0; i < this.length; i++) {
11 if(this[i] == value) {
12 return this[i];
13 }
14 }
15 return false;
16};
17
18Array.prototype.empty = function() {
19 return (this.length == 0);
Scott Baker38e2cea2014-06-18 19:02:37 -070020};*/
21
22function ArrayInclude(arr,value) {
23 for(var i=0; i < arr.length; i++) {
24 if(arr[i] == value) {
25 return arr[i];
26 }
27 }
28 return false;
Scott Baker999edc62014-06-18 15:40:56 -070029};
30
31Function.prototype.bind = function() {
32 var __method = this, object = arguments[0], args = [];
33
34 for(i = 1; i < arguments.length; i++) {
35 args.push(arguments[i]);
36 }
37
38 return function() {
39 return __method.apply(object, args);
40 };
41};
42
43String.prototype.trim = function() {
44 return this.replace(/^\s+|\s+$/g,"");
45};
46
47// Prints javascript types as readable strings.
48Inspect = function(obj) {
49 if(typeof(obj) != 'object') {
50 return obj;
51 }
52
53 else if (obj instanceof Array) {
54 var objRep = [];
55 for(var prop in obj) {
56 if(obj.hasOwnProperty(prop)) {
57 objRep.push(obj[prop]);
58 }
59 }
60 return '[' + objRep.join(', ') + ']';
61 }
62
63 else {
64 var objRep = [];
65 for(var prop in obj) {
66 if(obj.hasOwnProperty(prop)) {
67 objRep.push(prop + ': ' + ((typeof(obj[prop]) == 'object') ? Inspect(obj[prop]) : obj[prop]));
68 }
69 }
70 return '{' + objRep.join(', ') + '}';
71 }
72};
73
74// Prints an array of javascript objects.
75CollectionInspect = function(coll) {
76 var str = '';
77 for(var i=0; i<coll.length; i++) {
78 str += Inspect(coll[i]) + '<br />';
79 }
80 return str;
81};