Skip to content

Commit 3c29c7f

Browse files
committed
Auto-generated commit
1 parent 0540bd4 commit 3c29c7f

File tree

13 files changed

+622
-1
lines changed

13 files changed

+622
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Features
1212

13+
- [`62419d0`](https://github.com/stdlib-js/stdlib/commit/62419d0162b5fc9e4d18a97b67d8a2aea556b1a5) - add `isStruct` to namespace
14+
- [`76f2fd3`](https://github.com/stdlib-js/stdlib/commit/76f2fd3b4df1d68fa5619bbe6cc7ea2878a4bc8e) - add `assert/is-struct`
1315
- [`0ba0d91`](https://github.com/stdlib-js/stdlib/commit/0ba0d912c0608c3fa8daff70874c9fa8de672a3a) - add `isStructConstructorLike` to namespace
1416
- [`67b59c6`](https://github.com/stdlib-js/stdlib/commit/67b59c6d61abd31bc0fa7fadc673a0dbfb02d387) - add `assert/is-struct-constructor-like`
1517
- [`f58120f`](https://github.com/stdlib-js/stdlib/commit/f58120f6a16840c817e26f439224a67e1680e21c) - add header for asserting is a Node-API value is a DataView
@@ -108,6 +110,8 @@ A total of 6 issues were closed in this release:
108110

109111
<details>
110112

113+
- [`62419d0`](https://github.com/stdlib-js/stdlib/commit/62419d0162b5fc9e4d18a97b67d8a2aea556b1a5) - **feat:** add `isStruct` to namespace _(by Athan Reines)_
114+
- [`76f2fd3`](https://github.com/stdlib-js/stdlib/commit/76f2fd3b4df1d68fa5619bbe6cc7ea2878a4bc8e) - **feat:** add `assert/is-struct` _(by Athan Reines)_
111115
- [`edef1e2`](https://github.com/stdlib-js/stdlib/commit/edef1e298a551ed453c4edc3d769746baf5dbde1) - **chore:** minor clean-up _(by Philipp Burckhardt)_
112116
- [`04fbd21`](https://github.com/stdlib-js/stdlib/commit/04fbd2138efb9db2fc14dcff5be31f200004a9e2) - **fix:** add missing `isStruct` method check _(by Athan Reines)_
113117
- [`0ba0d91`](https://github.com/stdlib-js/stdlib/commit/0ba0d912c0608c3fa8daff70874c9fa8de672a3a) - **feat:** add `isStructConstructorLike` to namespace _(by Athan Reines)_

is-struct/README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# isStruct
22+
23+
> Test if a value is a [`struct`][@stdlib/dstructs/struct] instance.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var isStruct = require( '@stdlib/assert/is-struct' );
31+
```
32+
33+
#### isStruct( value )
34+
35+
Tests if a value is a [`struct`][@stdlib/dstructs/struct] instance.
36+
37+
```javascript
38+
var structFactory = require( '@stdlib/dstructs/struct' );
39+
40+
var schema = [
41+
{
42+
'name': 'value',
43+
'type': 'float64'
44+
}
45+
];
46+
var Struct = structFactory( schema );
47+
48+
var bool = isStruct( new Struct() );
49+
// returns true
50+
```
51+
52+
</section>
53+
54+
<!-- /.usage -->
55+
56+
<section class="examples">
57+
58+
## Examples
59+
60+
<!-- eslint no-undef: "error" -->
61+
62+
```javascript
63+
var structFactory = require( '@stdlib/dstructs/struct' );
64+
var isStruct = require( '@stdlib/assert/is-struct' );
65+
66+
var schema = [
67+
{
68+
'name': 'value',
69+
'type': 'float64'
70+
}
71+
];
72+
var Struct = structFactory( schema );
73+
74+
var bool = isStruct( new Struct() );
75+
// returns true
76+
77+
bool = isStruct( [ 1, 2, 3, 4 ] );
78+
// returns false
79+
80+
bool = isStruct( {} );
81+
// returns false
82+
83+
bool = isStruct( null );
84+
// returns false
85+
```
86+
87+
</section>
88+
89+
<!-- /.examples -->
90+
91+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
92+
93+
<section class="related">
94+
95+
</section>
96+
97+
<!-- /.related -->
98+
99+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
100+
101+
<section class="links">
102+
103+
[@stdlib/dstructs/struct]: https://github.com/stdlib-js/dstructs-struct
104+
105+
</section>
106+
107+
<!-- /.links -->

is-struct/benchmark/benchmark.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isBoolean = require( './../../is-boolean' ).isPrimitive;
25+
var Float64Results = require( '@stdlib/stats/base/ztest/one-sample/results/float64' );
26+
var pkg = require( './../package.json' ).name;
27+
var isStruct = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg+'::true', function benchmark( b ) {
33+
var values;
34+
var bool;
35+
var i;
36+
37+
values = [
38+
new Float64Results(),
39+
new Float64Results()
40+
];
41+
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
bool = isStruct( values[ i%values.length ] );
45+
if ( typeof bool !== 'boolean' ) {
46+
b.fail( 'should return a boolean' );
47+
}
48+
}
49+
b.toc();
50+
if ( !isBoolean( bool ) ) {
51+
b.fail( 'should return a boolean' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
});
56+
57+
bench( pkg+'::false', function benchmark( b ) {
58+
var values;
59+
var bool;
60+
var i;
61+
62+
values = [
63+
[ 1, 2, 3 ],
64+
{},
65+
null,
66+
5,
67+
'beep'
68+
];
69+
70+
b.tic();
71+
for ( i = 0; i < b.iterations; i++ ) {
72+
bool = isStruct( values[ i%values.length ] );
73+
if ( typeof bool !== 'boolean' ) {
74+
b.fail( 'should return a boolean' );
75+
}
76+
}
77+
b.toc();
78+
if ( !isBoolean( bool ) ) {
79+
b.fail( 'should return a boolean' );
80+
}
81+
b.pass( 'benchmark finished' );
82+
b.end();
83+
});

is-struct/docs/repl.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
{{alias}}( value )
3+
Tests if a value is a `struct` instance.
4+
5+
Parameters
6+
----------
7+
value: any
8+
Value to test.
9+
10+
Returns
11+
-------
12+
bool: boolean
13+
Boolean indicating whether a value is a `struct` instance.
14+
15+
Examples
16+
--------
17+
> var schema = [ { 'name': 'foo', 'type': 'float64' } ];
18+
> var S = {{alias:@stdlib/dstructs/struct}}( schema );
19+
> var bool = {{alias}}( new S() )
20+
true
21+
> bool = {{alias}}( [ 1, 2, 3, 4 ] )
22+
false
23+
> bool = {{alias}}( 3.14 )
24+
false
25+
> bool = {{alias}}( {} )
26+
false
27+
28+
See Also
29+
--------
30+

is-struct/docs/types/index.d.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Tests if a value is a `struct` instance.
23+
*
24+
* @param v - value to test
25+
* @returns boolean indicating if a value is a `struct` instance
26+
*
27+
* @example
28+
* var structFactory = require( '@stdlib/dstructs/struct' );
29+
*
30+
* var schema = [
31+
* {
32+
* 'name': 'foo',
33+
* 'type': 'float64'
34+
* }
35+
* ];
36+
* var Struct = structFactory( schema );
37+
*
38+
* var bool = isStruct( new Struct() );
39+
* // returns true
40+
*
41+
* bool = isStruct( [] );
42+
* // returns false
43+
*/
44+
declare function isStruct( v: any ): boolean;
45+
46+
47+
// EXPORTS //
48+
49+
export = isStruct;

is-struct/docs/types/test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import isStruct = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isStruct( {} ); // $ExpectType boolean
27+
isStruct( [] ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isStruct(); // $ExpectError
33+
isStruct( {}, 123 ); // $ExpectError
34+
}

is-struct/examples/index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var structFactory = require( '@stdlib/dstructs/struct' );
22+
var isStruct = require( './../lib' );
23+
24+
var schema = [
25+
{
26+
'name': 'value',
27+
'type': 'float64'
28+
}
29+
];
30+
var Struct = structFactory( schema );
31+
32+
console.log( isStruct( new Struct() ) );
33+
// => true
34+
35+
console.log( isStruct( [ 1, 2, 3, 4 ] ) );
36+
// => false
37+
38+
console.log( isStruct( {} ) );
39+
// => false
40+
41+
console.log( isStruct( null ) );
42+
// => false

0 commit comments

Comments
 (0)