Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dd5f89f
feat: implement `fromString` function to parse strings as unsigned 64…
impawstarlight May 21, 2026
7a258ba
docs: add readme and example
impawstarlight May 23, 2026
38e7169
bench: add benchmark for `uint64/from-string`
impawstarlight May 27, 2026
0929c41
fix: fix octal parsing
impawstarlight May 27, 2026
f644867
docs: add repl documentation for `fromString`
impawstarlight May 27, 2026
cb883db
feat: add typescript declarations
impawstarlight May 28, 2026
d352e3c
test: add unit tests for `from-string`
impawstarlight May 28, 2026
2159def
style: resolve lint errors
impawstarlight May 28, 2026
989dabb
test: add tests for max 64-bit value and overflow cases
impawstarlight May 30, 2026
d87c2dc
Merge branch 'develop' into feature/uint64-from-string
impawstarlight Jun 11, 2026
400acc7
chore: rename package
impawstarlight Jun 11, 2026
203bdc1
feat: reimplement parse logic with arbitrary radix support
impawstarlight Jun 11, 2026
7a7e5fd
Merge branch 'develop' into feature/uint64-from-string
impawstarlight Jul 21, 2026
b7ca36a
feat: major refactor
impawstarlight Jul 26, 2026
816985f
Merge branch 'develop' into feature/uint64-from-string
impawstarlight Jul 26, 2026
e887ad0
bench: update name
kgryte Jul 27, 2026
19560b0
Apply suggestions from code review
kgryte Jul 27, 2026
d69febf
Apply suggestions from code review
kgryte Jul 27, 2026
de43749
Apply suggestions from code review
kgryte Jul 27, 2026
c4410d7
Apply suggestions from code review
kgryte Jul 27, 2026
9e37de4
Apply suggestions from code review
kgryte Jul 27, 2026
5a41358
Apply suggestions from code review
kgryte Jul 27, 2026
b7eff90
Apply suggestions from code review
kgryte Jul 27, 2026
82bbc4a
Apply suggestions from code review
kgryte Jul 27, 2026
c4ddd57
Apply suggestions from code review
kgryte Jul 27, 2026
705a3ca
Apply suggestions from code review
kgryte Jul 27, 2026
56191c0
Apply suggestions from code review
kgryte Jul 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions lib/node_modules/@stdlib/number/uint64/parse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<!--

@license Apache-2.0

Copyright (c) 2026 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.

-->

# parseUint64

> Parse a string representation of a 64-bit unsigned integer.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var parseUint64 = require( '@stdlib/number/uint64/parse' );
```

#### parseUint64( str\[, radix\] )

Parses a string representation of a 64-bit unsigned integer.

```javascript
var a = parseUint64( '1234' );
// returns <Uint64>[ 1234n ]

a = parseUint64( '0xffffffffffffffff' );
// returns <Uint64>[ 18446744073709551615n ]

a = parseUint64( '123abcxyz', 36 );
// returns <Uint64>[ 2984992324091n ]
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

- The input string must be a valid representation of an 64-bit unsigned integer.
- If the provided string is malformed (e.g., contains invalid characters or is incomplete), the function throws a `SyntaxError`.
- If the provided string represents a value greater than `2^64-1` or the radix is not an integer on the interval `[2, 36]`, the function throws a `RangeError`.

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Uint64 = require( '@stdlib/number/uint64/ctor' );
var parseUint64 = require( '@stdlib/number/uint64/parse' );

var a = parseUint64( '9876543210' );
console.log( 'value: %s', a );
// => 'value: 9876543210'

a = parseUint64( '0xdeadbeef0badf00d' );
console.log( 'value: %s', a );
// => 'value: 16045690981293355021'

a = parseUint64( 'ilovestdlib', 36 );
console.log( 'value: %s', a );
// => 'value: 68013779155385123'

console.log( a instanceof Uint64 );
// => true
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

<!-- <related-links> -->

<!-- </related-links> -->

</section>

<!-- /.links -->
108 changes: 108 additions & 0 deletions lib/node_modules/@stdlib/number/uint64/parse/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 bench = require( '@stdlib/bench' );
var UINT32_MAX = require( '@stdlib/constants/uint32/max' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var Uint64 = require( '@stdlib/number/uint64/ctor' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var parseUint64 = require( './../lib' );


// VARIABLES //

var options = {
'dtype': 'uint32'
};


// MAIN //

bench( pkg, function benchmark( b ) {
var values;
var N;
var a;
var i;
var x;

N = 100;
x = discreteUniform( N, 0, UINT32_MAX, options );
values = [];
for ( i = 0; i < N; i++ ) {
a = Uint64.of( x[ i ], x[ (i+1)%N ] );
values.push( a.toString( 10 ) );
values.push( '0b'+a.toString( 2 ) );
values.push( '0o'+a.toString( 8 ) );
values.push( '0x'+a.toString( 16 ) );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
a = parseUint64( values[ i % N ] );
if ( typeof a !== 'object' ) {
b.fail( 'should return a Uint64 instance' );
}
}
b.toc();
if ( !( a instanceof Uint64 ) ) {
b.fail( 'should return a Uint64 instance' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::radix', pkg ), function benchmark( b ) {
var radices;
var values;
var rad;
var N;
var a;
var i;
var x;

N = 100;
x = discreteUniform( N, 0, UINT32_MAX, options );
values = [];
radices = [];
for ( i = 0; i < N; i++ ) {
a = Uint64.of( x[ i ], x[ (i+1)%N ] );
for ( rad = 2; rad <= 36; rad++ ) {
values.push( a.toString( rad ) );
radices.push( rad );
}
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
a = parseUint64( values[ i % N ], radices[ i % N ] );
if ( typeof a !== 'object' ) {
b.fail( 'should return a Uint64 instance' );
}
}
b.toc();
if ( !( a instanceof Uint64 ) ) {
b.fail( 'should return a Uint64 instance' );
}
b.pass( 'benchmark finished' );
b.end();
});
29 changes: 29 additions & 0 deletions lib/node_modules/@stdlib/number/uint64/parse/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

{{alias}}( str[, radix] )
Parses a string representation of a 64-bit unsigned integer.

Parameters
----------
str: string
String representation of a 64-bit unsigned integer.

radix: integer (optional)
Radix (base) to use for string conversion (2-36). Default: 10.

Returns
-------
v: Uint64
64-bit unsigned integer.

Examples
--------
> var a = {{alias}}( '1234' )
<Uint64>[ 1234n ]
> a = {{alias}}( '0xffffffffffffffff' )
<Uint64>[ 18446744073709551615n ]
> a = {{alias}}( '123abcxyz', 36 )
<Uint64>[ 2984992324091n ]

See Also
--------

45 changes: 45 additions & 0 deletions lib/node_modules/@stdlib/number/uint64/parse/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 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.
*/

// TypeScript Version: 4.1

import Uint64 = require( '@stdlib/number/uint64/ctor' );

/**
* Parses a string representation of a 64-bit unsigned integer.
*
* @param str - string representation of a 64-bit unsigned integer
* @param radix - radix (base) to use for string conversion (2-36)
* @returns 64-bit unsigned integer
*
* @example
* var a = parseUint64( '1234' );
* // returns <Uint64>[ 1234n ]
*
* a = parseUint64( '0xffffffffffffffff' );
* // returns <Uint64>[ 18446744073709551615n ]
*
* a = parseUint64( '123abcxyz', 36 );
* // returns <Uint64>[ 2984992324091n ]
*/
declare function parseUint64( str: string, radix?: number ): Uint64;


// EXPORTS //

export = parseUint64;
62 changes: 62 additions & 0 deletions lib/node_modules/@stdlib/number/uint64/parse/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 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.
*/

import parseUint64 = require( './index' );


// TESTS //

// The function returns a 64-bit unsigned integer...
{
parseUint64( '1234' ); // $ExpectType Uint64
parseUint64( '0xabcd' ); // $ExpectType Uint64
parseUint64( 'wxyz', 36 ); // $ExpectType Uint64
}

// The compiler throws an error if the function is provided a first argument which is not a string...
{
parseUint64( true ); // $ExpectError
parseUint64( false ); // $ExpectError
parseUint64( null ); // $ExpectError
parseUint64( 123 ); // $ExpectError
parseUint64( {} ); // $ExpectError
parseUint64( ( x: number ): number => x ); // $ExpectError

parseUint64( 5, 36 ); // $ExpectError
parseUint64( true, 36 ); // $ExpectError
parseUint64( false, 36 ); // $ExpectError
parseUint64( null, 36 ); // $ExpectError
parseUint64( {}, 36 ); // $ExpectError
parseUint64( ( x: number ): number => x, 36 ); // $ExpectError
}

// The compiler throws an error if the function is provided a second argument which is not a number...
{
parseUint64( '1234', '5' ); // $ExpectError
parseUint64( '1234', true ); // $ExpectError
parseUint64( '1234', false ); // $ExpectError
parseUint64( '1234', null ); // $ExpectError
parseUint64( '1234', {} ); // $ExpectError
parseUint64( '1234', ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
parseUint64(); // $ExpectError
parseUint64( '1234', 10, 1 ); // $ExpectError
}
Loading