Skip to content

Commit

Permalink
chore: add build
Browse files Browse the repository at this point in the history
  • Loading branch information
Nesopie committed Aug 2, 2024
1 parent 0adf2a8 commit c040470
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
22 changes: 11 additions & 11 deletions src/cjs/index.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict";
'use strict';
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
Expand Down Expand Up @@ -29,7 +29,7 @@ exports.encodingLength = encodingLength;
const tools = __importStar(require("uint8array-tools"));
const checkUInt64 = (n) => {
if (n < 0 || n > 0xffffffffffffffffn) {
throw new RangeError("value out of range");
throw new RangeError('value out of range');
}
};
function encode(n, buffer, offset) {
Expand All @@ -48,19 +48,19 @@ function encode(n, buffer, offset) {
}
else if (n <= 0xffff) {
buffer.set([0xfd], offset);
tools.writeUInt16(buffer, offset + 1, Number(n), "LE");
tools.writeUInt16(buffer, offset + 1, Number(n), 'LE');
bytes = 3;
// 32 bit
}
else if (n <= 0xffffffff) {
buffer.set([0xfe], offset);
tools.writeUInt32(buffer, offset + 1, Number(n), "LE");
tools.writeUInt32(buffer, offset + 1, Number(n), 'LE');
bytes = 5;
// 64 bit
}
else {
buffer.set([0xff], offset);
tools.writeUInt64(buffer, offset + 1, n, "LE");
tools.writeUInt64(buffer, offset + 1, n, 'LE');
bytes = 9;
}
return { buffer, bytes };
Expand All @@ -70,28 +70,28 @@ function decode(buffer, offset) {
offset = 0;
const first = buffer.at(offset);
if (first === undefined)
throw new Error("buffer too small");
throw new Error('buffer too small');
// 8 bit
if (first < 0xfd) {
return { value: BigInt(first), bytes: 1 };
// 16 bit
}
else if (first === 0xfd) {
return {
value: BigInt(tools.readUInt16(buffer, offset + 1, "LE")),
bytes: 3,
value: BigInt(tools.readUInt16(buffer, offset + 1, 'LE')),
bytes: 3
};
// 32 bit
}
else if (first === 0xfe) {
return {
value: BigInt(tools.readUInt32(buffer, offset + 1, "LE")),
bytes: 5,
value: BigInt(tools.readUInt32(buffer, offset + 1, 'LE')),
bytes: 5
};
// 64 bit
}
else {
const number = tools.readUInt64(buffer, offset + 1, "LE");
const number = tools.readUInt64(buffer, offset + 1, 'LE');
return { value: number, bytes: 9 };
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/esm/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";
import * as tools from "uint8array-tools";
'use strict';
import * as tools from 'uint8array-tools';
const checkUInt64 = (n) => {
if (n < 0 || n > 0xffffffffffffffffn) {
throw new RangeError("value out of range");
throw new RangeError('value out of range');
}
};
export function encode(n, buffer, offset) {
Expand All @@ -21,19 +21,19 @@ export function encode(n, buffer, offset) {
}
else if (n <= 0xffff) {
buffer.set([0xfd], offset);
tools.writeUInt16(buffer, offset + 1, Number(n), "LE");
tools.writeUInt16(buffer, offset + 1, Number(n), 'LE');
bytes = 3;
// 32 bit
}
else if (n <= 0xffffffff) {
buffer.set([0xfe], offset);
tools.writeUInt32(buffer, offset + 1, Number(n), "LE");
tools.writeUInt32(buffer, offset + 1, Number(n), 'LE');
bytes = 5;
// 64 bit
}
else {
buffer.set([0xff], offset);
tools.writeUInt64(buffer, offset + 1, n, "LE");
tools.writeUInt64(buffer, offset + 1, n, 'LE');
bytes = 9;
}
return { buffer, bytes };
Expand All @@ -43,28 +43,28 @@ export function decode(buffer, offset) {
offset = 0;
const first = buffer.at(offset);
if (first === undefined)
throw new Error("buffer too small");
throw new Error('buffer too small');
// 8 bit
if (first < 0xfd) {
return { value: BigInt(first), bytes: 1 };
// 16 bit
}
else if (first === 0xfd) {
return {
value: BigInt(tools.readUInt16(buffer, offset + 1, "LE")),
bytes: 3,
value: BigInt(tools.readUInt16(buffer, offset + 1, 'LE')),
bytes: 3
};
// 32 bit
}
else if (first === 0xfe) {
return {
value: BigInt(tools.readUInt32(buffer, offset + 1, "LE")),
bytes: 5,
value: BigInt(tools.readUInt32(buffer, offset + 1, 'LE')),
bytes: 5
};
// 64 bit
}
else {
const number = tools.readUInt64(buffer, offset + 1, "LE");
const number = tools.readUInt64(buffer, offset + 1, 'LE');
return { value: number, bytes: 9 };
}
}
Expand Down

0 comments on commit c040470

Please sign in to comment.