forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@stdlib/assert): if applied, this commit will add the function '…
…isRaggedNestedArray' (assert/is-ragged-nested-array) Add support for checking if array-like objects are ragged and nested. Fixes: stdlib-js#1347 Issue Link: stdlib-js#1347
- Loading branch information
1 parent
f3def6d
commit d1d40de
Showing
10 changed files
with
647 additions
and
0 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
lib/node_modules/@stdlib/assert/is-ragged-nested-array/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<!-- | ||
@license Apache-2.0 | ||
Copyright (c) 2024 The Stdlib Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
# isRaggedNestedArray | ||
|
||
> Test if a value is a ragged nested array. | ||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var isRaggedNestedArray = require( '@stdlib/assert/is-ragged-nested-array' ); | ||
``` | ||
|
||
#### isRaggedNestedArray( value ) | ||
|
||
Tests if a value is a ragged nested array. A ragged nested array is a nested array having inner dimensions of varying lengths. | ||
|
||
```javascript | ||
var bool = isRaggedNestedArray( [ [1, 2, 3], [4, 5] ] ); | ||
// returns true | ||
|
||
bool = isRaggedNestedArray( [ [1, 2, 3], [4, 5, 6] ] ); | ||
// returns false | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint-disable object-curly-newline, object-curly-spacing, no-empty-function, no-restricted-syntax --> | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var isRaggedNestedArray = require( '@stdlib/assert/is-ragged-nested-array' ); | ||
|
||
var bool = isRaggedNestedArray( [ [1, 2, 3], [4, 5] ] ); | ||
// returns true | ||
|
||
bool = isRaggedNestedArray( [ [1, 2, 3], [4, 5, 6] ] ); | ||
// returns false | ||
|
||
bool = isRaggedNestedArray( 'beep' ); | ||
// returns false | ||
|
||
bool = isRaggedNestedArray( null ); | ||
// returns false | ||
|
||
bool = isRaggedNestedArray( void 0 ); | ||
// returns false | ||
|
||
bool = isRaggedNestedArray( 5 ); | ||
// returns false | ||
|
||
bool = isRaggedNestedArray( true ); | ||
// returns false | ||
|
||
bool = isRaggedNestedArray( {} ); | ||
// returns false | ||
|
||
bool = isRaggedNestedArray( function noop() {} ); | ||
// returns false | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
||
<section class="related"> | ||
|
||
* * * | ||
|
||
## See Also | ||
|
||
- <span class="package-name">[`@stdlib/assert/is-array`][@stdlib/assert/is-array]</span><span class="delimiter">: </span><span class="description">test if a value is an array.</span> | ||
- <span class="package-name">[`@stdlib/assert/is-array-like-object`][@stdlib/assert/is-array-like-object]</span><span class="delimiter">: </span><span class="description">test if a value is an array-like object.</span> | ||
|
||
</section> | ||
|
||
<!-- /.related --> | ||
|
||
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="links"> | ||
<!-- <related-links> --> | ||
|
||
[@stdlib/assert/is-array-like-object]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-array-like-object | ||
|
||
[@stdlib/assert/is-array]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-array | ||
|
||
<!-- </related-links> --> | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
91 changes: 91 additions & 0 deletions
91
lib/node_modules/@stdlib/assert/is-ragged-nested-array/benchmark/benchmark.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2018 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var pkg = require( './../package.json' ).name; | ||
var isRaggedNestedArray = require( './../lib' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg+'::ragged_array', function benchmark( b ) { | ||
var bool; | ||
var arr; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
arr = [ [1, 2, 3], [4, 5] ]; | ||
bool = isRaggedNestedArray( arr ); | ||
if ( typeof bool !== 'boolean' ) { | ||
b.fail( 'should return a boolean' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( !bool ) { | ||
b.fail( 'should return true' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); | ||
|
||
bench( pkg+'::non_ragged_array', function benchmark( b ) { | ||
var bool; | ||
var arr; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
arr = [ [1, 2, 3], [4, 5, 6] ]; | ||
bool = isRaggedNestedArray( arr ); | ||
if ( typeof bool !== 'boolean' ) { | ||
b.fail( 'should return a boolean' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( bool ) { | ||
b.fail( 'should return false' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); | ||
|
||
bench( pkg+'::non_array', function benchmark( b ) { | ||
var bool; | ||
var val; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
val = 'beep'; | ||
bool = isRaggedNestedArray( val ); | ||
if ( typeof bool !== 'boolean' ) { | ||
b.fail( 'should return a boolean' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( bool ) { | ||
b.fail( 'should return false' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
27 changes: 27 additions & 0 deletions
27
lib/node_modules/@stdlib/assert/is-ragged-nested-array/docs/repl.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{{alias}}( value ) | ||
Tests if a value is a ragged nested array. A ragged nested array is a nested | ||
array having inner dimensions of varying lengths. This function supports | ||
two-dimensional nested arrays and uses isArrayLikeObject to check if a value | ||
is an array-like object. | ||
|
||
Parameters | ||
---------- | ||
value: any | ||
Value to test. | ||
|
||
Returns | ||
------- | ||
bool: boolean | ||
Boolean indicating whether a value is a ragged nested array. | ||
|
||
Examples | ||
-------- | ||
> var bool = {{alias}}( [ [1, 2, 3], [4, 5] ] ) | ||
true | ||
> bool = {{alias}}( [ [1, 2, 3], [4, 5, 6] ] ) | ||
false | ||
> bool = {{alias}}( 'beep' ) | ||
false | ||
|
||
See Also | ||
-------- |
44 changes: 44 additions & 0 deletions
44
lib/node_modules/@stdlib/assert/is-ragged-nested-array/docs/types/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// TypeScript Version: 4.1 | ||
|
||
/** | ||
* Tests if a value is a ragged nested array. | ||
* | ||
* @param value - value to test | ||
* @returns boolean indicating if a value is a ragged nested array | ||
* | ||
* @example | ||
* var bool = isRaggedNestedArray( [ [1, 2, 3], [4, 5] ] ); | ||
* // returns true | ||
* | ||
* @example | ||
* var bool = isRaggedNestedArray( [ [1, 2, 3], [4, 5, 6] ] ); | ||
* // returns false | ||
* | ||
* @example | ||
* var bool = isRaggedNestedArray( 'beep' ); | ||
* // returns false | ||
*/ | ||
declare function isRaggedNestedArray( value: any ): value is ArrayLike<any>; | ||
|
||
|
||
// EXPORTS // | ||
|
||
export = isRaggedNestedArray; |
34 changes: 34 additions & 0 deletions
34
lib/node_modules/@stdlib/assert/is-ragged-nested-array/docs/types/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2019 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import isRaggedNestedArray = require( './index' ); | ||
|
||
// TESTS // | ||
|
||
// The function returns a boolean... | ||
{ | ||
isRaggedNestedArray( [ [1, 2, 3], [4, 5] ] ); // $ExpectType boolean | ||
isRaggedNestedArray( [ [1, 2, 3], [4, 5, 6] ] ); // $ExpectType boolean | ||
isRaggedNestedArray( 'beep' ); // $ExpectType boolean | ||
} | ||
|
||
// The compiler throws an error if the function is provided an unsupported number of arguments... | ||
{ | ||
isRaggedNestedArray(); // $ExpectError | ||
isRaggedNestedArray( [], 123 ); // $ExpectError | ||
} |
50 changes: 50 additions & 0 deletions
50
lib/node_modules/@stdlib/assert/is-ragged-nested-array/examples/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2018 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* eslint-disable no-empty-function, no-restricted-syntax */ | ||
|
||
'use strict'; | ||
|
||
var isRaggedNestedArray = require( './../lib' ); | ||
|
||
console.log( isRaggedNestedArray( [ [1, 2, 3], [4, 5] ] ) ); | ||
// => true | ||
|
||
console.log( isRaggedNestedArray( [ [1, 2, 3], [4, 5, 6] ] ) ); | ||
// => false | ||
|
||
console.log( isRaggedNestedArray( 'beep' ) ); | ||
// => false | ||
|
||
console.log( isRaggedNestedArray( null ) ); | ||
// => false | ||
|
||
console.log( isRaggedNestedArray( void 0 ) ); | ||
// => false | ||
|
||
console.log( isRaggedNestedArray( 5 ) ); | ||
// => false | ||
|
||
console.log( isRaggedNestedArray( true ) ); | ||
// => false | ||
|
||
console.log( isRaggedNestedArray( {} ) ); | ||
// => false | ||
|
||
console.log( isRaggedNestedArray( function noop() {} ) ); | ||
// => false |
Oops, something went wrong.