blob: 93aff08136587c19c1783d391cc9d77825995e56 [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
7Array.prototype.include = function(value) {
8 for(var i=0; i < this.length; i++) {
9 if(this[i] == value) {
10 return this[i];
11 }
12 }
13 return false;
14};
15
16Array.prototype.empty = function() {
17 return (this.length == 0);
18};
19
20Function.prototype.bind = function() {
21 var __method = this, object = arguments[0], args = [];
22
23 for(i = 1; i < arguments.length; i++) {
24 args.push(arguments[i]);
25 }
26
27 return function() {
28 return __method.apply(object, args);
29 };
30};
31
32String.prototype.trim = function() {
33 return this.replace(/^\s+|\s+$/g,"");
34};
35
36// Prints javascript types as readable strings.
37Inspect = function(obj) {
38 if(typeof(obj) != 'object') {
39 return obj;
40 }
41
42 else if (obj instanceof Array) {
43 var objRep = [];
44 for(var prop in obj) {
45 if(obj.hasOwnProperty(prop)) {
46 objRep.push(obj[prop]);
47 }
48 }
49 return '[' + objRep.join(', ') + ']';
50 }
51
52 else {
53 var objRep = [];
54 for(var prop in obj) {
55 if(obj.hasOwnProperty(prop)) {
56 objRep.push(prop + ': ' + ((typeof(obj[prop]) == 'object') ? Inspect(obj[prop]) : obj[prop]));
57 }
58 }
59 return '{' + objRep.join(', ') + '}';
60 }
61};
62
63// Prints an array of javascript objects.
64CollectionInspect = function(coll) {
65 var str = '';
66 for(var i=0; i<coll.length; i++) {
67 str += Inspect(coll[i]) + '<br />';
68 }
69 return str;
70};