Skip to content

Commit

Permalink
changed from Uint typed arrays to Int typed arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Maurice Müller committed Jun 11, 2018
1 parent 10c81cd commit 04f269e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@esentri/transformer-functions",
"version": "0.3.1",
"version": "0.3.2",
"description": "transformer functions from one data type into another",
"keywords": [],
"main": "dist/transformer-functions.umd.js",
Expand Down
6 changes: 3 additions & 3 deletions src/ArrayBufferTo.ts
Expand Up @@ -6,15 +6,15 @@ export function ArrayBufferToHexString (arrayBuffer: ArrayBuffer): string {
}

export function ArrayBufferToString (arrayBuffer: ArrayBuffer): string {
return String.fromCharCode.apply(null, new Uint8Array(arrayBuffer))
return String.fromCharCode.apply(null, new Int8Array(arrayBuffer))
}

export function ArrayBufferToBase64 (arrayBuffer: ArrayBuffer): string {
return StringToBase64(ArrayBufferToString(arrayBuffer))
}

export function ArrayBufferToArrayObject (arrayBuffer: ArrayBuffer, byteLength: number = 8): string {
if (byteLength === 8) return JSON.parse(JSON.stringify(new Uint8Array(arrayBuffer)))
if (byteLength === 16) return JSON.parse(JSON.stringify(new Uint16Array(arrayBuffer)))
if (byteLength === 8) return JSON.parse(JSON.stringify(new Int8Array(arrayBuffer)))
if (byteLength === 16) return JSON.parse(JSON.stringify(new Int16Array(arrayBuffer)))
throw new Error('Unsupported type length: ' + byteLength)
}
4 changes: 2 additions & 2 deletions src/ArrayObjectTo.ts
Expand Up @@ -8,7 +8,7 @@ export function ArrayObjectToArrayBuffer (arrayObject: any, byteLength = 8): Arr
array.push(arrayObject[property])
index++
}
if (byteLength === 8) return new Uint8Array(array).buffer as ArrayBuffer
if (byteLength === 16) return new Uint16Array(array).buffer as ArrayBuffer
if (byteLength === 8) return new Int8Array(array).buffer as ArrayBuffer
if (byteLength === 16) return new Int16Array(array).buffer as ArrayBuffer
throw new Error('Unsupported byte length: ' + byteLength)
}
2 changes: 1 addition & 1 deletion src/HexStringTo.ts
Expand Up @@ -6,7 +6,7 @@ export function HexStringToArrayBuffer (str: string): ArrayBuffer {
for (let i = 0; i < length; i += 2) {
a.push(parseInt(str.substr(i, 2), 16))
}
return new Uint8Array(a).buffer as ArrayBuffer
return new Int8Array(a).buffer as ArrayBuffer
}

export function HexStringToString (hexString: string): string {
Expand Down
2 changes: 1 addition & 1 deletion src/StringTo.ts
@@ -1,5 +1,5 @@
export function StringToArrayBuffer (str: string): ArrayBuffer {
return (new Uint8Array([].map.call(str, (x: any) => {
return (new Int8Array([].map.call(str, (x: any) => {
return x.charCodeAt(0)
}))).buffer as ArrayBuffer
}
Expand Down

0 comments on commit 04f269e

Please sign in to comment.