Skip to content

Commit 205e623

Browse files
authored
Port utils to TypeScript (#1019)
1 parent 9274024 commit 205e623

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

src/util/cborTypedArrayTags.js renamed to src/util/cborTypedArrayTags.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ function warnPrecision() {
1212

1313
/**
1414
* Unpack 64-bit unsigned integer from byte array.
15-
* @param {Uint8Array} bytes
15+
* @param bytes
1616
*/
17-
function decodeUint64LE(bytes) {
17+
function decodeUint64LE(bytes: Uint8Array) {
1818
warnPrecision();
1919

2020
const byteLen = bytes.byteLength;
@@ -37,9 +37,9 @@ function decodeUint64LE(bytes) {
3737

3838
/**
3939
* Unpack 64-bit signed integer from byte array.
40-
* @param {Uint8Array} bytes
40+
* @param bytes
4141
*/
42-
function decodeInt64LE(bytes) {
42+
function decodeInt64LE(bytes: Uint8Array) {
4343
warnPrecision();
4444

4545
const byteLen = bytes.byteLength;
@@ -63,10 +63,10 @@ function decodeInt64LE(bytes) {
6363

6464
/**
6565
* Unpack typed array from byte array.
66-
* @param {Uint8Array} bytes
67-
* @param {ArrayConstructor} ArrayType - Desired output array type
66+
* @param bytes
67+
* @param ArrayType - Desired output array type
6868
*/
69-
function decodeNativeArray(bytes, ArrayType) {
69+
function decodeNativeArray(bytes: Uint8Array, ArrayType: ArrayConstructor) {
7070
const byteLen = bytes.byteLength;
7171
const offset = bytes.byteOffset;
7272
const buffer = bytes.buffer.slice(offset, offset + byteLen);
@@ -100,10 +100,10 @@ const conversionArrayTypes = {
100100

101101
/**
102102
* Handle CBOR typed array tags during decoding.
103-
* @param {Uint8Array} data
104-
* @param {Number} tag
103+
* @param data
104+
* @param tag
105105
*/
106-
export default function cborTypedArrayTagger(data, tag) {
106+
export default function cborTypedArrayTagger(data: Uint8Array, tag: number) {
107107
if (tag in nativeArrayTypes) {
108108
const arrayType = nativeArrayTypes[tag];
109109
return decodeNativeArray(data, arrayType);

src/util/decompressPng.js renamed to src/util/decompressPng.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55

66
import pngparse from "pngparse";
77

8-
/**
9-
* @callback decompressPngCallback
10-
* @param data - The uncompressed data.
11-
*/
128
/**
139
* If a message was compressed as a PNG image (a compression hack since
1410
* gzipping over WebSockets * is not supported yet), this function decodes
1511
* the "image" as a Base64 string.
1612
*
1713
* @private
1814
* @param data - An object containing the PNG data.
19-
* @param {decompressPngCallback} callback - Function with the following params:
15+
* @param callback - Function with the following params:
2016
*/
21-
export default function decompressPng(data, callback) {
17+
export default function decompressPng(
18+
data: string,
19+
callback: (data: unknown) => void,
20+
) {
2221
const buffer = new Buffer(data, "base64");
2322

2423
pngparse.parse(buffer, function (err, data) {

src/util/shim/decompressPng.js renamed to src/util/shim/decompressPng.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
* @author Graeme Yeates - github.com/megawac
44
*/
55

6-
/**
7-
* @callback decompressPngCallback
8-
* @param data - The uncompressed data.
9-
*/
106
/**
117
* If a message was compressed as a PNG image (a compression hack since
128
* gzipping over WebSockets * is not supported yet), this function places the
139
* "image" in a canvas element then decodes the * "image" as a Base64 string.
1410
*
1511
* @private
16-
* @param data - An object containing the PNG data.
17-
* @param {decompressPngCallback} callback - Function with the following params:
12+
* @param data - A string containing the PNG data.
13+
* @param callback - Function with the following params:
1814
*/
19-
export default function decompressPng(data, callback) {
15+
export default function decompressPng(
16+
data: string,
17+
callback: (data: unknown) => void,
18+
) {
2019
// Uncompresses the data before sending it through (use image/canvas to do so).
2120
const image = new Image();
2221
// When the image loads, extracts the raw data (JSON message).

0 commit comments

Comments
 (0)