Skip to content

Commit 6bca46c

Browse files
committed
Auto-generated commit
1 parent 4a40ed8 commit 6bca46c

File tree

3 files changed

+93
-3
lines changed

3 files changed

+93
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@
556556

557557
### Bug Fixes
558558

559+
- [`eab49ad`](https://github.com/stdlib-js/stdlib/commit/eab49ad435f6080ec28a8fbb75de4d9520bdd7e4) - ensure support for elements which are null or undefined
559560
- [`f10a6aa`](https://github.com/stdlib-js/stdlib/commit/f10a6aaf98c37bb630ac75e1a50dd0bd4a0eb417) - ensure unique indices
560561
- [`11cc2cf`](https://github.com/stdlib-js/stdlib/commit/11cc2cf8869a4b6ebf48545d5678eda25513529e) - use ndarray assertion utility
561562
- [`6c43167`](https://github.com/stdlib-js/stdlib/commit/6c4316733d615b06d301eec89c377838a6b56dd8) - resolve normalized data type
@@ -783,6 +784,7 @@ A total of 44 issues were closed in this release:
783784

784785
<details>
785786

787+
- [`eab49ad`](https://github.com/stdlib-js/stdlib/commit/eab49ad435f6080ec28a8fbb75de4d9520bdd7e4) - **fix:** ensure support for elements which are null or undefined _(by Athan Reines)_
786788
- [`7f1f9ca`](https://github.com/stdlib-js/stdlib/commit/7f1f9cae7096b100fb0d2fafdb6822545bd0489a) - **test:** fix missing argument in TypeScript test _(by Philipp Burckhardt)_
787789
- [`5ff8528`](https://github.com/stdlib-js/stdlib/commit/5ff852828a9f5d0388ef386f039649d95987252d) - **chore:** minor clean-up _(by Philipp Burckhardt)_
788790
- [`98b02ad`](https://github.com/stdlib-js/stdlib/commit/98b02adb85c1a0644510dddd2fab2c1b6b61c2eb) - **feat:** update `ndarray/base` TypeScript declarations [(#10584)](https://github.com/stdlib-js/stdlib/pull/10584) _(by stdlib-bot)_

base/ctor/lib/tolocalestring.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var isComplexDataType = require( './../../../base/assert/is-complex-floating-point-data-type' );
2424
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2525
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
26+
var isUndefinedOrNull = require( '@stdlib/assert/is-undefined-or-null' );
2627
var isObject = require( '@stdlib/assert/is-plain-object' );
2728
var format = require( '@stdlib/string/format' );
2829
var replace = require( '@stdlib/string/replace' );
@@ -114,7 +115,12 @@ function toLocaleString( locales, options ) { // eslint-disable-line stdlib/no-r
114115
}
115116
} else {
116117
for ( i = 0; i < this._length; i++ ) {
117-
buffer += this.iget( i ).toLocaleString( loc, opts );
118+
v = this.iget( i );
119+
if ( !isUndefinedOrNull( v ) && v.toLocaleString ) {
120+
buffer += v.toLocaleString( loc, opts );
121+
} else {
122+
buffer += String( v );
123+
}
118124
if ( i < this._length-1 ) {
119125
buffer += ', ';
120126
}
@@ -132,7 +138,12 @@ function toLocaleString( locales, options ) { // eslint-disable-line stdlib/no-r
132138
}
133139
} else {
134140
for ( i = 0; i < 3; i++ ) {
135-
buffer += this.iget( i ).toLocaleString( loc, opts );
141+
v = this.iget( i );
142+
if ( !isUndefinedOrNull( v ) && v.toLocaleString ) {
143+
buffer += v.toLocaleString( loc, opts );
144+
} else {
145+
buffer += String( v );
146+
}
136147
if ( i < 2 ) {
137148
buffer += ', ';
138149
}
@@ -151,7 +162,12 @@ function toLocaleString( locales, options ) { // eslint-disable-line stdlib/no-r
151162
}
152163
} else {
153164
for ( i = 2; i >= 0; i-- ) {
154-
buffer += this.iget( this._length-1-i ).toLocaleString( loc, opts ); // eslint-disable-line max-len
165+
v = this.iget( this._length-1-i );
166+
if ( !isUndefinedOrNull( v ) && v.toLocaleString ) {
167+
buffer += v.toLocaleString( loc, opts );
168+
} else {
169+
buffer += String( v );
170+
}
155171
if ( i > 0 ) {
156172
buffer += ', ';
157173
}

base/ctor/test/test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3810,6 +3810,37 @@ tape( 'an ndarray has a custom `toLocaleString()` method (boolean type)', functi
38103810
t.end();
38113811
});
38123812

3813+
tape( 'an ndarray has a custom `toLocaleString()` method (generic type)', function test( t ) {
3814+
var expected;
3815+
var strides;
3816+
var actual;
3817+
var buffer;
3818+
var offset;
3819+
var dtype;
3820+
var order;
3821+
var shape;
3822+
var arr;
3823+
3824+
dtype = 'generic';
3825+
buffer = [ null, void 0, null, void 0 ];
3826+
shape = [ 2, 2 ];
3827+
order = 'row-major';
3828+
strides = [ 2, 1 ];
3829+
offset = 0;
3830+
3831+
arr = ndarray( dtype, buffer, shape, strides, offset, order );
3832+
3833+
t.strictEqual( hasOwnProp( arr, 'toLocaleString' ), false, 'does not have own property' );
3834+
t.strictEqual( hasProp( arr, 'toLocaleString' ), true, 'has property' );
3835+
t.strictEqual( isFunction( arr.toLocaleString ), true, 'has method' );
3836+
3837+
expected = 'ndarray( \'generic\', [ null, undefined, null, undefined ], [ 2, 2 ], [ 2, 1 ], 0, \'row-major\' )';
3838+
actual = arr.toLocaleString();
3839+
t.strictEqual( actual, expected, 'returns expected value' );
3840+
3841+
t.end();
3842+
});
3843+
38133844
tape( 'an ndarray has a custom `toLocaleString()` method (0d)', function test( t ) {
38143845
var expected;
38153846
var strides;
@@ -3964,6 +3995,47 @@ tape( 'an ndarray has a custom `toLocaleString()` method (large array; complex t
39643995
t.end();
39653996
});
39663997

3998+
tape( 'an ndarray has a custom `toLocaleString()` method (large array; generic type)', function test( t ) {
3999+
var expected;
4000+
var strides;
4001+
var actual;
4002+
var buffer;
4003+
var offset;
4004+
var dtype;
4005+
var order;
4006+
var shape;
4007+
var arr;
4008+
var i;
4009+
4010+
dtype = 'generic';
4011+
buffer = [];
4012+
for ( i = 0; i < 10000; i++ ) {
4013+
if ( i < 3 ) {
4014+
buffer.push( null );
4015+
} else if ( i >= 9997 ) {
4016+
buffer.push( void 0 );
4017+
} else {
4018+
buffer.push( 0 );
4019+
}
4020+
}
4021+
shape = [ 10000 ];
4022+
order = 'row-major';
4023+
strides = [ 1 ];
4024+
offset = 0;
4025+
4026+
arr = ndarray( dtype, buffer, shape, strides, offset, order );
4027+
4028+
t.strictEqual( hasOwnProp( arr, 'toLocaleString' ), false, 'does not have own property' );
4029+
t.strictEqual( hasProp( arr, 'toLocaleString' ), true, 'has property' );
4030+
t.strictEqual( isFunction( arr.toLocaleString ), true, 'has method' );
4031+
4032+
expected = 'ndarray( \'generic\', [ null, null, null, ..., undefined, undefined, undefined ], [ 10000 ], [ 1 ], 0, \'row-major\' )';
4033+
actual = arr.toLocaleString();
4034+
t.strictEqual( actual, expected, 'returns expected value' );
4035+
4036+
t.end();
4037+
});
4038+
39674039
tape( 'an ndarray has a custom `toLocaleString()` method (locale, options)', function test( t ) {
39684040
var expected;
39694041
var strides;

0 commit comments

Comments
 (0)