Skip to content

Commit f9f1914

Browse files
committed
Auto-generated commit
1 parent 401ea02 commit f9f1914

File tree

11 files changed

+141
-39
lines changed

11 files changed

+141
-39
lines changed

.github/.keepalive

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
- name: Replace all GitHub links to individual packages with npm links
4040
run: |
4141
find . -type f -name '*.md' -print0 | xargs -0 sed -Ei '/tree\/main/b; s/@stdlib\/([^:]*)\]: https:\/\/github.com\/stdlib-js/@stdlib\/\1\]: https:\/\/www.npmjs.com\/package\/@stdlib/g'
42+
- name: Replace list with links to other branches from installation section
43+
run: |
44+
find . -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`\n\nAlternatively,[^<]+<\/section>/\`\`\`\n\n<\/section>/"
4245
- name: Replace all stdlib GitHub dependencies with the respective npm packages
4346
run: |
4447
find package.json -type f -print0 | xargs -0 sed -Ei 's/"github:stdlib-js[^"]*"/"^0.0.x"/g'

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,8 @@ var shape = arrayShape( arr );
109109
```javascript
110110
var arrayShape = require( '@stdlib/array-shape' );
111111

112-
var shape;
113-
var arr;
114-
115-
arr = [ 1, 2, 3 ];
116-
shape = arrayShape( arr );
112+
var arr = [ 1, 2, 3 ];
113+
var shape = arrayShape( arr );
117114
// returns [ 3 ]
118115

119116
arr = [
@@ -258,7 +255,7 @@ See [LICENSE][stdlib-license].
258255

259256
## Copyright
260257

261-
Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
258+
Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
262259

263260
</section>
264261

docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Parameters
66
----------
7-
arr: Array
7+
arr: ArrayLikeObject
88
Input array.
99

1010
Returns

docs/types/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
// TypeScript Version: 2.0
2020

21+
/// <reference types="@stdlib/types"/>
22+
23+
import { ArrayLike } from '@stdlib/types/array';
24+
2125
/**
2226
* Determines (nested) array dimensions.
2327
*
@@ -42,7 +46,7 @@
4246
* var shape = arrayShape( arr );
4347
* // returns [ 3 ]
4448
*/
45-
declare function arrayShape( arr: Array<any> ): Array<number>;
49+
declare function arrayShape( arr: ArrayLike<any> ): Array<number>;
4650

4751

4852
// EXPORTS //

docs/types/test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,24 @@
1818

1919
import arrayShape = require( './index' );
2020

21+
2122
// TESTS //
2223

2324
// The function returns an array of numbers..
2425
{
2526
arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[]
2627
}
2728

29+
// The compiler throws an error if not provided an array-like object...
30+
{
31+
arrayShape( 5 ); // $ExpectError
32+
arrayShape( false ); // $ExpectError
33+
arrayShape( true ); // $ExpectError
34+
arrayShape( null ); // $ExpectError
35+
arrayShape( undefined ); // $ExpectError
36+
arrayShape( {} ); // $ExpectError
37+
}
38+
2839
// The compiler throws an error if the function is provided an unsupported number of arguments...
2940
{
3041
arrayShape(); // $ExpectError

examples/index.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@
2020

2121
var arrayShape = require( './../lib' );
2222

23-
var shape;
24-
var arr;
25-
26-
arr = [ 1, 2, 3 ];
27-
shape = arrayShape( arr );
23+
var arr = [ 1, 2, 3 ];
24+
var shape = arrayShape( arr );
2825
console.log( shape.join( 'x' ) );
29-
// => 3
26+
// => '3'
3027

3128
arr = [
3229
[ 1 ],
@@ -35,7 +32,7 @@ arr = [
3532
];
3633
shape = arrayShape( arr );
3734
console.log( shape.join( 'x' ) );
38-
// => 3x1
35+
// => '3x1'
3936

4037
arr = [
4138
[],
@@ -44,14 +41,14 @@ arr = [
4441
];
4542
shape = arrayShape( arr );
4643
console.log( shape.join( 'x' ) );
47-
// => 3x0
44+
// => '3x0'
4845

4946
arr = [
5047
[ 1, 2, 3 ]
5148
];
5249
shape = arrayShape( arr );
5350
console.log( shape.join( 'x' ) );
54-
// => 1x3
51+
// => '1x3'
5552

5653
arr = [
5754
[ [ 1 ] ],
@@ -60,20 +57,20 @@ arr = [
6057
];
6158
shape = arrayShape( arr );
6259
console.log( shape.join( 'x' ) );
63-
// => 3x1x1
60+
// => '3x1x1'
6461

6562
arr = [ [ [ [ 1, 2, 3 ] ] ] ];
6663
shape = arrayShape( arr );
6764
console.log( shape.join( 'x' ) );
68-
// => 1x1x1x3
65+
// => '1x1x1x3'
6966

7067
arr = [
7168
[ 1, 2 ],
7269
[ 3, 4 ]
7370
];
7471
shape = arrayShape( arr );
7572
console.log( shape.join( 'x' ) );
76-
// => 2x2
73+
// => '2x2'
7774

7875
arr = [
7976
[ 1, 2, 3 ],
@@ -82,7 +79,7 @@ arr = [
8279
];
8380
shape = arrayShape( arr );
8481
console.log( shape.join( 'x' ) );
85-
// => 3x3
82+
// => '3x3'
8683

8784
arr = [
8885
[ 1, 2, 3 ],
@@ -91,7 +88,7 @@ arr = [
9188
];
9289
shape = arrayShape( arr );
9390
console.log( shape.join( 'x' ) );
94-
// => 3
91+
// => '3'
9592

9693
arr = [
9794
[ 1, 2, 3 ],
@@ -100,7 +97,7 @@ arr = [
10097
];
10198
shape = arrayShape( arr );
10299
console.log( shape.join( 'x' ) );
103-
// => 3
100+
// => '3'
104101

105102
arr = [
106103
[ [ 1, 2, 3 ] ],
@@ -109,7 +106,7 @@ arr = [
109106
];
110107
shape = arrayShape( arr );
111108
console.log( shape.join( 'x' ) );
112-
// => 3
109+
// => '3'
113110

114111
arr = [
115112
[ [ 1, 2, 3 ] ],
@@ -118,7 +115,7 @@ arr = [
118115
];
119116
shape = arrayShape( arr );
120117
console.log( shape.join( 'x' ) );
121-
// => 3
118+
// => '3'
122119

123120
arr = [
124121
[ [ [ 1, 2, 3 ] ] ],
@@ -127,4 +124,4 @@ arr = [
127124
];
128125
shape = arrayShape( arr );
129126
console.log( shape.join( 'x' ) );
130-
// => 3x1
127+
// => '3x1'

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050

5151
// MODULES //
5252

53-
var arrayShape = require( './main.js' );
53+
var main = require( './main.js' );
5454

5555

5656
// EXPORTS //
5757

58-
module.exports = arrayShape;
58+
module.exports = main;

lib/main.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
// MODULES //
2222

23-
var isArray = require( '@stdlib/assert-is-array' );
23+
var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );
2424

2525

2626
// FUNCTIONS //
@@ -30,12 +30,12 @@ var isArray = require( '@stdlib/assert-is-array' );
3030
*
3131
* @private
3232
* @param {Array} shape - output array
33-
* @param {Array} arr - array
33+
* @param {ArrayLikeObject} arr - array
3434
* @returns {Array} shape array
3535
*/
3636
function recurse( shape, arr ) {
3737
var v = arr[ 0 ];
38-
if ( isArray( v ) ) {
38+
if ( isArrayLikeObject( v ) ) {
3939
shape.push( v.length );
4040
recurse( shape, v );
4141
}
@@ -49,7 +49,7 @@ function recurse( shape, arr ) {
4949
* @param {PositiveInteger} ndims - number of dimensions
5050
* @param {Array} shape - shape array
5151
* @param {NonNegativeInteger} d - dimension
52-
* @param {Array} arr - array element to verify
52+
* @param {ArrayLikeObject} arr - array element to verify
5353
* @param {boolean} flg - boolean indicating whether to continue recursing
5454
* @returns {NonNegativeInteger} number of consistent dimensions
5555
*/
@@ -66,7 +66,7 @@ function check( ndims, shape, d, arr, flg ) {
6666
v = arr[ i ];
6767

6868
// If the array element is not an array or is not the same size, we have found an inconsistent dimension:
69-
if ( !isArray( v ) || v.length !== len ) {
69+
if ( !isArrayLikeObject( v ) || v.length !== len ) {
7070
// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:
7171
return d;
7272
}
@@ -88,7 +88,7 @@ function check( ndims, shape, d, arr, flg ) {
8888
/**
8989
* Determines (nested) array dimensions.
9090
*
91-
* @param {Array} arr - array
91+
* @param {ArrayLikeObject} arr - array
9292
* @throws {TypeError} must provide an array
9393
* @returns {Array} array shape
9494
*
@@ -114,8 +114,8 @@ function arrayShape( arr ) {
114114
var shape;
115115
var ndims;
116116

117-
if ( !isArray( arr ) ) {
118-
throw new TypeError( 'invalid argument. Must provide an array. Value: `' + arr + '`.' );
117+
if ( !isArrayLikeObject( arr ) ) {
118+
throw new TypeError( 'invalid argument. Must provide an array-like object. Value: `' + arr + '`.' );
119119
}
120120
// Initialize the shape/dimensions array:
121121
shape = [ arr.length ];

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@
3737
"url": "https://github.com/stdlib-js/stdlib/issues"
3838
},
3939
"dependencies": {
40-
"@stdlib/assert-is-array": "^0.0.x"
40+
"@stdlib/assert-is-array-like-object": "^0.0.x",
41+
"@stdlib/types": "^0.0.x"
4142
},
4243
"devDependencies": {
44+
"@stdlib/array-float64": "^0.0.x",
45+
"@stdlib/assert-is-array": "^0.0.x",
4346
"@stdlib/bench": "^0.0.x",
4447
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
4548
"istanbul": "^0.4.1",

0 commit comments

Comments
 (0)