From 78cbb857bb58770948c0beee01c80d22e2b77918 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 10 Nov 2023 08:04:23 +0000 Subject: [PATCH] style: format code with Prettier and StandardJS This commit fixes the style issues introduced in ee34cb8 according to the output from Prettier and StandardJS. Details: None --- README.md | 2 +- src/Binary.js | 72 +++++++++++++++++++++++----------------------- src/BinaryArray.js | 70 ++++++++++++++++++++++---------------------- src/index.test.js | 22 +++++++------- 4 files changed, 83 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index 7c4d927..39341ba 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ class MyBinaryClass extends Binary { Object.defineProperty( MyBinaryClass.prototype, "someMember", - binary(Types.Float32) + binary(Types.Float32), ); ``` diff --git a/src/Binary.js b/src/Binary.js index b769ca7..374c4ec 100644 --- a/src/Binary.js +++ b/src/Binary.js @@ -1,7 +1,7 @@ // Not efficient enough... -//import { nonenumerable } from 'core-decorators'; +// import { nonenumerable } from 'core-decorators'; -import Types from "./Types"; +import Types from './Types' /** Class allowing `@binary` members */ class Binary { @@ -11,24 +11,24 @@ class Binary { // Class props // Slowers down 4x times... - //@nonenumerable - static _size; + // @nonenumerable + static _size /** * Static getter for the class binary size * @return {number} - The class binary size */ - static get binarySize() { - return this._size; + static get binarySize () { + return this._size } - //@nonenumerable - static _binaryProps; + // @nonenumerable + static _binaryProps /** * Static getter for the class binary props * @return {array} - The list of binary props */ - static get binaryProps() { - return this._binaryProps; + static get binaryProps () { + return this._binaryProps } /** @@ -39,35 +39,35 @@ class Binary { * @param {array} list - The array where new objects will be added * @return {array} - The array {@link list} where the objects have been added */ - //@nonenumerable - static arrayFactory(binOrDV, length, initialOffset = 0, list = []) { + // @nonenumerable + static arrayFactory (binOrDV, length, initialOffset = 0, list = []) { // Optimize: Generate a single DataView for all elements - const dv = binOrDV instanceof DataView ? binOrDV : new DataView(binOrDV); + const dv = binOrDV instanceof DataView ? binOrDV : new DataView(binOrDV) for (let i = 0; i < length; i++) { - list.push(new this(dv, initialOffset + this._size * i)); + list.push(new this(dv, initialOffset + this._size * i)) } - return list; + return list } // Prototype props - //@nonenumerable - _initialOffset; - //@nonenumerable - _bin; - //@nonenumerable - __dv; + // @nonenumerable + _initialOffset + // @nonenumerable + _bin + // @nonenumerable + __dv /** * Getter of the DataView containing this object's data * @return {DataView} - The DataView */ - //@nonenumerable - get _dv() { + // @nonenumerable + get _dv () { this.__dv = this?.__dv ?? - new DataView(this._bin, this._initialOffset, this.constructor._size); - return this.__dv; + new DataView(this._bin, this._initialOffset, this.constructor._size) + return this.__dv } /** @@ -75,15 +75,15 @@ class Binary { * @return {string} - The JSON string * @method */ - //@nonenumerable + // @nonenumerable toJSON = () => this.constructor._binaryProps.reduce( (acc, prop) => ({ ...acc, - [prop]: this[prop], + [prop]: this[prop] }), {} - ); + ) /** * Save own initial offset at binary data @@ -91,14 +91,14 @@ class Binary { * @param {number} initialOffset - Buffer offset before this object data start * @param {boolean} isLazy - If true and {@link binOrDv} is not a {DataView}, wait until first acces before Instantiating the __dv */ - constructor(binOrDV, initialOffset = 0, isLazy = true) { - this._initialOffset = initialOffset; + constructor (binOrDV, initialOffset = 0, isLazy = true) { + this._initialOffset = initialOffset if (binOrDV instanceof DataView) { - this.__dv = binOrDV; + this.__dv = binOrDV } else { - this._bin = binOrDV; + this._bin = binOrDV if (!isLazy) { - this._dv; // Call getter + this._dv // Call getter } } } @@ -109,9 +109,9 @@ class Binary { * @return {number} - The unsigned numerical number at the specified position * @method */ - //@nonenumerable + // @nonenumerable getByteAt = (offset) => - Types.Uint8.get(this._dv, this._initialOffset + offset); + Types.Uint8.get(this._dv, this._initialOffset + offset) } /* @@ -134,4 +134,4 @@ Object.defineProperty(Binary, "binaryProps", { }); */ -export default Binary; +export default Binary diff --git a/src/BinaryArray.js b/src/BinaryArray.js index 4ce69c0..2c33325 100644 --- a/src/BinaryArray.js +++ b/src/BinaryArray.js @@ -1,15 +1,15 @@ /** Class for returning array members from {@link Binary} objects */ class BinaryArrayBase { // @member - type; + type // @member - dv; + dv // @member - offset; + offset // @member - length; + length // @member - bytes; + bytes /** * Creates a new customized array @@ -18,12 +18,12 @@ class BinaryArrayBase { * @param {number} offset - The offset of the first member of the array into the buffer * @param {number} length - The length of the array */ - constructor(dv, type, offset, length) { - this.type = type; - this.dv = dv; - this.offset = offset; - this.length = length; - this.bytes = length * type.bytes; + constructor (dv, type, offset, length) { + this.type = type + this.dv = dv + this.offset = offset + this.length = length + this.bytes = length * type.bytes } /** @@ -32,8 +32,8 @@ class BinaryArrayBase { * @return {array} - The new generated array (not bound to original values) * @method */ - map = (fn) => Array.from(this, fn); - //reduce = (...args) => Array.prototype.reduce.call([...this], ...args); + map = (fn) => Array.from(this, fn) + // reduce = (...args) => Array.prototype.reduce.call([...this], ...args); /** * Transform this array into a JSON string @@ -50,20 +50,20 @@ class BinaryArrayBase { * @yield {any} - Each of this array elements of type {@link Types} * @name iterator */ - *[Symbol.iterator]() { + * [Symbol.iterator] () { // Deconstruct to optimize and ease reading const { length, dv, offset, - type: { get, bytes }, - } = this; + type: { get, bytes } + } = this // Use a new index for each iterator. This makes multiple // iterations over the iterable safe for non-trivial cases, // such as use of break or nested looping over the same iterable. for (let index = 0; index < length; index++) { - yield get(dv, offset + bytes * index); + yield get(dv, offset + bytes * index) } } } @@ -79,23 +79,23 @@ const BinaryArrayHandler = { * @param {string} prop - The property to return (only handled when prop is a string representing a number) * @return {any} - The element at {@link prop} position, or a reflected value from {@link target} */ - get(target, prop) { + get (target, prop) { // Very inefficient way // Need to: // - Override Array internals, but are private // - Override `[]` operator, but it's not possible - if (prop === "0" || (typeof prop === "string" && Number(prop) > 0)) { + if (prop === '0' || (typeof prop === 'string' && Number(prop) > 0)) { // Destructure to optimize const { dv, offset, - type: { get, bytes }, - } = target; - return get(dv, offset + bytes * Number(prop)); + type: { get, bytes } + } = target + return get(dv, offset + bytes * Number(prop)) } // Return original value - return Reflect.get(target, prop); + return Reflect.get(target, prop) }, /** @@ -105,20 +105,20 @@ const BinaryArrayHandler = { * @param {any} value - The value to assign to the {@link prop}'th element * @return {boolean} - If {@link prop} is numericalish, true (as needed for JS setters), else the return value from the {@link target} reflected setter */ - set(target, prop, value) { - if (prop === "0" || (typeof prop === "string" && Number(prop) > 0)) { + set (target, prop, value) { + if (prop === '0' || (typeof prop === 'string' && Number(prop) > 0)) { // Destructure to optimize const { dv, offset, - type: { set, bytes }, - } = target; - set(dv, offset + bytes * Number(prop), value); - return true; + type: { set, bytes } + } = target + set(dv, offset + bytes * Number(prop), value) + return true } - return Reflect.set(target, prop, value); - }, -}; + return Reflect.set(target, prop, value) + } +} // #TODO: BUG: Argument Spread Operator not working // well when packing with webpack @@ -134,7 +134,7 @@ const BinaryArray = (dv, type, offset, length) => { return new Proxy( new BinaryArrayBase(dv, type, offset, length), BinaryArrayHandler - ); -}; + ) +} -export default BinaryArray; +export default BinaryArray diff --git a/src/index.test.js b/src/index.test.js index 9e3ff09..896a546 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -400,7 +400,7 @@ test("Instantiate an object with a binary data using an initial offset > 0", () const expectedValues = [1, 2, 3]; const values = expectedValues.map((_, index) => - initialsDV.getInt32(index * 4) + initialsDV.getInt32(index * 4), ); expect(values).toEqual(expectedValues); }); @@ -497,7 +497,7 @@ test("Profile a natural object against a binary object", async () => { await testProfile(`${name} modification array element 2nd phase`, () => { objList.forEach( - ({ testFloatArray }, id) => (testFloatArray[0] = id * 2) + ({ testFloatArray }, id) => (testFloatArray[0] = id * 2), ); }); } @@ -543,13 +543,13 @@ test("Profile a natural object against a binary object", async () => { () => { binTest3 = new ArrayBuffer(BinaryTest.binarySize * iterations); dv3 = new DataView(binTest3); - } + }, ); await testProfile( "Binary Object with pre-created DataView instantation", () => { bDvObjList = BinaryTest.arrayFactory(dv3, iterations); - } + }, ); await testObjList("Binary Object with pre-created DataView", bDvObjList); @@ -591,7 +591,7 @@ test("Profile a natural object against a binary object", async () => { } const binTest2 = new ArrayBuffer( - BinaryWithoutArrayTest.binarySize * iterations + BinaryWithoutArrayTest.binarySize * iterations, ); bwoaObjList = BinaryWithoutArrayTest.arrayFactory(binTest2, iterations); }); @@ -616,7 +616,7 @@ test("Profile a natural object against a binary object", async () => { } const binTest2 = new ArrayBuffer( - BinaryObjectWithDecorator.binarySize * iterations + BinaryObjectWithDecorator.binarySize * iterations, ); bdObjList = BinaryObjectWithDecorator.arrayFactory(binTest2, iterations); }); @@ -643,15 +643,15 @@ test("Profile a natural object against a binary object", async () => { } const binTest2 = new ArrayBuffer( - BinaryObjectWithDecorator.binarySize * iterations + BinaryObjectWithDecorator.binarySize * iterations, ); bdpObjList = BinaryObjectWithDecorator.arrayFactory(binTest2, iterations); - } + }, ); await testObjList( "Binary Object with class decorator and padded array", - bdpObjList + bdpObjList, ); // Show collected metrics in a table @@ -672,7 +672,7 @@ test("Profile a natural object against a binary object", async () => { ...acc, [key]: numberWithCommas(value), }), - {} + {}, ), })) .reduce( @@ -680,7 +680,7 @@ test("Profile a natural object against a binary object", async () => { ...acc, [name]: rest, }), - {} + {}, ); console.table(memoryDiffTable); }, 6e4);