@slimevr/common
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| var _utils = require("./utils"); | ||
| Object.keys(_utils).forEach(function (key) { | ||
| if (key === "default" || key === "__esModule") return; | ||
| if (key in exports && exports[key] === _utils[key]) return; | ||
| Object.defineProperty(exports, key, { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _utils[key]; | ||
| } | ||
| }); | ||
| }); | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","names":["_utils","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../esm/index.js"],"sourcesContent":["export * from './utils';\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.formatMACAddressDigit = exports.Vector = exports.Quaternion = exports.MACAddress = void 0; | ||
| class Vector { | ||
| constructor(x, y, z) { | ||
| this.x = x; | ||
| this.y = y; | ||
| this.z = z; | ||
| } | ||
| static from(init) { | ||
| if (Array.isArray(init)) { | ||
| return new Vector(init[0], init[1], init[2]); | ||
| } else { | ||
| return new Vector(init.x, init.y, init.z); | ||
| } | ||
| } | ||
| static readFloatBE(buf, offset) { | ||
| return new Vector(buf.readFloatBE(offset), buf.readFloatBE(offset + 4), buf.readFloatBE(offset + 8)); | ||
| } | ||
| static readInt32BE(buf, offset) { | ||
| return new Vector(buf.readInt32BE(offset), buf.readInt32BE(offset + 4), buf.readInt32BE(offset + 8)); | ||
| } | ||
| writeFloatBE(buf, offset) { | ||
| buf.writeFloatBE(this.x, offset); | ||
| buf.writeFloatBE(this.y, offset + 4); | ||
| buf.writeFloatBE(this.z, offset + 8); | ||
| } | ||
| writeInt32BE(buf, offset) { | ||
| buf.writeInt32BE(this.x, offset); | ||
| buf.writeInt32BE(this.y, offset + 4); | ||
| buf.writeInt32BE(this.z, offset + 8); | ||
| } | ||
| static zero() { | ||
| return new Vector(0, 0, 0); | ||
| } | ||
| get byteLength() { | ||
| return 3 * 4; | ||
| } | ||
| get bytes() { | ||
| return [this.x, this.y, this.z]; | ||
| } | ||
| toString() { | ||
| return `(${this.x}, ${this.y}, ${this.z})`; | ||
| } | ||
| } | ||
| exports.Vector = Vector; | ||
| class Quaternion { | ||
| constructor(x, y, z, w) { | ||
| this.x = x; | ||
| this.y = y; | ||
| this.z = z; | ||
| this.w = w; | ||
| } | ||
| static from(init) { | ||
| if (Array.isArray(init)) { | ||
| return new Quaternion(init[0], init[1], init[2], init[3]); | ||
| } else { | ||
| return new Quaternion(init.x, init.y, init.z, init.w); | ||
| } | ||
| } | ||
| static read(buf, offset) { | ||
| return new Quaternion(buf.readFloatBE(offset), buf.readFloatBE(offset + 4), buf.readFloatBE(offset + 8), buf.readFloatBE(offset + 12)); | ||
| } | ||
| write(buf, offset) { | ||
| buf.writeFloatBE(this.x, offset); | ||
| buf.writeFloatBE(this.y, offset + 4); | ||
| buf.writeFloatBE(this.z, offset + 8); | ||
| buf.writeFloatBE(this.w, offset + 12); | ||
| } | ||
| static zero() { | ||
| return new Quaternion(0, 0, 0, 1); | ||
| } | ||
| isSimilarTo(q, e = 0.0001) { | ||
| return Math.abs(this.x - q.x) < e && Math.abs(this.y - q.y) < e && Math.abs(this.z - q.z) < e && Math.abs(this.w - q.w) < e; | ||
| } | ||
| get byteLength() { | ||
| return 4 * 4; | ||
| } | ||
| get bytes() { | ||
| return [this.x, this.y, this.z, this.w]; | ||
| } | ||
| toString() { | ||
| return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`; | ||
| } | ||
| } | ||
| exports.Quaternion = Quaternion; | ||
| const formatMACAddressDigit = mac => { | ||
| return mac.toString(16).padStart(2, '0').toUpperCase(); | ||
| }; | ||
| exports.formatMACAddressDigit = formatMACAddressDigit; | ||
| class MACAddress { | ||
| constructor(bytes) { | ||
| this.bytes = bytes; | ||
| } | ||
| write(buf, offset) { | ||
| for (let i = 0; i < this.bytes.length; i++) { | ||
| buf.writeUInt8(this.bytes[i], offset + i); | ||
| } | ||
| } | ||
| toString() { | ||
| return this.bytes.map(formatMACAddressDigit).join(':'); | ||
| } | ||
| static zero() { | ||
| return new MACAddress([0, 0, 0, 0, 0, 0]); | ||
| } | ||
| static random() { | ||
| return new MACAddress(new Array(6).fill(0).map(() => Math.floor(Math.random() * 256))); | ||
| } | ||
| } | ||
| exports.MACAddress = MACAddress; | ||
| //# sourceMappingURL=utils.js.map |
| {"version":3,"file":"utils.js","names":["Vector","constructor","x","y","z","from","init","Array","isArray","readFloatBE","buf","offset","readInt32BE","writeFloatBE","writeInt32BE","zero","byteLength","bytes","toString","exports","Quaternion","w","read","write","isSimilarTo","q","e","Math","abs","formatMACAddressDigit","mac","padStart","toUpperCase","MACAddress","i","length","writeUInt8","map","join","random","fill","floor"],"sources":["../esm/utils.js"],"sourcesContent":["export class Vector {\n constructor(x, y, z) {\n this.x = x;\n this.y = y;\n this.z = z;\n }\n static from(init) {\n if (Array.isArray(init)) {\n return new Vector(init[0], init[1], init[2]);\n }\n else {\n return new Vector(init.x, init.y, init.z);\n }\n }\n static readFloatBE(buf, offset) {\n return new Vector(buf.readFloatBE(offset), buf.readFloatBE(offset + 4), buf.readFloatBE(offset + 8));\n }\n static readInt32BE(buf, offset) {\n return new Vector(buf.readInt32BE(offset), buf.readInt32BE(offset + 4), buf.readInt32BE(offset + 8));\n }\n writeFloatBE(buf, offset) {\n buf.writeFloatBE(this.x, offset);\n buf.writeFloatBE(this.y, offset + 4);\n buf.writeFloatBE(this.z, offset + 8);\n }\n writeInt32BE(buf, offset) {\n buf.writeInt32BE(this.x, offset);\n buf.writeInt32BE(this.y, offset + 4);\n buf.writeInt32BE(this.z, offset + 8);\n }\n static zero() {\n return new Vector(0, 0, 0);\n }\n get byteLength() {\n return 3 * 4;\n }\n get bytes() {\n return [this.x, this.y, this.z];\n }\n toString() {\n return `(${this.x}, ${this.y}, ${this.z})`;\n }\n}\nexport class Quaternion {\n constructor(x, y, z, w) {\n this.x = x;\n this.y = y;\n this.z = z;\n this.w = w;\n }\n static from(init) {\n if (Array.isArray(init)) {\n return new Quaternion(init[0], init[1], init[2], init[3]);\n }\n else {\n return new Quaternion(init.x, init.y, init.z, init.w);\n }\n }\n static read(buf, offset) {\n return new Quaternion(buf.readFloatBE(offset), buf.readFloatBE(offset + 4), buf.readFloatBE(offset + 8), buf.readFloatBE(offset + 12));\n }\n write(buf, offset) {\n buf.writeFloatBE(this.x, offset);\n buf.writeFloatBE(this.y, offset + 4);\n buf.writeFloatBE(this.z, offset + 8);\n buf.writeFloatBE(this.w, offset + 12);\n }\n static zero() {\n return new Quaternion(0, 0, 0, 1);\n }\n isSimilarTo(q, e = 0.0001) {\n return (Math.abs(this.x - q.x) < e &&\n Math.abs(this.y - q.y) < e &&\n Math.abs(this.z - q.z) < e &&\n Math.abs(this.w - q.w) < e);\n }\n get byteLength() {\n return 4 * 4;\n }\n get bytes() {\n return [this.x, this.y, this.z, this.w];\n }\n toString() {\n return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`;\n }\n}\nexport const formatMACAddressDigit = (mac) => {\n return mac.toString(16).padStart(2, '0').toUpperCase();\n};\nexport class MACAddress {\n constructor(bytes) {\n this.bytes = bytes;\n }\n write(buf, offset) {\n for (let i = 0; i < this.bytes.length; i++) {\n buf.writeUInt8(this.bytes[i], offset + i);\n }\n }\n toString() {\n return this.bytes.map(formatMACAddressDigit).join(':');\n }\n static zero() {\n return new MACAddress([0, 0, 0, 0, 0, 0]);\n }\n static random() {\n return new MACAddress(new Array(6).fill(0).map(() => Math.floor(Math.random() * 256)));\n }\n}\n"],"mappings":";;;;;;AAAO,MAAMA,MAAM,CAAC;EAChBC,WAAWA,CAACC,CAAC,EAAEC,CAAC,EAAEC,CAAC,EAAE;IACjB,IAAI,CAACF,CAAC,GAAGA,CAAC;IACV,IAAI,CAACC,CAAC,GAAGA,CAAC;IACV,IAAI,CAACC,CAAC,GAAGA,CAAC;EACd;EACA,OAAOC,IAAIA,CAACC,IAAI,EAAE;IACd,IAAIC,KAAK,CAACC,OAAO,CAACF,IAAI,CAAC,EAAE;MACrB,OAAO,IAAIN,MAAM,CAACM,IAAI,CAAC,CAAC,CAAC,EAAEA,IAAI,CAAC,CAAC,CAAC,EAAEA,IAAI,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC,MACI;MACD,OAAO,IAAIN,MAAM,CAACM,IAAI,CAACJ,CAAC,EAAEI,IAAI,CAACH,CAAC,EAAEG,IAAI,CAACF,CAAC,CAAC;IAC7C;EACJ;EACA,OAAOK,WAAWA,CAACC,GAAG,EAAEC,MAAM,EAAE;IAC5B,OAAO,IAAIX,MAAM,CAACU,GAAG,CAACD,WAAW,CAACE,MAAM,CAAC,EAAED,GAAG,CAACD,WAAW,CAACE,MAAM,GAAG,CAAC,CAAC,EAAED,GAAG,CAACD,WAAW,CAACE,MAAM,GAAG,CAAC,CAAC,CAAC;EACxG;EACA,OAAOC,WAAWA,CAACF,GAAG,EAAEC,MAAM,EAAE;IAC5B,OAAO,IAAIX,MAAM,CAACU,GAAG,CAACE,WAAW,CAACD,MAAM,CAAC,EAAED,GAAG,CAACE,WAAW,CAACD,MAAM,GAAG,CAAC,CAAC,EAAED,GAAG,CAACE,WAAW,CAACD,MAAM,GAAG,CAAC,CAAC,CAAC;EACxG;EACAE,YAAYA,CAACH,GAAG,EAAEC,MAAM,EAAE;IACtBD,GAAG,CAACG,YAAY,CAAC,IAAI,C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,MAAM,EAAED,CAAC,EAAE,EAAE;MACxCxB,GAAG,CAAC0B,UAAU,CAAC,IAAI,CAACnB,KAAK,CAACiB,CAAC,CAAC,EAAEvB,MAAM,GAAGuB,CAAC,CAAC;IAC7C;EACJ;EACAhB,QAAQA,CAAA,EAAG;IACP,OAAO,IAAI,CAACD,KAAK,CAACoB,GAAG,CAACR,qBAAqB,CAAC,CAACS,IAAI,CAAC,GAAG,CAAC;EAC1D;EACA,OAAOvB,IAAIA,CAAA,EAAG;IACV,OAAO,IAAIkB,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;EAC7C;EACA,OAAOM,MAAMA,CAAA,EAAG;IACZ,OAAO,IAAIN,UAAU,CAAC,IAAI1B,KAAK,CAAC,CAAC,CAAC,CAACiC,IAAI,CAAC,CAAC,CAAC,CAACH,GAAG,CAAC,MAAMV,IAAI,CAACc,KAAK,CAACd,IAAI,CAACY,MAAM,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;EAC1F;AACJ;AAACpB,OAAA,CAAAc,UAAA,GAAAA,UAAA","ignoreList":[]} |
| export * from './utils'; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"} |
| /// <reference types="node" /> | ||
| export type VectorInit = [number, number, number] | { | ||
| x: number; | ||
| y: number; | ||
| z: number; | ||
| }; | ||
| export declare class Vector { | ||
| x: number; | ||
| y: number; | ||
| z: number; | ||
| constructor(x: number, y: number, z: number); | ||
| static from(init: VectorInit): Vector; | ||
| static readFloatBE(buf: Buffer, offset: number): Vector; | ||
| static readInt32BE(buf: Buffer, offset: number): Vector; | ||
| writeFloatBE(buf: Buffer, offset: number): void; | ||
| writeInt32BE(buf: Buffer, offset: number): void; | ||
| static zero(): Vector; | ||
| get byteLength(): number; | ||
| get bytes(): readonly [number, number, number]; | ||
| toString(): string; | ||
| } | ||
| export type QuaternionInit = [number, number, number, number] | { | ||
| x: number; | ||
| y: number; | ||
| z: number; | ||
| w: number; | ||
| }; | ||
| export declare class Quaternion { | ||
| x: number; | ||
| y: number; | ||
| z: number; | ||
| w: number; | ||
| constructor(x: number, y: number, z: number, w: number); | ||
| static from(init: QuaternionInit): Quaternion; | ||
| static read(buf: Buffer, offset: number): Quaternion; | ||
| write(buf: Buffer, offset: number): void; | ||
| static zero(): Quaternion; | ||
| isSimilarTo(q: Quaternion, e?: number): boolean; | ||
| get byteLength(): number; | ||
| get bytes(): readonly [number, number, number, number]; | ||
| toString(): string; | ||
| } | ||
| export declare const formatMACAddressDigit: (mac: number) => string; | ||
| type MACAddressBytes = [number, number, number, number, number, number]; | ||
| export declare class MACAddress { | ||
| private readonly bytes; | ||
| constructor(bytes: MACAddressBytes); | ||
| write(buf: Buffer, offset: number): void; | ||
| toString(): string; | ||
| static zero(): MACAddress; | ||
| static random(): MACAddress; | ||
| } | ||
| export {}; | ||
| //# sourceMappingURL=utils.d.ts.map |
| {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACxF,qBAAa,MAAM;IACE,CAAC,EAAE,MAAM;IAAS,CAAC,EAAE,MAAM;IAAS,CAAC,EAAE,MAAM;gBAA7C,CAAC,EAAE,MAAM,EAAS,CAAC,EAAE,MAAM,EAAS,CAAC,EAAE,MAAM;IAEhE,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU;IAQ5B,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAI9C,MAAM,CAAC,W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AC,KAAK;gBAAL,KAAK,EAAE,eAAe;IAEnD,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAMjC,QAAQ;IAIR,MAAM,CAAC,IAAI;IAIX,MAAM,CAAC,MAAM;CAGd"} |
| export * from './utils'; |
| export class Vector { | ||
| constructor(x, y, z) { | ||
| this.x = x; | ||
| this.y = y; | ||
| this.z = z; | ||
| } | ||
| static from(init) { | ||
| if (Array.isArray(init)) { | ||
| return new Vector(init[0], init[1], init[2]); | ||
| } | ||
| else { | ||
| return new Vector(init.x, init.y, init.z); | ||
| } | ||
| } | ||
| static readFloatBE(buf, offset) { | ||
| return new Vector(buf.readFloatBE(offset), buf.readFloatBE(offset + 4), buf.readFloatBE(offset + 8)); | ||
| } | ||
| static readInt32BE(buf, offset) { | ||
| return new Vector(buf.readInt32BE(offset), buf.readInt32BE(offset + 4), buf.readInt32BE(offset + 8)); | ||
| } | ||
| writeFloatBE(buf, offset) { | ||
| buf.writeFloatBE(this.x, offset); | ||
| buf.writeFloatBE(this.y, offset + 4); | ||
| buf.writeFloatBE(this.z, offset + 8); | ||
| } | ||
| writeInt32BE(buf, offset) { | ||
| buf.writeInt32BE(this.x, offset); | ||
| buf.writeInt32BE(this.y, offset + 4); | ||
| buf.writeInt32BE(this.z, offset + 8); | ||
| } | ||
| static zero() { | ||
| return new Vector(0, 0, 0); | ||
| } | ||
| get byteLength() { | ||
| return 3 * 4; | ||
| } | ||
| get bytes() { | ||
| return [this.x, this.y, this.z]; | ||
| } | ||
| toString() { | ||
| return `(${this.x}, ${this.y}, ${this.z})`; | ||
| } | ||
| } | ||
| export class Quaternion { | ||
| constructor(x, y, z, w) { | ||
| this.x = x; | ||
| this.y = y; | ||
| this.z = z; | ||
| this.w = w; | ||
| } | ||
| static from(init) { | ||
| if (Array.isArray(init)) { | ||
| return new Quaternion(init[0], init[1], init[2], init[3]); | ||
| } | ||
| else { | ||
| return new Quaternion(init.x, init.y, init.z, init.w); | ||
| } | ||
| } | ||
| static read(buf, offset) { | ||
| return new Quaternion(buf.readFloatBE(offset), buf.readFloatBE(offset + 4), buf.readFloatBE(offset + 8), buf.readFloatBE(offset + 12)); | ||
| } | ||
| write(buf, offset) { | ||
| buf.writeFloatBE(this.x, offset); | ||
| buf.writeFloatBE(this.y, offset + 4); | ||
| buf.writeFloatBE(this.z, offset + 8); | ||
| buf.writeFloatBE(this.w, offset + 12); | ||
| } | ||
| static zero() { | ||
| return new Quaternion(0, 0, 0, 1); | ||
| } | ||
| isSimilarTo(q, e = 0.0001) { | ||
| return (Math.abs(this.x - q.x) < e && | ||
| Math.abs(this.y - q.y) < e && | ||
| Math.abs(this.z - q.z) < e && | ||
| Math.abs(this.w - q.w) < e); | ||
| } | ||
| get byteLength() { | ||
| return 4 * 4; | ||
| } | ||
| get bytes() { | ||
| return [this.x, this.y, this.z, this.w]; | ||
| } | ||
| toString() { | ||
| return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`; | ||
| } | ||
| } | ||
| export const formatMACAddressDigit = (mac) => { | ||
| return mac.toString(16).padStart(2, '0').toUpperCase(); | ||
| }; | ||
| export class MACAddress { | ||
| constructor(bytes) { | ||
| this.bytes = bytes; | ||
| } | ||
| write(buf, offset) { | ||
| for (let i = 0; i < this.bytes.length; i++) { | ||
| buf.writeUInt8(this.bytes[i], offset + i); | ||
| } | ||
| } | ||
| toString() { | ||
| return this.bytes.map(formatMACAddressDigit).join(':'); | ||
| } | ||
| static zero() { | ||
| return new MACAddress([0, 0, 0, 0, 0, 0]); | ||
| } | ||
| static random() { | ||
| return new MACAddress(new Array(6).fill(0).map(() => Math.floor(Math.random() * 256))); | ||
| } | ||
| } |
| export * from './utils'; |
+129
| export type VectorInit = [number, number, number] | { x: number; y: number; z: number }; | ||
| export class Vector { | ||
| constructor(public x: number, public y: number, public z: number) {} | ||
| static from(init: VectorInit) { | ||
| if (Array.isArray(init)) { | ||
| return new Vector(init[0], init[1], init[2]); | ||
| } else { | ||
| return new Vector(init.x, init.y, init.z); | ||
| } | ||
| } | ||
| static readFloatBE(buf: Buffer, offset: number) { | ||
| return new Vector(buf.readFloatBE(offset), buf.readFloatBE(offset + 4), buf.readFloatBE(offset + 8)); | ||
| } | ||
| static readInt32BE(buf: Buffer, offset: number) { | ||
| return new Vector(buf.readInt32BE(offset), buf.readInt32BE(offset + 4), buf.readInt32BE(offset + 8)); | ||
| } | ||
| writeFloatBE(buf: Buffer, offset: number) { | ||
| buf.writeFloatBE(this.x, offset); | ||
| buf.writeFloatBE(this.y, offset + 4); | ||
| buf.writeFloatBE(this.z, offset + 8); | ||
| } | ||
| writeInt32BE(buf: Buffer, offset: number) { | ||
| buf.writeInt32BE(this.x, offset); | ||
| buf.writeInt32BE(this.y, offset + 4); | ||
| buf.writeInt32BE(this.z, offset + 8); | ||
| } | ||
| static zero() { | ||
| return new Vector(0, 0, 0); | ||
| } | ||
| get byteLength() { | ||
| return 3 * 4; | ||
| } | ||
| get bytes() { | ||
| return [this.x, this.y, this.z] as const; | ||
| } | ||
| toString() { | ||
| return `(${this.x}, ${this.y}, ${this.z})`; | ||
| } | ||
| } | ||
| export type QuaternionInit = [number, number, number, number] | { x: number; y: number; z: number; w: number }; | ||
| export class Quaternion { | ||
| constructor(public x: number, public y: number, public z: number, public w: number) {} | ||
| static from(init: QuaternionInit) { | ||
| if (Array.isArray(init)) { | ||
| return new Quaternion(init[0], init[1], init[2], init[3]); | ||
| } else { | ||
| return new Quaternion(init.x, init.y, init.z, init.w); | ||
| } | ||
| } | ||
| static read(buf: Buffer, offset: number) { | ||
| return new Quaternion( | ||
| buf.readFloatBE(offset), | ||
| buf.readFloatBE(offset + 4), | ||
| buf.readFloatBE(offset + 8), | ||
| buf.readFloatBE(offset + 12) | ||
| ); | ||
| } | ||
| write(buf: Buffer, offset: number) { | ||
| buf.writeFloatBE(this.x, offset); | ||
| buf.writeFloatBE(this.y, offset + 4); | ||
| buf.writeFloatBE(this.z, offset + 8); | ||
| buf.writeFloatBE(this.w, offset + 12); | ||
| } | ||
| static zero() { | ||
| return new Quaternion(0, 0, 0, 1); | ||
| } | ||
| isSimilarTo(q: Quaternion, e = 0.0001) { | ||
| return ( | ||
| Math.abs(this.x - q.x) < e && | ||
| Math.abs(this.y - q.y) < e && | ||
| Math.abs(this.z - q.z) < e && | ||
| Math.abs(this.w - q.w) < e | ||
| ); | ||
| } | ||
| get byteLength() { | ||
| return 4 * 4; | ||
| } | ||
| get bytes() { | ||
| return [this.x, this.y, this.z, this.w] as const; | ||
| } | ||
| toString() { | ||
| return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`; | ||
| } | ||
| } | ||
| export const formatMACAddressDigit = (mac: number) => { | ||
| return mac.toString(16).padStart(2, '0').toUpperCase(); | ||
| }; | ||
| type MACAddressBytes = [number, number, number, number, number, number]; | ||
| export class MACAddress { | ||
| constructor(private readonly bytes: MACAddressBytes) {} | ||
| write(buf: Buffer, offset: number) { | ||
| for (let i = 0; i < this.bytes.length; i++) { | ||
| buf.writeUInt8(this.bytes[i], offset + i); | ||
| } | ||
| } | ||
| toString() { | ||
| return this.bytes.map(formatMACAddressDigit).join(':'); | ||
| } | ||
| static zero() { | ||
| return new MACAddress([0, 0, 0, 0, 0, 0]); | ||
| } | ||
| static random() { | ||
| return new MACAddress(new Array(6).fill(0).map(() => Math.floor(Math.random() * 256)) as MACAddressBytes); | ||
| } | ||
| } |
+10
-7
| { | ||
| "name": "@slimevr/common", | ||
| "version": "0.1.0", | ||
| "version": "0.1.1", | ||
| "license": "(MIT OR Apache-2.0)", | ||
| "main": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "module": "dist/index.mjs", | ||
| "main": "dist/cjs/index.js", | ||
| "types": "dist/dts/index.d.ts", | ||
| "module": "dist/esm/index.js", | ||
| "type": "module", | ||
| "publishConfig": { | ||
@@ -13,9 +14,11 @@ "access": "public" | ||
| "@types/node": "^18.17.2", | ||
| "tsup": "^7.2.0", | ||
| "@slimevr/tsconfig": "0.0.1" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsup src/index.ts --format cjs,esm --dts", | ||
| "dev": "pnpm build -- --watch" | ||
| "build": "pnpm run build:esm && pnpm run build:cjs", | ||
| "build:esm": "tsc", | ||
| "build:cjs": "babel dist/esm --plugins @babel/transform-export-namespace-from --plugins @babel/transform-modules-commonjs --out-dir dist/cjs --source-maps", | ||
| "dev": "pnpm build:esm -- -w", | ||
| "clean": "rimraf dist" | ||
| } | ||
| } |
| declare type VectorInit = [number, number, number] | { | ||
| x: number; | ||
| y: number; | ||
| z: number; | ||
| }; | ||
| declare class Vector { | ||
| x: number; | ||
| y: number; | ||
| z: number; | ||
| constructor(x: number, y: number, z: number); | ||
| static from(init: VectorInit): Vector; | ||
| static readFloatBE(buf: Buffer, offset: number): Vector; | ||
| static readInt32BE(buf: Buffer, offset: number): Vector; | ||
| writeFloatBE(buf: Buffer, offset: number): void; | ||
| writeInt32BE(buf: Buffer, offset: number): void; | ||
| static zero(): Vector; | ||
| get byteLength(): number; | ||
| get bytes(): readonly [number, number, number]; | ||
| toString(): string; | ||
| } | ||
| declare type QuaternionInit = [number, number, number, number] | { | ||
| x: number; | ||
| y: number; | ||
| z: number; | ||
| w: number; | ||
| }; | ||
| declare class Quaternion { | ||
| x: number; | ||
| y: number; | ||
| z: number; | ||
| w: number; | ||
| constructor(x: number, y: number, z: number, w: number); | ||
| static from(init: QuaternionInit): Quaternion; | ||
| static read(buf: Buffer, offset: number): Quaternion; | ||
| write(buf: Buffer, offset: number): void; | ||
| static zero(): Quaternion; | ||
| isSimilarTo(q: Quaternion, e?: number): boolean; | ||
| get byteLength(): number; | ||
| get bytes(): readonly [number, number, number, number]; | ||
| toString(): string; | ||
| } | ||
| declare const formatMACAddressDigit: (mac: number) => string; | ||
| declare type MACAddressBytes = [number, number, number, number, number, number]; | ||
| declare class MACAddress { | ||
| private readonly bytes; | ||
| constructor(bytes: MACAddressBytes); | ||
| write(buf: Buffer, offset: number): void; | ||
| toString(): string; | ||
| static zero(): MACAddress; | ||
| static random(): MACAddress; | ||
| } | ||
| export { MACAddress, Quaternion, QuaternionInit, Vector, VectorInit, formatMACAddressDigit }; |
| declare type VectorInit = [number, number, number] | { | ||
| x: number; | ||
| y: number; | ||
| z: number; | ||
| }; | ||
| declare class Vector { | ||
| x: number; | ||
| y: number; | ||
| z: number; | ||
| constructor(x: number, y: number, z: number); | ||
| static from(init: VectorInit): Vector; | ||
| static readFloatBE(buf: Buffer, offset: number): Vector; | ||
| static readInt32BE(buf: Buffer, offset: number): Vector; | ||
| writeFloatBE(buf: Buffer, offset: number): void; | ||
| writeInt32BE(buf: Buffer, offset: number): void; | ||
| static zero(): Vector; | ||
| get byteLength(): number; | ||
| get bytes(): readonly [number, number, number]; | ||
| toString(): string; | ||
| } | ||
| declare type QuaternionInit = [number, number, number, number] | { | ||
| x: number; | ||
| y: number; | ||
| z: number; | ||
| w: number; | ||
| }; | ||
| declare class Quaternion { | ||
| x: number; | ||
| y: number; | ||
| z: number; | ||
| w: number; | ||
| constructor(x: number, y: number, z: number, w: number); | ||
| static from(init: QuaternionInit): Quaternion; | ||
| static read(buf: Buffer, offset: number): Quaternion; | ||
| write(buf: Buffer, offset: number): void; | ||
| static zero(): Quaternion; | ||
| isSimilarTo(q: Quaternion, e?: number): boolean; | ||
| get byteLength(): number; | ||
| get bytes(): readonly [number, number, number, number]; | ||
| toString(): string; | ||
| } | ||
| declare const formatMACAddressDigit: (mac: number) => string; | ||
| declare type MACAddressBytes = [number, number, number, number, number, number]; | ||
| declare class MACAddress { | ||
| private readonly bytes; | ||
| constructor(bytes: MACAddressBytes); | ||
| write(buf: Buffer, offset: number): void; | ||
| toString(): string; | ||
| static zero(): MACAddress; | ||
| static random(): MACAddress; | ||
| } | ||
| export { MACAddress, Quaternion, QuaternionInit, Vector, VectorInit, formatMACAddressDigit }; |
-145
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/index.ts | ||
| var src_exports = {}; | ||
| __export(src_exports, { | ||
| MACAddress: () => MACAddress, | ||
| Quaternion: () => Quaternion, | ||
| Vector: () => Vector, | ||
| formatMACAddressDigit: () => formatMACAddressDigit | ||
| }); | ||
| module.exports = __toCommonJS(src_exports); | ||
| // src/utils.ts | ||
| var Vector = class _Vector { | ||
| constructor(x, y, z) { | ||
| this.x = x; | ||
| this.y = y; | ||
| this.z = z; | ||
| } | ||
| static from(init) { | ||
| if (Array.isArray(init)) { | ||
| return new _Vector(init[0], init[1], init[2]); | ||
| } else { | ||
| return new _Vector(init.x, init.y, init.z); | ||
| } | ||
| } | ||
| static readFloatBE(buf, offset) { | ||
| return new _Vector(buf.readFloatBE(offset), buf.readFloatBE(offset + 4), buf.readFloatBE(offset + 8)); | ||
| } | ||
| static readInt32BE(buf, offset) { | ||
| return new _Vector(buf.readInt32BE(offset), buf.readInt32BE(offset + 4), buf.readInt32BE(offset + 8)); | ||
| } | ||
| writeFloatBE(buf, offset) { | ||
| buf.writeFloatBE(this.x, offset); | ||
| buf.writeFloatBE(this.y, offset + 4); | ||
| buf.writeFloatBE(this.z, offset + 8); | ||
| } | ||
| writeInt32BE(buf, offset) { | ||
| buf.writeInt32BE(this.x, offset); | ||
| buf.writeInt32BE(this.y, offset + 4); | ||
| buf.writeInt32BE(this.z, offset + 8); | ||
| } | ||
| static zero() { | ||
| return new _Vector(0, 0, 0); | ||
| } | ||
| get byteLength() { | ||
| return 3 * 4; | ||
| } | ||
| get bytes() { | ||
| return [this.x, this.y, this.z]; | ||
| } | ||
| toString() { | ||
| return `(${this.x}, ${this.y}, ${this.z})`; | ||
| } | ||
| }; | ||
| var Quaternion = class _Quaternion { | ||
| constructor(x, y, z, w) { | ||
| this.x = x; | ||
| this.y = y; | ||
| this.z = z; | ||
| this.w = w; | ||
| } | ||
| static from(init) { | ||
| if (Array.isArray(init)) { | ||
| return new _Quaternion(init[0], init[1], init[2], init[3]); | ||
| } else { | ||
| return new _Quaternion(init.x, init.y, init.z, init.w); | ||
| } | ||
| } | ||
| static read(buf, offset) { | ||
| return new _Quaternion( | ||
| buf.readFloatBE(offset), | ||
| buf.readFloatBE(offset + 4), | ||
| buf.readFloatBE(offset + 8), | ||
| buf.readFloatBE(offset + 12) | ||
| ); | ||
| } | ||
| write(buf, offset) { | ||
| buf.writeFloatBE(this.x, offset); | ||
| buf.writeFloatBE(this.y, offset + 4); | ||
| buf.writeFloatBE(this.z, offset + 8); | ||
| buf.writeFloatBE(this.w, offset + 12); | ||
| } | ||
| static zero() { | ||
| return new _Quaternion(0, 0, 0, 1); | ||
| } | ||
| isSimilarTo(q, e = 1e-4) { | ||
| return Math.abs(this.x - q.x) < e && Math.abs(this.y - q.y) < e && Math.abs(this.z - q.z) < e && Math.abs(this.w - q.w) < e; | ||
| } | ||
| get byteLength() { | ||
| return 4 * 4; | ||
| } | ||
| get bytes() { | ||
| return [this.x, this.y, this.z, this.w]; | ||
| } | ||
| toString() { | ||
| return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`; | ||
| } | ||
| }; | ||
| var formatMACAddressDigit = (mac) => { | ||
| return mac.toString(16).padStart(2, "0").toUpperCase(); | ||
| }; | ||
| var MACAddress = class _MACAddress { | ||
| constructor(bytes) { | ||
| this.bytes = bytes; | ||
| } | ||
| write(buf, offset) { | ||
| for (let i = 0; i < this.bytes.length; i++) { | ||
| buf.writeUInt8(this.bytes[i], offset + i); | ||
| } | ||
| } | ||
| toString() { | ||
| return this.bytes.map(formatMACAddressDigit).join(":"); | ||
| } | ||
| static zero() { | ||
| return new _MACAddress([0, 0, 0, 0, 0, 0]); | ||
| } | ||
| static random() { | ||
| return new _MACAddress(new Array(6).fill(0).map(() => Math.floor(Math.random() * 256))); | ||
| } | ||
| }; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| MACAddress, | ||
| Quaternion, | ||
| Vector, | ||
| formatMACAddressDigit | ||
| }); |
-115
| // src/utils.ts | ||
| var Vector = class _Vector { | ||
| constructor(x, y, z) { | ||
| this.x = x; | ||
| this.y = y; | ||
| this.z = z; | ||
| } | ||
| static from(init) { | ||
| if (Array.isArray(init)) { | ||
| return new _Vector(init[0], init[1], init[2]); | ||
| } else { | ||
| return new _Vector(init.x, init.y, init.z); | ||
| } | ||
| } | ||
| static readFloatBE(buf, offset) { | ||
| return new _Vector(buf.readFloatBE(offset), buf.readFloatBE(offset + 4), buf.readFloatBE(offset + 8)); | ||
| } | ||
| static readInt32BE(buf, offset) { | ||
| return new _Vector(buf.readInt32BE(offset), buf.readInt32BE(offset + 4), buf.readInt32BE(offset + 8)); | ||
| } | ||
| writeFloatBE(buf, offset) { | ||
| buf.writeFloatBE(this.x, offset); | ||
| buf.writeFloatBE(this.y, offset + 4); | ||
| buf.writeFloatBE(this.z, offset + 8); | ||
| } | ||
| writeInt32BE(buf, offset) { | ||
| buf.writeInt32BE(this.x, offset); | ||
| buf.writeInt32BE(this.y, offset + 4); | ||
| buf.writeInt32BE(this.z, offset + 8); | ||
| } | ||
| static zero() { | ||
| return new _Vector(0, 0, 0); | ||
| } | ||
| get byteLength() { | ||
| return 3 * 4; | ||
| } | ||
| get bytes() { | ||
| return [this.x, this.y, this.z]; | ||
| } | ||
| toString() { | ||
| return `(${this.x}, ${this.y}, ${this.z})`; | ||
| } | ||
| }; | ||
| var Quaternion = class _Quaternion { | ||
| constructor(x, y, z, w) { | ||
| this.x = x; | ||
| this.y = y; | ||
| this.z = z; | ||
| this.w = w; | ||
| } | ||
| static from(init) { | ||
| if (Array.isArray(init)) { | ||
| return new _Quaternion(init[0], init[1], init[2], init[3]); | ||
| } else { | ||
| return new _Quaternion(init.x, init.y, init.z, init.w); | ||
| } | ||
| } | ||
| static read(buf, offset) { | ||
| return new _Quaternion( | ||
| buf.readFloatBE(offset), | ||
| buf.readFloatBE(offset + 4), | ||
| buf.readFloatBE(offset + 8), | ||
| buf.readFloatBE(offset + 12) | ||
| ); | ||
| } | ||
| write(buf, offset) { | ||
| buf.writeFloatBE(this.x, offset); | ||
| buf.writeFloatBE(this.y, offset + 4); | ||
| buf.writeFloatBE(this.z, offset + 8); | ||
| buf.writeFloatBE(this.w, offset + 12); | ||
| } | ||
| static zero() { | ||
| return new _Quaternion(0, 0, 0, 1); | ||
| } | ||
| isSimilarTo(q, e = 1e-4) { | ||
| return Math.abs(this.x - q.x) < e && Math.abs(this.y - q.y) < e && Math.abs(this.z - q.z) < e && Math.abs(this.w - q.w) < e; | ||
| } | ||
| get byteLength() { | ||
| return 4 * 4; | ||
| } | ||
| get bytes() { | ||
| return [this.x, this.y, this.z, this.w]; | ||
| } | ||
| toString() { | ||
| return `(${this.x}, ${this.y}, ${this.z}, ${this.w})`; | ||
| } | ||
| }; | ||
| var formatMACAddressDigit = (mac) => { | ||
| return mac.toString(16).padStart(2, "0").toUpperCase(); | ||
| }; | ||
| var MACAddress = class _MACAddress { | ||
| constructor(bytes) { | ||
| this.bytes = bytes; | ||
| } | ||
| write(buf, offset) { | ||
| for (let i = 0; i < this.bytes.length; i++) { | ||
| buf.writeUInt8(this.bytes[i], offset + i); | ||
| } | ||
| } | ||
| toString() { | ||
| return this.bytes.map(formatMACAddressDigit).join(":"); | ||
| } | ||
| static zero() { | ||
| return new _MACAddress([0, 0, 0, 0, 0, 0]); | ||
| } | ||
| static random() { | ||
| return new _MACAddress(new Array(6).fill(0).map(() => Math.floor(Math.random() * 256))); | ||
| } | ||
| }; | ||
| export { | ||
| MACAddress, | ||
| Quaternion, | ||
| Vector, | ||
| formatMACAddressDigit | ||
| }; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23463
114.78%2
-33.33%13
160%396
27.74%Yes
NaN