Skip to content

Commit bf26784

Browse files
committed
feat: add isStruct method
This static method is similar to `Buffer.isBuffer` in Node.js. --- 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 fd7b7eb commit bf26784

File tree

1 file changed

+22
-0
lines changed
  • lib/node_modules/@stdlib/dstructs/struct/lib

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
2626
var setNonEnumerableReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' );
27+
var isStructConstructorLike = require( '@stdlib/assert/is-struct-constructor-like' );
2728
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
2829
var isCollection = require( '@stdlib/assert/is-collection' );
2930
var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' );
@@ -422,6 +423,27 @@ function factory( fields ) {
422423
return obj[ PRIVATE_BUFFER ].buffer;
423424
});
424425

426+
/**
427+
* Returns a boolean indicating whether a provided value is a `struct` instance.
428+
*
429+
* @private
430+
* @name isStruct
431+
* @memberof Struct
432+
* @readonly
433+
* @type {Function}
434+
* @param {*} value - input value
435+
* @returns {boolean} boolean indicating whether a value is a `struct` instance
436+
*/
437+
setReadOnly( Struct, 'isStruct', function isStruct( value ) {
438+
return (
439+
value instanceof Struct ||
440+
(
441+
isStructInstance( value ) &&
442+
isStructConstructorLike( value.constructor )
443+
)
444+
);
445+
});
446+
425447
/**
426448
* Returns the underlying byte buffer of a `struct` as a `DataView`.
427449
*

0 commit comments

Comments
 (0)