8000 Auto-generated commit · stdlib-js/array-complex64@ffec62a · GitHub
[go: up one dir, main page]

Skip to content

Commit ffec62a

Browse files
committed
Auto-generated commit
1 parent 083197f commit ffec62a

10 files changed

+448
-4
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Shivam <11shivam00@gmail.com>
7373
Shraddheya Shendre <shendreshraddheya@gmail.com>
7474
Shubh Mehta <93862397+Shubh942@users.noreply.github.com>
7575
Shubham Mishra <shubh622005@gmail.com>
76+
Sivam Das <100067002+Sivam2313@users.noreply.github.com>
7677
Snehil Shah <130062020+Snehil-Shah@users.noreply.github.com>
7778
Soumajit Chatterjee <121816890+soumajit23@users.noreply.github.com>
7879
Spandan Barve <contact@marsian.dev>

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,27 @@ im = imagf( z );
22252225
// returns 6.0
22262226
```
22272227

2228+
<a name="method-to-locale-string"></a>
2229+
2230+
#### Complex64Array.prototype.toLocaleString( \[locales\[, options]] )
2231+
2232+
Serializes an array as a locale-specific string.
2233+
2234+
```javascript
2235+
var arr = new Complex64Array( 2 );
2236+
2237+
arr.set( [ 1.0, 1.0 ], 0 );
2238+
arr.set( [ 2.0, 2.0 ], 1 );
2239+
2240+
var str = arr.toLocaleString();
2241+
// returns '1 + 1i,2 + 2i'
2242+
```
2243+
2244+
The method supports the following arguments:
2245+
2246+
- **locales**: a string with a BCP 47 language tag or an array of such strings.
2247+
- **options**: configuration properties.
2248+
22282249
<a name="method-to-reversed"></a>
22292250

22302251
#### Complex64Array.prototype.toReversed()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench-harness' );
24+
var pkg = require( './../package.json' ).name;
25+
var Complex64Array = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg+':toLocaleString', function benchmark( b ) {
31+
var out;
32+
var arr;
33+
var i;
34+
35+
arr = new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] );
36+
37+
b.tic();
38+
for ( i = 0; i < b.iterations; i++ ) {
39+
out = arr.toLocaleString();
40+
if ( typeof out !== 'string' ) {
41+
b.fail( 'should return a string' );
42+
}
43+
}
44+
b.toc();
45+
if ( typeof out !== 'string' ) {
46+
b.fail( 'should return a string' );
47+
}
48+
b.pass( 'benchmark finished' );
49+
b.end();
50+
});
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench-harness' );
24+
var pow = require( '@stdlib/math-base-special-pow' );
25+
var Complex64 = require( '@stdlib/complex-float32' );
26+
var pkg = require( './../package.json' ).name;
27+
var Complex64Array = require( './../lib' );
28+
29+
30+
// FUNCTIONS //
31+
32+
/**
33+
* Creates a benchmark function.
34+
*
35+
* @private
36+
* @param {PositiveInteger} len - array length
37+
* @returns {Function} benchmark function
38+
*/
39+
function createBenchmark( len ) {
40+
var arr;
41+
var i;
42+
43+
arr = [];
44+
for ( i = 0; i < len; i++ ) {
45+
arr.push( new Complex64( i, i ) );
46+
}
47+
arr = new Complex64Array( arr );
48+
49+
return benchmark;
50+
51+
/**
52+
* Benchmark function.
53+
*
54+
* @private
55+
* @param {Benchmark} b - benchmark instance
56+
*/
57+
function benchmark( b ) {
58+
var out;
59+
var i;
60+
61+
b.tic();
62+
for ( i = 0; i < b.iterations; i++ ) {
63+
out = arr.toLocaleString();
64+
if ( typeof out !== 'string' ) {
65+
b.fail( 'should return a string' );
66+
}
67+
}
68+
b.toc();
69+
if ( typeof out !== 'string' ) {
70+
b.fail( 'should return a string' );
71+
}
72+
b.pass( 'benchmark finished' );
73+
b.end();
74+
}
75+
}
76+
77+
78+
// MAIN //
79+
80+
/**
81+
* Main execution sequence.
82+
*
83+
* @private
84+
*/
85+
function main() {
86+
var len;
87+
var min;
88+
var max;
89+
var f;
90+
var i;
91+
92+
min = 1; // 10^min
93+
max = 6; // 10^max
94+
95+
for ( i = min; i <= max; i++ ) {
96+
len = pow( 10, i );
97+
f = createBenchmark( len );
98+
bench( pkg+':toLocaleString:len='+len, f );
99+
}
100+
}
101+
102+
main();

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/types/index.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ import ArrayBuffer = require( '@stdlib/array-buffer' );
3030
// Define a union type representing both iterable and non-iterable iterators:
3131
type Iterator = Iter | IterableIterator;
3232

33+
/**
34+
* Locale-specific configuration options.
35+
*/
36+
interface LocaleOptions<T = unknown> {
37+
/**
38+
* Configuration property.
39+
*/
40+
[ key: string | symbol | number ]: T | undefined;
41+
};
42+
3343
/**
3444
* Callback invoked for each element in a source object.
3545
*
@@ -1221,6 +1231,24 @@ declare class Complex64Array implements Complex64ArrayInterface {
12211231
*/
12221232
subarray( begin?: number, end?: number ): Complex64Array;
12231233

1234+
/**
1235+
* Serializes an array as a locale-specific string.
1236+
*
1237+
* @param locales - locale identifier(s)
1238+
* @param options - configuration options
1239+
* @returns string
1240+
*
1241+
* @example
1242+
* var arr = new Complex64Array( 2 );
1243+
*
1244+
* arr.set( [ 1.0, 1.0 ], 0 );
1245+
* arr.set( [ 2.0, 2.0 ], 1 );
1246+
*
1247+
* var str = arr.toLocaleString();
1248+
* // returns '1 + 1i,2 + 2i'
1249+
*/
1250+
toLocaleString( locales?: string | Array<string>, options?: LocaleOptions ): string;
1251+
12241252
/**
12251253
* Returns a new typed array containing the elements in reversed order.
12261254
*

lib/main.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var isCollection = require( '@stdlib/assert-is-collection' );
2828
var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' );
2929
var isObject = require( '@stdlib/assert-is-object' );
3030
var isArray = require( '@stdlib/assert-is-array' );
31+
var isStringArray = require( '@stdlib/assert-is-string-array' ).primitives;
3132
var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
3233
var isFunction = require( '@stdlib/assert-is-function' );
3334
var isComplexLike = require( '@stdlib/assert-is-complex-like' );
@@ -2491,6 +2492,59 @@ setReadOnly( Complex64Array.prototype, 'subarray', function subarray( begin, end
24912492
return new this.constructor( buf.buffer, offset, ( len < 0 ) ? 0 : len );
24922493
});
24932494

2495+
/**
2496+
* Serializes an array as a locale-specific string.
2497+
*
2498+
* @name toLocaleString
2499+
* @memberof Complex64Array.prototype
2500+
* @type {Function}
2501+
* @param {(string|Array<string>)} [locales] - locale identifier(s)
2502+
* @param {Object} [options] - configuration options
2503+
* @throws {TypeError} `this` must be a complex number array
2504+
* @throws {TypeError} first argument must be a string or an array of strings
2505+
* @throws {TypeError} options argument must be an object
2506+
* @returns {string} string representation
2507+
*
2508+
* @example
2509+
* var arr = new Complex64Array( 2 );
2510+
*
2511+
* arr.set( [ 1.0, 1.0 ], 0 );
2512+
* arr.set( [ 2.0, 2.0 ], 1 );
2513+
*
2514+
* var str = arr.toLocaleString();
2515+
* // returns '1 + 1i,2 + 2i'
2516+
*/
2517+
setReadOnly( Complex64Array.prototype, 'toLocaleString', function toLocaleString( locales, options ) {
2518+
var opts;
2519+
var loc;
2520+
var out;
2521+
var buf;
2522+
var i;
2523+
if ( !isComplexArray( this ) ) {
2524+
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
2525+
}
2526+
if ( arguments.length === 0 ) {
2527+
loc = [];
2528+
} else if ( isString( locales ) || isStringArray( locales ) ) {
2529+
loc = locales;
2530+
} else {
2531+
throw new TypeError( 'invalid argument. First argument must be a string or an array of strings. Value: `' + locales + '`.' );
2532+
}
2533+
if ( arguments.length < 2 ) {
2534+
opts = {};
2535+
} else if ( isObject( options ) ) {
2536+
opts = options;
2537+
} else {
2538+
throw new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
2539+
}
2540+
buf = this._buffer;
2541+
out = [];
2542+
for ( i = 0; i < this._length; i++ ) {
2543+
out.push( getComplex64( buf, i ).toLocaleString( loc, opts ) );
2544+
}
2545+
return out.join( ',' );
2546+
});
2547+
24942548
/**
24952549
* Returns a new typed array containing the elements in reversed order.
24962550
*

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"@stdlib/assert-is-nonnegative-integer": "^0.2.1",
5353
"@stdlib/assert-is-object": "^0.2.1 5C0E ",
5454
"@stdlib/assert-is-string": "^0.2.1",
55+
"@stdlib/assert-is-string-array": "^0.2.1",
5556
"@stdlib/complex-float32": "^0.2.1",
5657
"@stdlib/complex-imagf": "^0.2.1",
5758
"@stdlib/complex-realf": "^0.2.1",

0 commit comments

Comments
 (0)
0