Skip to content

Commit 0aef010

Browse files
committed
refactor: reorder methods
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent d6074e2 commit 0aef010

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed

lib/node_modules/@stdlib/dstructs/struct/lib/main.js

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,25 @@ function factory( fields ) {
320320
return layoutFormat( FIELDS );
321321
});
322322

323+
/**
324+
* Returns the underlying byte buffer of a `struct`.
325+
*
326+
* @private
327+
* @name bufferOf
328+
* @memberof Struct
329+
* @readonly
330+
* @type {Function}
331+
* @param {Object} obj - struct instance
332+
* @throws {TypeError} must provide a `struct` instance
333+
* @returns {ArrayBuffer} underlying byte buffer
334+
*/
335+
setReadOnly( Struct, 'bufferOf', function bufferOf( obj ) {
336+
if ( !isStructInstance( obj ) ) {
337+
throw new TypeError( format( 'invalid argument. First argument must be a `struct` instance. Value: `%s`.', obj ) );
338+
}
339+
return obj[ PRIVATE_BUFFER ].buffer;
340+
});
341+
323342
/**
324343
* Returns the length, in bytes, of the value specified by the provided field name.
325344
*
@@ -383,46 +402,6 @@ function factory( fields ) {
383402
return FIELDS[ idx ].description;
384403
});
385404

386-
/**
387-
* Returns the type associated with a provided field name.
388-
*
389-
* @private
390-
* @name typeOf
391-
* @memberof Struct
392-
* @readonly
393-
* @type {Function}
394-
* @param {string} name - field name
395-
* @throws {Error} struct must have at least one field
396-
* @throws {TypeError} must provide a recognized field name
397-
* @returns {(string|Object)} type
398-
*/
399-
setReadOnly( Struct, 'typeOf', function typeOf( name ) {
400-
var idx = fieldIndex( FIELD_NAMES, name );
401-
if ( idx instanceof Error ) {
402-
throw idx;
403-
}
404-
return FIELDS[ idx ].type;
405-
});
406-
407-
/**
408-
* Returns the underlying byte buffer of a `struct`.
409-
*
410-
* @private
411-
* @name bufferOf
412-
* @memberof Struct
413-
* @readonly
414-
* @type {Function}
415-
* @param {Object} obj - struct instance
416-
* @throws {TypeError} must provide a `struct` instance
417-
* @returns {ArrayBuffer} underlying byte buffer
418-
*/
419-
setReadOnly( Struct, 'bufferOf', function bufferOf( obj ) {
420-
if ( !isStructInstance( obj ) ) {
421-
throw new TypeError( format( 'invalid argument. First argument must be a `struct` instance. Value: `%s`.', obj ) );
422-
}
423-
return obj[ PRIVATE_BUFFER ].buffer;
424-
});
425-
426405
/**
427406
* Returns a boolean indicating whether a provided value is a `struct` instance.
428407
*
@@ -444,6 +423,27 @@ function factory( fields ) {
444423
);
445424
});
446425

426+
/**
427+
* Returns the type associated with a provided field name.
428+
*
429+
* @private
430+
* @name typeOf
431+
* @memberof Struct
432+
* @readonly
433+
* @type {Function}
434+
* @param {string} name - field name
435+
* @throws {Error} struct must have at least one field
436+
* @throws {TypeError} must provide a recognized field name
437+
* @returns {(string|Object)} type
438+
*/
439+
setReadOnly( Struct, 'typeOf', function typeOf( name ) {
440+
var idx = fieldIndex( FIELD_NAMES, name );
441+
if ( idx instanceof Error ) {
442+
throw idx;
443+
}
444+
return FIELDS[ idx ].type;
445+
});
446+
447447
/**
448448
* Returns the underlying byte buffer of a `struct` as a `DataView`.
449449
*
@@ -493,7 +493,7 @@ function factory( fields ) {
493493
} else {
494494
opts = {};
495495
}
496-
return struct2string( this, FIELDS, opts );
496+
return struct2string( Struct, FIELDS, opts );
497497
});
498498

499499
/**

lib/node_modules/@stdlib/dstructs/struct/lib/to_string.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ var isFormat = contains( FORMATS );
4242
// MAIN //
4343

4444
/**
45-
* Serializes a `struct` instance to a string.
45+
* Serializes a struct to a string.
4646
*
4747
* @private
48-
* @param {Struct} struct - struct instance
48+
* @param {Function} Struct - struct constructor
4949
* @param {Array<Object>} fields - list of normalized fields
5050
* @param {Options} options - function options
5151
* @param {string} [options.format] - serialization format
5252
* @throws {TypeError} options argument must be an object
5353
* @throws {TypeError} must provide valid options
5454
* @returns {string} string representation
5555
*/
56-
function toString( struct, fields, options ) { // eslint-disable-line stdlib/no-redeclare
56+
function toString( Struct, fields, options ) { // eslint-disable-line stdlib/no-redeclare
5757
var opts;
5858
if ( !isPlainObject( options ) ) {
5959
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
@@ -68,7 +68,7 @@ function toString( struct, fields, options ) { // eslint-disable-line stdlib/no-
6868
}
6969
}
7070
if ( opts.format === 'linear' ) {
71-
return linearFormat( struct.constructor, fields );
71+
return linearFormat( Struct, fields );
7272
}
7373
if ( opts.format === 'layout' ) {
7474
return layoutFormat( fields );

0 commit comments

Comments
 (0)