Skip to content

Commit b38c3a9

Browse files
fix: change to custom serialization instead of array-style serialization
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 23b2e2b commit b38c3a9

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

lib/node_modules/@stdlib/dstructs/named-typed-tuple/docs/repl.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,10 +1378,11 @@ tuple.toLocaleString( [locales[, options]] )
13781378

13791379
Examples
13801380
--------
1381-
> var factory = {{alias}}( [ 'x', 'y', 'z' ] );
1381+
> opts = { 'name': 'Point' };
1382+
> var factory = {{alias}}( [ 'x', 'y', 'z' ], opts );
13821383
> var p = factory( [ 1.0, -1.0, 0.0 ], 'int32' );
13831384
> p.toLocaleString()
1384-
'1,-1,0'
1385+
'Point(x=1, y=-1, z=0)'
13851386

13861387

13871388
tuple.toString()

lib/node_modules/@stdlib/dstructs/named-typed-tuple/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ interface Tuple {
12441244
* var tuple = factory( [ 1.0, 0.0, -1.0 ], 'int32' );
12451245
*
12461246
* var str = tuple.toLocaleString();
1247-
* // returns '1,0,-1'
1247+
* // returns 'tuple(x=1, y=0, z=-1)'
12481248
*/
12491249
toLocaleString( locales: string | Array<string>, options?: any ): string;
12501250

lib/node_modules/@stdlib/dstructs/named-typed-tuple/lib/main.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,10 +1212,9 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi
12121212
* @returns {string} string representation
12131213
*/
12141214
function toLocaleString( locales, options ) {
1215-
var opts;
1215+
var opt;
12161216
var loc;
12171217
var out;
1218-
var val;
12191218
var i;
12201219

12211220
if ( this !== tuple ) { // eslint-disable-line no-invalid-this
@@ -1229,18 +1228,23 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi
12291228
throw new TypeError( format( 'invalid argument. First argument must be a string or an array of strings. Value: `%s`.', locales ) );
12301229
}
12311230
if ( arguments.length < 2 ) {
1232-
opts = {};
1231+
opt = {};
12331232
} else if ( isObject( options ) ) {
1234-
opts = options;
1233+
opt = options;
12351234
} else {
12361235
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
12371236
}
1238-
out = [];
1237+
out = opts.name.toLocaleString( loc, opt ) + '(';
12391238
for ( i = 0; i < nfields; i++ ) {
1240-
val = tuple[ indices[ i ] ];
1241-
out.push( val.toLocaleString( loc, opts ) );
1239+
out += fields[ i ].toLocaleString( loc, opt );
1240+
out += '=';
1241+
out += tuple[ indices[ i ] ].toLocaleString( loc, opt );
1242+
if ( i < nfields-1 ) {
1243+
out += ', ';
1244+
}
12421245
}
1243-
return out.join( ',' );
1246+
out += ')';
1247+
return out;
12441248
}
12451249

12461250
/**

lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.to_locale_string.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ tape( 'the method serializes a tuple as a locale-specific string (default locale
8787
Point = namedtypetuple( [ 'price', 'quantity' ] );
8888
p = new Point( [ 123456.789, 9876 ] );
8989

90-
expected = [ (123456.789).toLocaleString(), (9876).toLocaleString() ].join( ',' );
90+
expected = 'tuple(price=' + (123456.789).toLocaleString() + ', quantity=' + (9876).toLocaleString() + ')';
9191
actual = p.toLocaleString();
9292

9393
t.strictEqual( actual, expected, 'returns expected string' );
@@ -103,7 +103,7 @@ tape( 'the method serializes a tuple as a locale-specific string (specified loca
103103
Point = namedtypetuple( [ 'price', 'quantity' ] );
104104
p = new Point( [ 123456.789, 9876 ] );
105105

106-
expected = [ '123.456,789', '9.876' ].join( ',' );
106+
expected = 'tuple(price=123.456,789, quantity=9.876)';
107107
actual = p.toLocaleString( 'de-DE' );
108108

109109
t.strictEqual( actual, expected, 'returns expected string for German locale' );
@@ -124,7 +124,7 @@ tape( 'the method serializes a tuple as a locale-specific string (locale and opt
124124
'currency': 'USD'
125125
};
126126

127-
expected = [ (1234.56).toLocaleString( 'en-US', opts ), (50).toLocaleString( 'en-US', opts ) ].join( ',' );
127+
expected = 'tuple(price=' + (1234.56).toLocaleString( 'en-US', opts ) + ', quantity=' + (50).toLocaleString( 'en-US', opts ) + ')';
128128
actual = p.toLocaleString( 'en-US', opts );
129129

130130
t.strictEqual( actual, expected, 'returns expected string for currency format' );
@@ -140,7 +140,7 @@ tape( 'the method handles null and undefined values using String()', function te
140140
Data = namedtypetuple( [ 'value', 'notes', 'status' ] );
141141
d = new Data( [ 1000, null, void 0 ] );
142142

143-
expected = [ (1000).toLocaleString(), '0', 'NaN' ].join( ',' );
143+
expected = 'tuple(value=' + (1000).toLocaleString() + ', notes=0, status=NaN)';
144144
actual = d.toLocaleString();
145145

146146
t.strictEqual( actual, expected, 'returns expected string with null and undefined' );
@@ -158,7 +158,7 @@ tape( 'the method serializes a tuple containing a Date object', function test( t
158158
date = new Date( '2025-09-02T18:30:00.000Z' );
159159
e = new Event( [ 123, date ] );
160160

161-
expected = [ (123).toLocaleString(), date.getTime().toLocaleString() ].join(',');
161+
expected = 'tuple(id=' + (123).toLocaleString() + ', timestamp=' + date.getTime().toLocaleString() + ')';
162162
actual = e.toLocaleString();
163163

164164
t.strictEqual( actual, expected, 'calls toLocaleString on the Date object' );
@@ -174,7 +174,7 @@ tape( 'the method handles boolean and NaN values', function test( t ) {
174174
Record = namedtypetuple( [ 'isValid', 'value' ] );
175175
r = new Record( [ true, NaN ] );
176176

177-
expected = [ '1', 'NaN' ].join(',');
177+
expected = 'tuple(isValid=1, value=NaN)';
178178
actual = r.toLocaleString();
179179

180180
t.strictEqual( actual, expected, 'handles boolean and NaN values' );
@@ -196,7 +196,7 @@ tape( 'the method serializes a tuple containing an object with a custom toLocale
196196
};
197197
c = new Custom( [ customObject ] );
198198

199-
expected = 'NaN';
199+
expected = 'tuple(item=NaN)';
200200
actual = c.toLocaleString();
201201

202202
t.strictEqual( actual, expected, 'uses the custom toLocaleString method from the object' );

0 commit comments

Comments
 (0)