-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
61 lines (52 loc) · 1.25 KB
/
functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function toStorage(key, object) {
localStorage.setItem(key, JSON.stringify(object));
}
function fromStorage(key) {
return JSON.parse(localStorage.getItem(key));
}
function log(object) {
console.log(object);
}
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function randomString(length, type) {
if( length==undefined ) length=8;
if( type==undefined ) type='alphanumeric';
var chars='';
switch( type ){
case 'alphanumeric':
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
break;
case 'alpha':
chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
break;
case 'numeric':
chars = "0123456789";
break;
}
var randomstring = '';
for (var i=0; i<length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}
function clone(obj) {
var clone = {};
clone.prototype = obj.prototype;
for (var property in obj) clone[property] = obj[property];
return clone;
}
function properties(object)
{
var keys = [];
for(var i in object) if (object.hasOwnProperty(i))
{
keys.push(i);
}
return keys;
}
function present(object) {
return typeof(object) !== 'undefined' && object !== null;
}