-
-
Notifications
You must be signed in to change notification settings - Fork 896
feat: implement toLocaleString
method in dstructs/named-typed-tuple
#8009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kgryte
merged 35 commits into
stdlib-js:develop
from
Gauravkaushik-1206:fix-tolocale-string
Sep 8, 2025
Merged
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
fd9a4f3
feat(named-typed-tuple): implement toLocaleString function
Gauravkaushik-1206 6591629
Discard changes to lib/node_modules/@stdlib/dstructs/named-typed-tupl…
kgryte 2075abe
fix: update `fromIndex` handling in `blas/ext/base/ndarray/slast-inde…
headlessNode d86f3ef
fix: update `fromIndex` handling in `blas/ext/base/ndarray/glast-inde…
headlessNode 65c9403
feat: add argument validation to toLocaleString
Gauravkaushik-1206 09c587f
feat: changed copyright year to 2025
Gauravkaushik-1206 e63aa17
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/gla…
kgryte c4eda5f
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/gla…
kgryte f97d9f8
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/gla…
kgryte 0c57f34
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/gla…
kgryte 71ef02d
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/gla…
kgryte 5ab6214
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/gla…
kgryte 27dfeaa
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/gla…
kgryte ba670f7
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/sla…
kgryte 8951632
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/sla…
kgryte 9f98254
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/sla…
kgryte 30c2f33
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/sla…
kgryte f894a17
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/sla…
kgryte 28ed5ca
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/sla…
kgryte fbcae92
Discard changes to lib/node_modules/@stdlib/blas/ext/base/ndarray/sla…
kgryte 5eb4b37
Merge remote-tracking branch 'upstream/develop' into fix-tolocale-string
stdlib-bot 23b2e2b
Apply suggestions from code review
kgryte b38c3a9
fix: change to custom serialization instead of array-style serialization
Gauravkaushik-1206 8f2650c
docs: fix missing declaration
kgryte 7fa7688
docs: fix missing declaration
kgryte 15c46bf
refactor: rename variable
kgryte ee7116d
test: update description
kgryte 0fde4ab
test: remove test
kgryte 95fdf7f
test: remove tests
kgryte 1d807f3
test: update description
kgryte dbce613
test: update test value
kgryte 272428a
test: rename variable and update test messages
kgryte b4a0d74
test: reorder tests
kgryte 17daba7
test: update message
kgryte 885162e
Merge remote-tracking branch 'upstream/develop' into fix-tolocale-string
stdlib-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.to_locale_string.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2025 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var tape = require( 'tape' ); | ||
var hasProp = require( '@stdlib/assert/has-property' ); | ||
var isFunction = require( '@stdlib/assert/is-function' ); | ||
var namedtypetuple = require( './../lib' ); | ||
|
||
|
||
// TESTS // | ||
|
||
tape( 'main export is a function', function test( t ) { | ||
t.ok( true, __filename ); | ||
t.strictEqual( typeof namedtypetuple, 'function', 'main export is a function' ); | ||
t.end(); | ||
}); | ||
|
||
tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { | ||
var values; | ||
var Point; | ||
var p; | ||
var i; | ||
|
||
Point = namedtypetuple( [ 'x', 'y' ] ); | ||
p = new Point(); | ||
|
||
values = [ | ||
'5', | ||
5, | ||
NaN, | ||
true, | ||
false, | ||
null, | ||
void 0, | ||
{}, | ||
[] | ||
]; | ||
for ( i = 0; i < values.length; i++ ) { | ||
t.throws( badValue( values[i] ), TypeError, 'throws a TypeError when provided '+values[i] ); | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
t.end(); | ||
|
||
function badValue( value ) { | ||
return function badValue() { | ||
return p.toLocaleString.call( value ); | ||
}; | ||
} | ||
}); | ||
|
||
tape( 'a tuple has a `toLocaleString` method', function test( t ) { | ||
var Point; | ||
var p; | ||
|
||
Point = namedtypetuple( [ 'x', 'y' ] ); | ||
p = new Point(); | ||
|
||
t.strictEqual( hasProp( p, 'toLocaleString' ), true, 'has property' ); | ||
t.strictEqual( isFunction( p.toLocaleString ), true, 'is a function' ); | ||
t.end(); | ||
}); | ||
|
||
tape( 'the method serializes a tuple as a locale-specific string (default locale)', function test( t ) { | ||
var expected; | ||
var actual; | ||
var Point; | ||
var p; | ||
|
||
Point = namedtypetuple( [ 'price', 'quantity' ] ); | ||
p = new Point( [ 123456.789, 9876 ] ); | ||
|
||
expected = 'tuple(price=' + (123456.789).toLocaleString() + ', quantity=' + (9876).toLocaleString() + ')'; | ||
actual = p.toLocaleString(); | ||
|
||
t.strictEqual( actual, expected, 'returns expected string' ); | ||
t.end(); | ||
}); | ||
|
||
tape( 'the method serializes a tuple as a locale-specific string (specified locale)', function test( t ) { | ||
var expected; | ||
var actual; | ||
var Point; | ||
var p; | ||
|
||
Point = namedtypetuple( [ 'price', 'quantity' ] ); | ||
p = new Point( [ 123456.789, 9876 ] ); | ||
|
||
expected = 'tuple(price=123.456,789, quantity=9.876)'; | ||
actual = p.toLocaleString( 'de-DE' ); | ||
|
||
t.strictEqual( actual, expected, 'returns expected string for German locale' ); | ||
t.end(); | ||
}); | ||
|
||
tape( 'the method serializes a tuple as a locale-specific string (locale and options)', function test( t ) { | ||
var expected; | ||
var actual; | ||
var Point; | ||
var opts; | ||
var p; | ||
|
||
Point = namedtypetuple( [ 'price', 'quantity' ] ); | ||
p = new Point( [ 1234.56, 50 ] ); | ||
opts = { | ||
'style': 'currency', | ||
'currency': 'USD' | ||
}; | ||
|
||
expected = 'tuple(price=' + (1234.56).toLocaleString( 'en-US', opts ) + ', quantity=' + (50).toLocaleString( 'en-US', opts ) + ')'; | ||
actual = p.toLocaleString( 'en-US', opts ); | ||
|
||
t.strictEqual( actual, expected, 'returns expected string for currency format' ); | ||
t.end(); | ||
}); | ||
|
||
tape( 'the method handles boolean and NaN values', function test( t ) { | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
var expected; | ||
var Record; | ||
var actual; | ||
var r; | ||
|
||
Record = namedtypetuple( [ 'isValid', 'value' ] ); | ||
r = new Record( [ true, NaN ] ); | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
expected = 'tuple(isValid=1, value=NaN)'; | ||
actual = r.toLocaleString(); | ||
|
||
t.strictEqual( actual, expected, 'handles boolean and NaN values' ); | ||
t.end(); | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.