@@ -1198,8 +1198,6 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi
1198
1198
return out ;
1199
1199
}
1200
1200
1201
- // Consider adding `toLocaleString()` in a manner similar to `toString()` below
1202
-
1203
1201
/**
1204
1202
* Serializes a tuple as a string.
1205
1203
*
@@ -1226,6 +1224,32 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi
1226
1224
out += ')' ;
1227
1225
return out ;
1228
1226
}
1227
+ /**
1228
+ * Serializes a tuple as a localized string.
1229
+ *
1230
+ * @private
1231
+ * @memberof tuple
1232
+ * @throws {TypeError } `this` must be the host tuple
1233
+ * @returns {string } localized tuple string representation
1234
+ */
1235
+ function toLocaleString ( ) {
1236
+ var out ;
1237
+ var i ;
1238
+ if ( this !== tuple ) { // eslint-disable-line no-invalid-this
1239
+ throw new TypeError ( 'invalid invocation. `this` is not host tuple.' ) ;
1240
+ }
1241
+ out = opts . name + '(' ;
1242
+ for ( i = 0 ; i < nfields ; i ++ ) {
1243
+ out += fields [ i ] ;
1244
+ out += '=' ;
1245
+ out += tuple [ indices [ i ] ] . toLocaleString ( ) ;
1246
+ if ( i < nfields - 1 ) {
1247
+ out += ', ' ;
1248
+ }
1249
+ }
1250
+ out += ')' ;
1251
+ return out ;
1252
+ }
1229
1253
}
1230
1254
1231
1255
// Note: keep the following methods in alphabetical order...
@@ -1397,11 +1421,26 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi
1397
1421
return namedtypedtuple ( args ) ;
1398
1422
}
1399
1423
} ) ;
1424
+
1425
+ defineProperty ( namedtypedtuple . prototype , 'toLocaleString' , {
1426
+ 'configurable' : false ,
1427
+ 'enumerable' : false ,
1428
+ 'writable' : false ,
1429
+ 'value' : function toLocaleString ( ) {
1430
+ return this . toString ( ) ;
1431
+ }
1432
+ } ) ;
1433
+ defineProperty ( namedtypedtuple . prototype , 'toString' , {
1434
+ 'configurable' : false ,
1435
+ 'enumerable' : false ,
1436
+ 'writable' : false ,
1437
+ 'value' : toString
1438
+ } ) ;
1400
1439
1440
+
1401
1441
return namedtypedtuple ;
1402
1442
}
1403
1443
1404
-
1405
1444
// EXPORTS //
1406
1445
1407
1446
module . exports = factory ;
0 commit comments