diff --git a/.prettierignore b/.prettierignore index f0aa14a..2d2f359 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,3 +3,4 @@ package-lock.json dist build coverage +test diff --git a/.prettierrc b/.prettierrc index ba4e1a9..b2095be 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,4 +2,3 @@ "semi": false, "singleQuote": true } - diff --git a/rollup.config.js b/rollup.config.js index 7232d86..e8076bb 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,10 +1,10 @@ -import { dts } from "rollup-plugin-dts"; +import { dts } from 'rollup-plugin-dts' export default { input: 'types/index.d.ts', output: { file: 'dist/index.d.ts', - format: 'es', + format: 'es', }, plugins: [dts()], } diff --git a/src/ConstArray.js b/src/ConstArray.js index d29d030..89a08da 100644 --- a/src/ConstArray.js +++ b/src/ConstArray.js @@ -1,4 +1,12 @@ -import { isHeadless, isSerializableType, parse, serialize, sizeof, sizeofHead, Type } from "." +import { + isHeadless, + isSerializableType, + parse, + serialize, + sizeof, + sizeofHead, + Type, +} from '.' export function ConstArray(size) { const obj = { _size: size } @@ -6,22 +14,34 @@ export function ConstArray(size) { obj.new(ConstArray, arguments) return obj } -ConstArray.prototype.serialize = function(dv, src, ...inner_types) { +ConstArray.prototype.serialize = function (dv, src, ...inner_types) { const item_headless = isHeadless(...inner_types) const item_head_size = sizeofHead(src[0], ...inner_types) const size = this._size if (dv.byteLength < this.sizeof(src, ...inner_types)) { - throw new Error(this.name_+ ', ' + inner_types.join(', ') + ' too small buffer') + throw new Error( + this.name_ + ', ' + inner_types.join(', ') + ' too small buffer', + ) } if (src.length != size) { - throw new Error(this.name_+ ', ' + inner_types.join(', ') + ' should be ' + size + ' elements length') + throw new Error( + this.name_ + + ', ' + + inner_types.join(', ') + + ' should be ' + + size + + ' elements length', + ) } let offset = item_head_size * size for (let i = 0; i < size; i++) { - const item_head_frame = new DataView(dv.buffer, dv.byteOffset + item_head_size * i) + const item_head_frame = new DataView( + dv.buffer, + dv.byteOffset + item_head_size * i, + ) if (item_headless) { item_head_frame.setUint32(0, offset) const item_frame = new DataView(dv.buffer, dv.byteOffset + offset) @@ -33,14 +53,17 @@ ConstArray.prototype.serialize = function(dv, src, ...inner_types) { } return } -ConstArray.prototype.parse = function(dv, ...inner_types) { +ConstArray.prototype.parse = function (dv, ...inner_types) { const item_headless = isHeadless(...inner_types) const item_head_size = sizeofHead(...inner_types) const size = this._size const array = Array(size) for (let i = 0; i < size; i++) { - const item_head_frame = new DataView(dv.buffer, dv.byteOffset + item_head_size * i) + const item_head_frame = new DataView( + dv.buffer, + dv.byteOffset + item_head_size * i, + ) if (item_headless) { const offset = item_head_frame.getUint32(0) const item_frame = new DataView(dv.buffer, dv.byteOffset + offset) @@ -52,10 +75,10 @@ ConstArray.prototype.parse = function(dv, ...inner_types) { return array } -ConstArray.prototype.isHeadless = function(...inner_types) { +ConstArray.prototype.isHeadless = function (...inner_types) { return isHeadless(...inner_types) } -ConstArray.prototype.sizeof = function(arg, ...args) { +ConstArray.prototype.sizeof = function (arg, ...args) { let inner_types let src @@ -68,10 +91,12 @@ ConstArray.prototype.sizeof = function(arg, ...args) { } const fixed_size = sizeofHead(...inner_types) * this._size - + if (isHeadless(...inner_types)) { if (src == undefined) { - throw new Error('unknown sizeof ' + this._name + ', ' + inner_types.join(',')) + throw new Error( + 'unknown sizeof ' + this._name + ', ' + inner_types.join(','), + ) } let variable_size = 0 @@ -82,7 +107,7 @@ ConstArray.prototype.sizeof = function(arg, ...args) { return fixed_size + variable_size } else { return fixed_size - } + } } Object.setPrototypeOf(ConstArray.prototype, Type.prototype) Object.freeze(ConstArray.prototype) diff --git a/src/ConstDataView.js b/src/ConstDataView.js index b8d381e..ef32ce2 100644 --- a/src/ConstDataView.js +++ b/src/ConstDataView.js @@ -1,4 +1,4 @@ -import { memcpy, Type } from "." +import { memcpy, Type } from '.' export function ConstDataView(size) { const obj = { _size: size } @@ -6,7 +6,7 @@ export function ConstDataView(size) { obj.new(ConstDataView, arguments) return obj } -ConstDataView.prototype.serialize = function(dv, src) { +ConstDataView.prototype.serialize = function (dv, src) { if (dv.byteLength < this._size) { throw new Error(this._name + ' too small buffer') } @@ -16,7 +16,7 @@ ConstDataView.prototype.serialize = function(dv, src) { memcpy(dv, src) return } -ConstDataView.prototype.parse = function(dv) { +ConstDataView.prototype.parse = function (dv) { const res_buffer = new ArrayBuffer(this._size) const res_dv = new DataView(res_buffer) @@ -24,10 +24,10 @@ ConstDataView.prototype.parse = function(dv) { return res_dv } -ConstDataView.prototype.isHeadless = function() { +ConstDataView.prototype.isHeadless = function () { return false } -ConstDataView.prototype.sizeof = function() { +ConstDataView.prototype.sizeof = function () { return this._size } Object.setPrototypeOf(ConstDataView.prototype, Type.prototype) diff --git a/src/ConstString.js b/src/ConstString.js index 33ae5ce..164cc72 100644 --- a/src/ConstString.js +++ b/src/ConstString.js @@ -1,5 +1,5 @@ -import { memcpy } from "./mem" -import { Type } from "./Type" +import { memcpy } from './mem' +import { Type } from './Type' export function ConstString(size) { const obj = { _size: size } @@ -7,7 +7,7 @@ export function ConstString(size) { obj.new(ConstString, arguments) return obj } -ConstString.prototype.serialize = function(dv, src) { +ConstString.prototype.serialize = function (dv, src) { const encoder = new TextEncoder('utf-8') const encoded = new DataView(encoder.encode(src).buffer, 0, this._size) @@ -21,15 +21,15 @@ ConstString.prototype.serialize = function(dv, src) { memcpy(dv, encoded) return } -ConstString.prototype.parse = function(dv) { +ConstString.prototype.parse = function (dv) { const frame = new DataView(dv.buffer, dv.byteOffset, this._size) const decoder = new TextDecoder('utf-8') return decoder.decode(frame) } -ConstString.prototype.isHeadless = function() { +ConstString.prototype.isHeadless = function () { return false } -ConstString.prototype.sizeof = function() { +ConstString.prototype.sizeof = function () { return this._size } Object.setPrototypeOf(ConstString.prototype, Type.prototype) diff --git a/src/Int.js b/src/Int.js index 7d2cf47..83428b5 100644 --- a/src/Int.js +++ b/src/Int.js @@ -6,58 +6,58 @@ export function Int(bits, sign) { obj.new(Int, arguments) switch (sign) { - case 'signed': - switch (bits) { - case 8: - obj._dv_set = DataView.prototype.setInt8 - obj._dv_get = DataView.prototype.getInt8 - obj._limits = limits.i8 + case 'signed': + switch (bits) { + case 8: + obj._dv_set = DataView.prototype.setInt8 + obj._dv_get = DataView.prototype.getInt8 + obj._limits = limits.i8 + break + + case 16: + obj._dv_set = DataView.prototype.setInt16 + obj._dv_get = DataView.prototype.getInt16 + obj._limits = limits.i16 + break + + case 32: + obj._dv_set = DataView.prototype.setInt32 + obj._dv_get = DataView.prototype.getInt32 + obj._limits = limits.i32 + break + + default: + throw new Error(obj._name + ' incorrect bits ' + bits) + } break - case 16: - obj._dv_set = DataView.prototype.setInt16 - obj._dv_get = DataView.prototype.getInt16 - obj._limits = limits.i16 - break + case 'unsigned': + switch (bits) { + case 8: + obj._dv_set = DataView.prototype.setUint8 + obj._dv_get = DataView.prototype.getUint8 + obj._limits = limits.u8 + break - case 32: - obj._dv_set = DataView.prototype.setInt32 - obj._dv_get = DataView.prototype.getInt32 - obj._limits = limits.i32 + case 16: + obj._dv_set = DataView.prototype.setUint16 + obj._dv_get = DataView.prototype.getUint16 + obj._limits = limits.u16 + break + + case 32: + obj._dv_set = DataView.prototype.setUint32 + obj._dv_get = DataView.prototype.getUint32 + obj._limits = limits.u32 + break + + default: + throw new Error(obj._name + ' incorrect bits ' + bits) + } break default: - throw new Error(obj._name + ' incorrect bits ' + bits) - } - break - - case 'unsigned': - switch (bits) { - case 8: - obj._dv_set = DataView.prototype.setUint8 - obj._dv_get = DataView.prototype.getUint8 - obj._limits = limits.u8 - break - - case 16: - obj._dv_set = DataView.prototype.setUint16 - obj._dv_get = DataView.prototype.getUint16 - obj._limits = limits.u16 - break - - case 32: - obj._dv_set = DataView.prototype.setUint32 - obj._dv_get = DataView.prototype.getUint32 - obj._limits = limits.u32 - break - - default: - throw new Error(obj._name + ' incorrect bits ' + bits) - } - break - - default: - throw new Error(obj._name + ' incorrect sign ' + sign) + throw new Error(obj._name + ' incorrect sign ' + sign) } return obj @@ -67,10 +67,14 @@ Int.prototype.serialize = function (dv, src) { throw new Error(this._name + ' buffer is too small') } if (src > this._limits.MAX_VALUE) { - throw new Error(this._name + ` should be less or equal than ` + this._limits.MAX_VALUE) + throw new Error( + this._name + ` should be less or equal than ` + this._limits.MAX_VALUE, + ) } if (src < this._limits.MIN_VALUE) { - throw new Error(this._name + ` should be more or equal than ` + this._limits.MIN_VALUE) + throw new Error( + this._name + ` should be more or equal than ` + this._limits.MIN_VALUE, + ) } this._dv_set.call(dv, 0, src) } diff --git a/src/Struct.js b/src/Struct.js index bdf7fe8..fc27a6c 100644 --- a/src/Struct.js +++ b/src/Struct.js @@ -1,12 +1,12 @@ -import { isHeadless, parse, serialize, sizeof, sizeofHead, Type } from "." +import { isHeadless, parse, serialize, sizeof, sizeofHead, Type } from '.' export function Struct(type_obj) { const obj = {} Object.setPrototypeOf(obj, Struct.prototype) - - obj._info_by_key = new Map + + obj._info_by_key = new Map() obj._headless = false - + const arg = {} let offset = 0 @@ -18,7 +18,7 @@ export function Struct(type_obj) { types = [value] } - arg[key] = types.map(type => type.name) + arg[key] = types.map((type) => type.name) const headless = isHeadless(...types) obj._info_by_key.set(key, { @@ -35,12 +35,12 @@ export function Struct(type_obj) { return obj } -Struct.prototype.serialize = function(dv, src) { +Struct.prototype.serialize = function (dv, src) { let data_offset = this._size for (const [key, value] of Object.entries(src)) { const info = this._info_by_key.get(key) - + if (info.headless) { dv.setUint32(info.offset, data_offset) const frame = new DataView(dv.buffer, dv.byteOffset + data_offset) @@ -52,10 +52,10 @@ Struct.prototype.serialize = function(dv, src) { } } } -Struct.prototype.parse = function(dv) { +Struct.prototype.parse = function (dv) { const res = {} - for (const [key, info] of this._info_by_key.entries()) { + for (const [key, info] of this._info_by_key.entries()) { if (info.headless) { const data_offset = dv.getUint32(info.offset) const frame = new DataView(dv.buffer, dv.byteOffset + data_offset) @@ -68,10 +68,10 @@ Struct.prototype.parse = function(dv) { return res } -Struct.prototype.isHeadless = function() { +Struct.prototype.isHeadless = function () { return this._headless } -Struct.prototype.sizeof = function(arg) { +Struct.prototype.sizeof = function (arg) { if (this._headless) { if (arg === undefined) { throw new Error('unknown size of ' + this) diff --git a/src/Type.js b/src/Type.js index 61330f5..3c08dd3 100644 --- a/src/Type.js +++ b/src/Type.js @@ -3,17 +3,17 @@ export function Type() { Object.setPrototypeOf(obj, Type.prototype) return obj } -Type.prototype.new = function(func, args) { +Type.prototype.new = function (func, args) { this._name = func.name if (args !== undefined) { - const str_args = Array.from(args).map(arg => JSON.stringify(arg)) + const str_args = Array.from(args).map((arg) => JSON.stringify(arg)) this._name += '(' + str_args.join(', ') + ')' } } -Type.prototype.toString = function() { +Type.prototype.toString = function () { return this._name } -Type.prototype.serialize = function() { +Type.prototype.serialize = function () { throw new Error('should be overloaded') } Type.prototype.parse = Type.prototype.serialize diff --git a/src/index.js b/src/index.js index b1f76c4..ef67d83 100644 --- a/src/index.js +++ b/src/index.js @@ -1,13 +1,22 @@ -import { limits } from "./limits" -import { memcpy } from "./mem" -import { Type } from "./Type" -import { Int } from "./Int" +import { limits } from './limits' +import { memcpy } from './mem' +import { Type } from './Type' +import { Int } from './Int' import { ConstString } from './ConstString' -import { ConstArray } from "./ConstArray" +import { ConstArray } from './ConstArray' import { ConstDataView } from './ConstDataView' import { Struct } from './Struct' -export { limits, memcpy, Type, Int, ConstString, ConstArray, ConstDataView, Struct } +export { + limits, + memcpy, + Type, + Int, + ConstString, + ConstArray, + ConstDataView, + Struct, +} export function serialize(dv, src, ...types) { const [type, ...inner_types] = types @@ -60,7 +69,10 @@ export function serialize(dv, src, ...types) { let offset = 4 + item_head_size * size for (let i = 0; i < size; i++) { - const item_head_frame = new DataView(dv.buffer, dv.byteOffset + 4 + item_head_size * i) + const item_head_frame = new DataView( + dv.buffer, + dv.byteOffset + 4 + item_head_size * i, + ) if (item_headless) { item_head_frame.setUint32(0, offset) const item_frame = new DataView(dv.buffer, dv.byteOffset + offset) @@ -114,7 +126,10 @@ export function parse(dv, ...types) { const array = Array(size) for (let i = 0; i < size; i++) { - const item_head_frame = new DataView(dv.buffer, dv.byteOffset + 4 + item_head_size * i) + const item_head_frame = new DataView( + dv.buffer, + dv.byteOffset + 4 + item_head_size * i, + ) if (item_headless) { const offset = item_head_frame.getUint32(0) const item_frame = new DataView(dv.buffer, dv.byteOffset + offset) @@ -146,12 +161,14 @@ export function isHeadless(...args) { if (arg instanceof Type) { return arg.isHeadless(...inner_args) } - return arg == Array || + return ( + arg == Array || arg == String || arg == DataView || Array.isArray(arg) || typeof arg == 'string' || arg instanceof DataView + ) } export function sizeofHead(...args) { @@ -166,10 +183,10 @@ export function sizeof(...args) { const [arg, ...inner_args] = args const [arg2, ...inner_args2] = inner_args - if (arg == Boolean || arg2 == Boolean && typeof arg == 'boolean') { + if (arg == Boolean || (arg2 == Boolean && typeof arg == 'boolean')) { return 1 } - if (arg == Number || arg2 == Number && typeof arg == 'number') { + if (arg == Number || (arg2 == Number && typeof arg == 'number')) { return 8 } if (arg2 == String && typeof arg == 'string') { @@ -177,10 +194,8 @@ export function sizeof(...args) { return 4 + encoder.encode(arg).byteLength } if (arg2 == Array && Array.isArray(arg)) { - const fixed_size = 4 + sizeofHead(...inner_args2) * arg.length if (isHeadless(...inner_args2)) { - let variable_size = 0 for (const item of arg) { variable_size += sizeof(item, ...inner_args2) @@ -204,10 +219,12 @@ export function sizeof(...args) { } export function isSerializableType(type) { - return type == Boolean || + return ( + type == Boolean || type == Number || type == String || type == Array || type == DataView || type instanceof Type + ) } diff --git a/src/limits.js b/src/limits.js index dc57027..aa067b3 100644 --- a/src/limits.js +++ b/src/limits.js @@ -35,16 +35,16 @@ const bool = { MAX_VALUE: 1, } const f32 = { - MIN_VALUE: -3.40282347e+38, - MAX_VALUE: 3.40282347e+38, + MIN_VALUE: -3.40282347e38, + MAX_VALUE: 3.40282347e38, MIN_NORMAL_VALUE: 1.17549435e-38, MIN_SAFE_INTEGER: -16777215, MAX_SAFE_INTEGER: 16777215, - EPSILON: 1.19209290e-07, + EPSILON: 1.1920929e-7, } const f64 = { - MIN_VALUE: -1.7976931348623157e+308, - MAX_VALUE: 1.7976931348623157e+308, + MIN_VALUE: -1.7976931348623157e308, + MAX_VALUE: 1.7976931348623157e308, MIN_NORMAL_VALUE: 2.2250738585072014e-308, MIN_SAFE_INTEGER: -9007199254740991, MAX_SAFE_INTEGER: 9007199254740991, diff --git a/src/mem.js b/src/mem.js index 1f631ae..baea2bf 100644 --- a/src/mem.js +++ b/src/mem.js @@ -1,12 +1,12 @@ export function memcpy(dest, src) { - const min_size = dest.byteLength > src.byteLength ? - src.byteLength : dest.byteLength + const min_size = + dest.byteLength > src.byteLength ? src.byteLength : dest.byteLength for (let i = 0; i < Math.floor(min_size / 8); i++) { dest.setFloat64(i * 8, src.getFloat64(i * 8)) } - for (let i = min_size - min_size % 8; i < min_size; i++) { + for (let i = min_size - (min_size % 8); i < min_size; i++) { dest.setInt8(i, src.getInt8(i)) } } diff --git a/types/ConstArray.d.ts b/types/ConstArray.d.ts index b624515..5d8fd17 100644 --- a/types/ConstArray.d.ts +++ b/types/ConstArray.d.ts @@ -1,8 +1,8 @@ -import { Type } from "."; +import { Type } from '.' /** - * constructs type of array with constant byte size - * @param {number} size number of items - * @returns {Type} - */ -export function ConstArray(size: number): Type; + * constructs type of array with constant byte size + * @param {number} size number of items + * @returns {Type} + */ +export function ConstArray(size: number): Type diff --git a/types/ConstDataView.d.ts b/types/ConstDataView.d.ts index 399da99..13b5fa7 100644 --- a/types/ConstDataView.d.ts +++ b/types/ConstDataView.d.ts @@ -1,8 +1,8 @@ -import { Type } from "."; +import { Type } from '.' /** - * constructs type of data view with constant byte size - * @param {number} byte_size max byte size - * @returns {Type} - */ -export function ConstDataView(byte_size: number): Type; + * constructs type of data view with constant byte size + * @param {number} byte_size max byte size + * @returns {Type} + */ +export function ConstDataView(byte_size: number): Type diff --git a/types/ConstString.d.ts b/types/ConstString.d.ts index 02291af..e377718 100644 --- a/types/ConstString.d.ts +++ b/types/ConstString.d.ts @@ -1,8 +1,8 @@ -import { Type } from "."; +import { Type } from '.' /** - * constructs type of utf8-string with constant byte size - * @param {number} byte_size max utf8-encoded byte size - * @returns {Type} - */ -export function ConstString(byte_size: number): Type; + * constructs type of utf8-string with constant byte size + * @param {number} byte_size max utf8-encoded byte size + * @returns {Type} + */ +export function ConstString(byte_size: number): Type diff --git a/types/Int.d.ts b/types/Int.d.ts index 8880b3b..66b988e 100644 --- a/types/Int.d.ts +++ b/types/Int.d.ts @@ -1,3 +1,3 @@ -import { Type } from "."; +import { Type } from '.' -export function Int(bits: 8 | 16 | 32, sign: 'signed' | 'unsigned'): Type; +export function Int(bits: 8 | 16 | 32, sign: 'signed' | 'unsigned'): Type diff --git a/types/Struct.d.ts b/types/Struct.d.ts index 977f317..153e1ee 100644 --- a/types/Struct.d.ts +++ b/types/Struct.d.ts @@ -1,7 +1,9 @@ -import { SerializableType, Type } from "." +import { SerializableType, Type } from '.' /** - * constructs type of c-like structure. if field is headless, inside of structure will be stored u32 offset, outside of structure will be stored value of field - * @returns {Type} - */ -export function Struct(type_obj: Record): Type; + * constructs type of c-like structure. if field is headless, inside of structure will be stored u32 offset, outside of structure will be stored value of field + * @returns {Type} + */ +export function Struct( + type_obj: Record, +): Type diff --git a/types/index.d.ts b/types/index.d.ts index df65d0a..9cfe277 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,59 +1,78 @@ -import { memcpy } from "./mem"; -import { limits } from "./limits"; -import { Type } from "./Type" -import { Int } from "./Int" -import { ConstString } from "./ConstString" -import { ConstArray } from "./ConstArray"; -import { ConstDataView } from "./ConstDataView"; -import { Struct } from "./Struct"; +import { memcpy } from './mem' +import { limits } from './limits' +import { Type } from './Type' +import { Int } from './Int' +import { ConstString } from './ConstString' +import { ConstArray } from './ConstArray' +import { ConstDataView } from './ConstDataView' +import { Struct } from './Struct' -export { memcpy, limits, Type, Int, ConstString, ConstArray, ConstDataView, Struct } +export { + memcpy, + limits, + Type, + Int, + ConstString, + ConstArray, + ConstDataView, + Struct, +} -export type SerializableType = BooleanConstructor | NumberConstructor | StringConstructor | ArrayConstructor | DataViewConstructor | Type +export type SerializableType = + | BooleanConstructor + | NumberConstructor + | StringConstructor + | ArrayConstructor + | DataViewConstructor + | Type export type Serializable = unknown /** - * @param {DataView} dv destination memory - * @param {Serializable} src source object - * @param {SerializableType[]} ...types primary and inner types. eg: Array, Number - * @throws {Error} if too small buffer - * @throws {Error} if array|string|DataView size is higher than limits.u32.MAX_VALUE - */ -export function serialize(dv: DataView, src: Serializable, ...types: SerializableType[]): void; + * @param {DataView} dv destination memory + * @param {Serializable} src source object + * @param {SerializableType[]} ...types primary and inner types. eg: Array, Number + * @throws {Error} if too small buffer + * @throws {Error} if array|string|DataView size is higher than limits.u32.MAX_VALUE + */ +export function serialize( + dv: DataView, + src: Serializable, + ...types: SerializableType[] +): void /** - * @param {DataView} dv source memory - * @param {SerializableType[]} ...types primary and inner types. eg: Array, Number - * @returns {Serializable} parsed object - */ -export function parse(dv: DataView, ...types: SerializableType[]): Serializable; + * @param {DataView} dv source memory + * @param {SerializableType[]} ...types primary and inner types. eg: Array, Number + * @returns {Serializable} parsed object + */ +export function parse(dv: DataView, ...types: SerializableType[]): Serializable /** - * some types, like Array, String, has no fixed size. So in Structure they are stored as u32 offset, which points to their beginning - * @param {SerializableType[]} ...types primary and inner types. eg: Array, Number - * @returns {boolean} - */ -export function isHeadless(...types: SerializableType[]): boolean; + * some types, like Array, String, has no fixed size. So in Structure they are stored as u32 offset, which points to their beginning + * @param {SerializableType[]} ...types primary and inner types. eg: Array, Number + * @returns {boolean} + */ +export function isHeadless(...types: SerializableType[]): boolean /** - * if obj has no fixed size, return 4 (sizeof u32 offset) - * @param {SerializableType[]} ...types primary and inner types. eg: Array, Number - * @returns {number} - */ -export function sizeofHead(...types: SerializableType[]): number; + * if obj has no fixed size, return 4 (sizeof u32 offset) + * @param {SerializableType[]} ...types primary and inner types. eg: Array, Number + * @returns {number} + */ +export function sizeofHead(...types: SerializableType[]): number /** - * @param {Serializable} obj to check - * @param {SerializableType[]} ...types primary and inner types. eg: Array, Number - * @returns {number} - */ -export function sizeof(obj: Serializable, ...types: SerializableType[]): number; + * @param {Serializable} obj to check + * @param {SerializableType[]} ...types primary and inner types. eg: Array, Number + * @returns {number} + */ +export function sizeof(obj: Serializable, ...types: SerializableType[]): number /** - * @param {SerializableType[]} ...types primary and inner types. eg: Array, Number - * @returns {number} - * @throws {Error} if passed Array, String, DataView type (unknown sizeof) - */ -export function sizeof(...types: SerializableType[]): number; + * @param {SerializableType[]} ...types primary and inner types. eg: Array, Number + * @returns {number} + * @throws {Error} if passed Array, String, DataView type (unknown sizeof) + */ +export function sizeof(...types: SerializableType[]): number -export function isSerializableType(type: unknown): boolean; +export function isSerializableType(type: unknown): boolean diff --git a/types/limits.d.ts b/types/limits.d.ts index 30b9f58..02af743 100644 --- a/types/limits.d.ts +++ b/types/limits.d.ts @@ -29,4 +29,4 @@ export const limits: { bool: IntLimit f32: FloatLimit f64: FloatLimit -}; +} diff --git a/types/mem.d.ts b/types/mem.d.ts index c9581f3..d1b5eb5 100644 --- a/types/mem.d.ts +++ b/types/mem.d.ts @@ -1,4 +1,4 @@ /** - * copies max possible number of bytes from src to dest (min of both sizes) - */ -export function memcpy(dest: DataView, src: DataView): void; + * copies max possible number of bytes from src to dest (min of both sizes) + */ +export function memcpy(dest: DataView, src: DataView): void