Debian Codegraph @

jsonpickleJS/util.js

raw
1 define(['./tags'], function(tags) {
2 var util = {};
3 util.merge = function(destination, source) {
4 if (source !== undefined) {
5 for (var property in source) {
6 destination[property] = source[property];
7 }
8 }
9 return destination;
10 };
11
12 util.PRIMITIVES = ['string', 'number', 'boolean'];
13
14 /* from jsonpickle.util */
15 // to_do...
16 util.is_type = function (obj) { return false; };
17
18 // same as dictionary in JS...
19 util.is_object = function (obj) { return util.is_dictionary(obj); };
20
21 util.is_primitive = function (obj) {
22 if (obj === undefined || obj == null) {
23 return true;
24 }
25 if (util.PRIMITIVES.indexOf(typeof obj) != -1) {
26 return true;
27 }
28 return false;
29 };
30
31
32 util.is_dictionary = function (obj) {
33 return ((typeof obj == 'object') && (obj !== null));
34 };
35
36 util.is_sequence = function (obj) {
37 return (util.is_list(obj) || util.is_set(obj) || util.is_tuple(obj));
38 };
39
40 util.is_list = function (obj) {
41 return (obj instanceof Array);
42 };
43
44 // to_do...
45 util.is_set = function (obj) { return false; };
46 util.is_tuple = function (obj) { return false; };
47 util.is_dictionary_subclass = function (obj) { return false; };
48 util.is_sequence_subclass = function (obj) { return false; };
49 util.is_noncomplex = function (obj) { return false; };
50
51 util.is_function = function (obj) {
52 return (typeof obj == 'function');
53 };
54 util.is_module = function (obj) { return false; };
55
56 util.is_picklable = function(name, value) {
57 if (tags.RESERVED.indexOf(name) != -1) {
58 return false;
59 }
60 if (util.is_function(value)) {
61 return false;
62 } else {
63 return true;
64 }
65 };
66 util.is_installed = function (module) {
67 return true; // ???
68 };
69
70 util.is_list_like = function (obj) {
71 return util.is_list(obj);
72 };
73
74 if (typeof jsonpickle != "undefined") {
75 jsonpickle.util = util;
76 }
77 return util;
78 });