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