Cleaned up git
[iotcloud.git] / version1 / src / js / iotjs / src / iotstring.js
diff --git a/version1/src/js/iotjs/src/iotstring.js b/version1/src/js/iotjs/src/iotstring.js
new file mode 100644 (file)
index 0000000..5a350e8
--- /dev/null
@@ -0,0 +1,81 @@
+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;
+    };
+}();
+
+function _classCallCheck(instance, Constructor) {
+    if (!(instance instanceof Constructor)) {
+        throw new TypeError("Cannot call a class as a function");
+    }
+}
+var IoTString = function() {
+    function IoTString(arg) {
+        _classCallCheck(this, IoTString);
+        if (arg === undefined) {
+            this.array = new Uint8Array();
+            this.hashcode = '';
+        } else if (arg && typeof arg === "string") {
+            this.array = new Uint8Array(arg.length);
+            for (var i = 0; i < arg.length; ++i) {
+                this.array[i] = arg.charCodeAt(i);
+            }
+            this.hashcode = hash(this.array);
+        } else if (arg && arg instanceof Uint8Array) {
+            this.array = arg;
+            this.hashcode = hashcode(arg);
+        }
+    }
+    _createClass(IoTString, [{
+        key: "shallow",
+        value: function shallow(arg) {
+            if (arg && arg instanceof Uint8Array) {
+                var i = new IotString(arg);
+                return i;
+            }
+        }
+    }, {
+        key: "internalBytes",
+        value: function internalBytes() {
+            return this.array;
+        }
+    }, {
+        key: "hashCode",
+        value: function hashCode() {
+            return this.hashcode;
+        }
+    }, {
+        key: "toString",
+        value: function toString() {
+            return this.array.toString();
+        }
+    }, {
+        key: "getBytes",
+        value: function getBytes() {
+            var obj;
+            return _.extend(obj, this.array);
+        }
+    }, {
+        key: "equals",
+        value: function equals(arr) {
+            return _.isEqual(arr, this.array);
+        }
+    }, {
+        key: "length",
+        value: function length() {
+            return this.array.length;
+        }
+    }]);
+    return IoTString;
+}();
\ No newline at end of file