@stdlib/console-log-each 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +10 -5
  3. package/lib/main.js +13 -2
  4. package/package.json +17 -15
package/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2022 The Stdlib Authors.
1
+ Copyright (c) 2016-2023 The Stdlib Authors.
package/README.md CHANGED
@@ -64,7 +64,7 @@ logEach( '%d < %d ', x, y );
64
64
  // e.g., => '1 < 4\n2 < 5\n3 < 6\n'
65
65
  ```
66
66
 
67
- If an interpolated argument is not a collection, the argument is broadcasted for each iteration.
67
+ If an interpolated argument is not an array-like object, the argument is broadcasted for each iteration.
68
68
 
69
69
  ```javascript
70
70
  var x = [ 1, 2, 3 ];
@@ -84,7 +84,8 @@ logEach( '%d < %d', x, y );
84
84
 
85
85
  ## Notes
86
86
 
87
- - If the function is provided collections of unequal lengths, the function throws an error.
87
+ - If the function is provided array-like objects of unequal lengths, the function throws an error.
88
+ - The function supports array-like objects supporting the accessor protocol (e.g., [`Complex128Array`][@stdlib/array/complex128], [`Complex64Array`][@stdlib/array/complex64], etc).
88
89
 
89
90
  </section>
90
91
 
@@ -159,7 +160,7 @@ See [LICENSE][stdlib-license].
159
160
 
160
161
  ## Copyright
161
162
 
162
- Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
163
+ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
163
164
 
164
165
  </section>
165
166
 
@@ -172,8 +173,8 @@ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
172
173
  [npm-image]: http://img.shields.io/npm/v/@stdlib/console-log-each.svg
173
174
  [npm-url]: https://npmjs.org/package/@stdlib/console-log-each
174
175
 
175
- [test-image]: https://github.com/stdlib-js/console-log-each/actions/workflows/test.yml/badge.svg?branch=v0.0.1
176
- [test-url]: https://github.com/stdlib-js/console-log-each/actions/workflows/test.yml?query=branch:v0.0.1
176
+ [test-image]: https://github.com/stdlib-js/console-log-each/actions/workflows/test.yml/badge.svg?branch=v0.0.2
177
+ [test-url]: https://github.com/stdlib-js/console-log-each/actions/workflows/test.yml?query=branch:v0.0.2
177
178
 
178
179
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/console-log-each/main.svg
179
180
  [coverage-url]: https://codecov.io/github/stdlib-js/console-log-each?branch=main
@@ -202,6 +203,10 @@ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
202
203
 
203
204
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/console-log-each/main/LICENSE
204
205
 
206
+ [@stdlib/array/complex128]: https://www.npmjs.com/package/@stdlib/stdlib
207
+
208
+ [@stdlib/array/complex64]: https://www.npmjs.com/package/@stdlib/stdlib
209
+
205
210
  </section>
206
211
 
207
212
  <!-- /.links -->
package/lib/main.js CHANGED
@@ -22,6 +22,7 @@
22
22
 
23
23
  var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
24
24
  var isCollection = require( '@stdlib/assert-is-collection' );
25
+ var accessors = require( '@stdlib/array-base-accessors' );
25
26
  var format = require( '@stdlib/string-format' );
26
27
  var logger = require( '@stdlib/console-log' );
27
28
 
@@ -40,30 +41,38 @@ var logger = require( '@stdlib/console-log' );
40
41
  function logEach( str ) {
41
42
  var strides;
42
43
  var offsets;
44
+ var getters;
43
45
  var values;
44
46
  var nargs;
45
47
  var args;
46
48
  var len;
47
49
  var v;
48
50
  var s;
51
+ var o;
49
52
  var i;
50
53
  var j;
51
54
  if ( !isString( str ) ) {
52
55
  throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );
53
56
  }
54
57
  nargs = arguments.length;
58
+ getters = [];
55
59
  strides = [];
56
60
  args = [];
57
61
  for ( i = 1; i < nargs; i++ ) {
58
62
  v = arguments[ i ];
59
63
  if ( isCollection( v ) ) {
64
+ o = accessors( v );
65
+ getters.push( o.accessors[ 0 ] );
60
66
  args.push( v );
61
67
  strides.push( 1 );
62
68
  len = v.length;
63
69
  i += 1;
64
70
  break;
65
71
  } else {
66
- args.push( [ v ] );
72
+ v = [ v ];
73
+ o = accessors( v );
74
+ getters.push( o.accessors[ 0 ] );
75
+ args.push( v );
67
76
  strides.push( 0 );
68
77
  }
69
78
  }
@@ -81,6 +90,8 @@ function logEach( str ) {
81
90
  v = [ v ];
82
91
  s = 0;
83
92
  }
93
+ o = accessors( v );
94
+ getters.push( o.accessors[ 0 ] );
84
95
  args.push( v );
85
96
  strides.push( s );
86
97
  }
@@ -92,7 +103,7 @@ function logEach( str ) {
92
103
  }
93
104
  for ( i = 0; i < len; i++ ) {
94
105
  for ( j = 0; j < nargs-1; j++ ) {
95
- values[ j+1 ] = args[ j ][ offsets[ j ] ];
106
+ values[ j+1 ] = getters[ j ]( args[ j ], offsets[ j ] );
96
107
  offsets[ j ] += strides[ j ];
97
108
  }
98
109
  logger( format.apply( null, values ) );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/console-log-each",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Insert array element values into a format string and print the result.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -37,20 +37,22 @@
37
37
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
38
  },
39
39
  "dependencies": {
40
- "@stdlib/assert-is-collection": "^0.0.x",
41
- "@stdlib/assert-is-string": "^0.0.x",
42
- "@stdlib/console-log": "^0.0.x",
43
- "@stdlib/string-format": "^0.0.x"
40
+ "@stdlib/array-base-accessors": "^0.0.1",
41
+ "@stdlib/assert-is-collection": "^0.0.8",
42
+ "@stdlib/assert-is-string": "^0.0.8",
43
+ "@stdlib/console-log": "^0.0.1",
44
+ "@stdlib/string-format": "^0.0.3"
44
45
  },
45
46
  "devDependencies": {
46
- "@stdlib/array-filled-by": "^0.0.x",
47
- "@stdlib/array-zeros": "^0.0.x",
48
- "@stdlib/bench": "^0.0.x",
49
- "@stdlib/math-base-special-abs": "^0.0.x",
50
- "@stdlib/math-base-special-pow": "^0.0.x",
51
- "@stdlib/random-base-discrete-uniform": "^0.0.x",
52
- "@stdlib/utils-map": "^0.0.x",
53
- "@stdlib/utils-nary-function": "^0.0.x",
47
+ "@stdlib/array-complex128": "^0.0.6",
48
+ "@stdlib/array-filled-by": "^0.0.2",
49
+ "@stdlib/array-zeros": "^0.0.1",
50
+ "@stdlib/bench": "^0.0.12",
51
+ "@stdlib/math-base-special-abs": "^0.0.6",
52
+ "@stdlib/math-base-special-pow": "^0.0.7",
53
+ "@stdlib/random-base-discrete-uniform": "^0.0.6",
54
+ "@stdlib/utils-map": "^0.0.1",
55
+ "@stdlib/utils-nary-function": "^0.0.1",
54
56
  "proxyquire": "^2.0.0",
55
57
  "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
56
58
  "istanbul": "^0.4.1",
@@ -75,7 +77,7 @@
75
77
  "stdlib"
76
78
  ],
77
79
  "funding": {
78
- "type": "patreon",
79
- "url": "https://www.patreon.com/athan"
80
+ "type": "opencollective",
81
+ "url": "https://opencollective.com/stdlib"
80
82
  }
81
83
  }