Cleaned up git
[iotcloud.git] / version1 / src / js / iotjs / src / iotstring.js
1 var _createClass = function() {
2     function defineProperties(target, props) {
3         for (var i = 0; i < props.length; i++) {
4             var descriptor = props[i];
5             descriptor.enumerable = descriptor.enumerable || false;
6             descriptor.configurable = true;
7             if ("value" in descriptor) descriptor.writable = true;
8             Object.defineProperty(target, descriptor.key, descriptor);
9         }
10     }
11     return function(Constructor, protoProps, staticProps) {
12         if (protoProps) defineProperties(Constructor.prototype, protoProps);
13         if (staticProps) defineProperties(Constructor, staticProps);
14         return Constructor;
15     };
16 }();
17
18 function _classCallCheck(instance, Constructor) {
19     if (!(instance instanceof Constructor)) {
20         throw new TypeError("Cannot call a class as a function");
21     }
22 }
23 var IoTString = function() {
24     function IoTString(arg) {
25         _classCallCheck(this, IoTString);
26         if (arg === undefined) {
27             this.array = new Uint8Array();
28             this.hashcode = '';
29         } else if (arg && typeof arg === "string") {
30             this.array = new Uint8Array(arg.length);
31             for (var i = 0; i < arg.length; ++i) {
32                 this.array[i] = arg.charCodeAt(i);
33             }
34             this.hashcode = hash(this.array);
35         } else if (arg && arg instanceof Uint8Array) {
36             this.array = arg;
37             this.hashcode = hashcode(arg);
38         }
39     }
40     _createClass(IoTString, [{
41         key: "shallow",
42         value: function shallow(arg) {
43             if (arg && arg instanceof Uint8Array) {
44                 var i = new IotString(arg);
45                 return i;
46             }
47         }
48     }, {
49         key: "internalBytes",
50         value: function internalBytes() {
51             return this.array;
52         }
53     }, {
54         key: "hashCode",
55         value: function hashCode() {
56             return this.hashcode;
57         }
58     }, {
59         key: "toString",
60         value: function toString() {
61             return this.array.toString();
62         }
63     }, {
64         key: "getBytes",
65         value: function getBytes() {
66             var obj;
67             return _.extend(obj, this.array);
68         }
69     }, {
70         key: "equals",
71         value: function equals(arr) {
72             return _.isEqual(arr, this.array);
73         }
74     }, {
75         key: "length",
76         value: function length() {
77             return this.array.length;
78         }
79     }]);
80     return IoTString;
81 }();