Remove build output committed beside the sources

19c8d69 (2026-01-11) and later commits added the build's output to every
package directory: 1484 .js/.d.ts files under cjs/ and at the package roots,
plus 14 copies of LICENSE (identical to the root one, which the build copies
into each package itself). Upstream keeps none of it. With the source
manifests pointing at them, imports resolved to this stale output instead of
src, and a JavaScript-checking build (@pezkuwi/dev 0.85.12) reads them as
inputs (TS5055).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Satoshi Qazi MuhammedandClaude Opus 5.5 authored and SatoshiQaziMuhammed committed 2026-10-07 19:21:45 +04:00
1 parent 134f0ae3ce
commit 8c0bb78993
1498 files changed
-50566

No files matched your search

-201
View File
@@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.
-15
View File
@@ -1,15 +0,0 @@
/**
* @name arrayChunk
* @summary Split T[] into T[][] based on the defind size
* @description
* Returns a set ao arrays based on the chunksize
* @example
* <BR>
*
* ```javascript
* import { arrayChunk } from '@pezkuwi/util';
*
* arrayChunk([1, 2, 3, 4, 5]); // [[1, 2], [3, 4], [5]]
* ```
*/
export declare function arrayChunk<T>(array: T[], chunkSize: number): T[][];
-27
View File
@@ -1,27 +0,0 @@
/**
* @name arrayChunk
* @summary Split T[] into T[][] based on the defind size
* @description
* Returns a set ao arrays based on the chunksize
* @example
* <BR>
*
* ```javascript
* import { arrayChunk } from '@pezkuwi/util';
*
* arrayChunk([1, 2, 3, 4, 5]); // [[1, 2], [3, 4], [5]]
* ```
*/
export function arrayChunk(array, chunkSize) {
const outputSize = Math.ceil(array.length / chunkSize);
// shortcut for the single-split case
if (outputSize === 1) {
return [array];
}
const output = Array(outputSize);
for (let i = 0; i < outputSize; i++) {
const offset = i * chunkSize;
output[i] = array.slice(offset, offset + chunkSize);
}
return output;
}
-16
View File
@@ -1,16 +0,0 @@
/**
* @name arrayFilter
* @summary Filters undefined and (optionally) null values from an array
* @description
* Returns a new array with all `undefined` values removed. Optionally, when `allowNulls = false`, it removes the `null` values as well
* @example
* <BR>
*
* ```javascript
* import { arrayFilter } from '@pezkuwi/util';
*
* arrayFilter([0, void 0, true, null, false, '']); // [0, true, null, false, '']
* arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, '']
* ```
*/
export declare function arrayFilter<T = unknown>(array: readonly (T | null | undefined)[], allowNulls?: boolean): T[];
-19
View File
@@ -1,19 +0,0 @@
/**
* @name arrayFilter
* @summary Filters undefined and (optionally) null values from an array
* @description
* Returns a new array with all `undefined` values removed. Optionally, when `allowNulls = false`, it removes the `null` values as well
* @example
* <BR>
*
* ```javascript
* import { arrayFilter } from '@pezkuwi/util';
*
* arrayFilter([0, void 0, true, null, false, '']); // [0, true, null, false, '']
* arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, '']
* ```
*/
export function arrayFilter(array, allowNulls = true) {
return array.filter((v) => v !== undefined &&
(allowNulls || v !== null));
}
-15
View File
@@ -1,15 +0,0 @@
/**
* @name arrayFlatten
* @summary Merge T[][] into T[]
* @description
* Returns a new array with all arrays merged into one
* @example
* <BR>
*
* ```javascript
* import { arrayFlatten } from '@pezkuwi/util';
*
* arrayFlatten([[1, 2], [3, 4], [5]]); // [1, 2, 3, 4, 5]
* ```
*/
export declare function arrayFlatten<T>(arrays: readonly T[][]): T[];
-39
View File
@@ -1,39 +0,0 @@
/**
* @name arrayFlatten
* @summary Merge T[][] into T[]
* @description
* Returns a new array with all arrays merged into one
* @example
* <BR>
*
* ```javascript
* import { arrayFlatten } from '@pezkuwi/util';
*
* arrayFlatten([[1, 2], [3, 4], [5]]); // [1, 2, 3, 4, 5]
* ```
*/
export function arrayFlatten(arrays) {
const num = arrays.length;
// shortcuts for the empty & single-entry case
if (num === 0) {
return [];
}
else if (num === 1) {
return arrays[0];
}
// pre-allocate based on the combined size
let size = 0;
for (let i = 0; i < num; i++) {
size += arrays[i].length;
}
const output = new Array(size);
let i = -1;
for (let j = 0; j < num; j++) {
const a = arrays[j];
// instead of pushing, we just set the entries
for (let e = 0, count = a.length; e < count; e++) {
output[++i] = a[e];
}
}
return output;
}
-10
View File
@@ -1,10 +0,0 @@
/**
* @summary Utility methods that operates on arrays
*/
export { arrayChunk } from './chunk.js';
export { arrayFilter } from './filter.js';
export { arrayFlatten } from './flatten.js';
export { arrayRange } from './range.js';
export { arrayShuffle } from './shuffle.js';
export { arrayUnzip } from './unzip.js';
export { arrayZip } from './zip.js';
-10
View File
@@ -1,10 +0,0 @@
/**
* @summary Utility methods that operates on arrays
*/
export { arrayChunk } from './chunk.js';
export { arrayFilter } from './filter.js';
export { arrayFlatten } from './flatten.js';
export { arrayRange } from './range.js';
export { arrayShuffle } from './shuffle.js';
export { arrayUnzip } from './unzip.js';
export { arrayZip } from './zip.js';
-16
View File
@@ -1,16 +0,0 @@
/**
* @name arrayRange
* @summary Returns a range of numbers ith the size and the specified offset
* @description
* Returns a new array of numbers with the specific size. Optionally, when `startAt`, is provided, it generates the range to start at a specific value.
* @example
* <BR>
*
* ```javascript
* import { arrayRange } from '@pezkuwi/util';
*
* arrayRange(5); // [0, 1, 2, 3, 4]
* arrayRange(3, 5); // [5, 6, 7]
* ```
*/
export declare function arrayRange(size: number, startAt?: number): number[];
-25
View File
@@ -1,25 +0,0 @@
/**
* @name arrayRange
* @summary Returns a range of numbers ith the size and the specified offset
* @description
* Returns a new array of numbers with the specific size. Optionally, when `startAt`, is provided, it generates the range to start at a specific value.
* @example
* <BR>
*
* ```javascript
* import { arrayRange } from '@pezkuwi/util';
*
* arrayRange(5); // [0, 1, 2, 3, 4]
* arrayRange(3, 5); // [5, 6, 7]
* ```
*/
export function arrayRange(size, startAt = 0) {
if (size <= 0) {
throw new Error('Expected non-zero, positive number as a range size');
}
const result = new Array(size);
for (let i = 0; i < size; i++) {
result[i] = i + startAt;
}
return result;
}
-5
View File
@@ -1,5 +0,0 @@
/**
* @name arrayShuffle
* @description Shuffles the input array (unlike sort, this is not done in-place)
*/
export declare function arrayShuffle<T>(input: readonly T[]): T[];
-19
View File
@@ -1,19 +0,0 @@
/**
* @name arrayShuffle
* @description Shuffles the input array (unlike sort, this is not done in-place)
*/
export function arrayShuffle(input) {
const result = input.slice();
let curr = result.length;
// noop for the single entry
if (curr === 1) {
return result;
}
while (curr !== 0) {
// ~~ is more performant than Math.floor
const rand = ~~(Math.random() * curr);
curr--;
[result[curr], result[rand]] = [result[rand], result[curr]];
}
return result;
}
-5
View File
@@ -1,5 +0,0 @@
/**
* @name arrayUnzip
* @description Splits a single [K, V][] into [K[], V[]]
*/
export declare function arrayUnzip<K, V>(entries: readonly [K, V][]): [K[], V[]];
-13
View File
@@ -1,13 +0,0 @@
/**
* @name arrayUnzip
* @description Splits a single [K, V][] into [K[], V[]]
*/
export function arrayUnzip(entries) {
const count = entries.length;
const keys = new Array(count);
const values = new Array(count);
for (let i = 0; i < count; i++) {
[keys[i], values[i]] = entries[i];
}
return [keys, values];
}
-5
View File
@@ -1,5 +0,0 @@
/**
* @name arrayZip
* @description Combines 2 distinct key/value arrays into a single [K, V] array
*/
export declare function arrayZip<K, V>(keys: readonly K[], values: readonly V[]): [K, V][];
-12
View File
@@ -1,12 +0,0 @@
/**
* @name arrayZip
* @description Combines 2 distinct key/value arrays into a single [K, V] array
*/
export function arrayZip(keys, values) {
const count = keys.length;
const result = new Array(count);
for (let i = 0; i < count; i++) {
result[i] = [keys[i], values[i]];
}
return result;
}
-29
View File
@@ -1,29 +0,0 @@
type MessageFn = () => string;
/**
* @name assert
* @summary Checks for a valid test, if not Error is thrown.
* @description
* Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an Error with the supplied `message`. When `test` passes, `true` is returned.
* @example
* <BR>
*
* ```javascript
* const { assert } from '@pezkuwi/util';
*
* assert(true, 'True should be true'); // passes
* assert(false, 'False should not be true'); // Error thrown
* assert(false, () => 'message'); // Error with 'message'
* ```
*/
export declare function assert(condition: unknown, message: string | MessageFn): asserts condition;
/**
* @name assertReturn
* @description Returns when the value is not undefined/null, otherwise throws assertion error
*/
export declare function assertReturn<T>(value: T | undefined | null, message: string | MessageFn): T;
/**
* @name assertUnreachable
* @description An assertion helper that ensures all codepaths are followed
*/
export declare function assertUnreachable(x: never): never;
export {};
-39
View File
@@ -1,39 +0,0 @@
import { isFunction } from './is/function.js';
/**
* @name assert
* @summary Checks for a valid test, if not Error is thrown.
* @description
* Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an Error with the supplied `message`. When `test` passes, `true` is returned.
* @example
* <BR>
*
* ```javascript
* const { assert } from '@pezkuwi/util';
*
* assert(true, 'True should be true'); // passes
* assert(false, 'False should not be true'); // Error thrown
* assert(false, () => 'message'); // Error with 'message'
* ```
*/
export function assert(condition, message) {
if (!condition) {
throw new Error(isFunction(message)
? message()
: message);
}
}
/**
* @name assertReturn
* @description Returns when the value is not undefined/null, otherwise throws assertion error
*/
export function assertReturn(value, message) {
assert(value !== undefined && value !== null, message);
return value;
}
/**
* @name assertUnreachable
* @description An assertion helper that ensures all codepaths are followed
*/
export function assertUnreachable(x) {
throw new Error(`This codepath should be unreachable. Unhandled input: ${x}`);
}
-90
View File
@@ -1,90 +0,0 @@
/**
* @name _0n
* @summary BigInt constant for 0.
*/
export declare const _0n: bigint;
/**
* @name _1n
* @summary BigInt constant for 1.
*/
export declare const _1n: bigint;
/**
* @name _2n
* @summary BigInt constant for 2.
*/
export declare const _2n: bigint;
/**
* @name _3n
* @summary BigInt constant for 3.
*/
export declare const _3n: bigint;
/**
* @name _4n
* @summary BigInt constant for 4.
*/
export declare const _4n: bigint;
/**
* @name _5n
* @summary BigInt constant for 5.
*/
export declare const _5n: bigint;
/**
* @name _6n
* @summary BigInt constant for 6.
*/
export declare const _6n: bigint;
/**
* @name _7n
* @summary BigInt constant for 7.
*/
export declare const _7n: bigint;
/**
* @name _8n
* @summary BigInt constant for 8.
*/
export declare const _8n: bigint;
/**
* @name _9n
* @summary BigInt constant for 9.
*/
export declare const _9n: bigint;
/**
* @name _10n
* @summary BigInt constant for 10.
*/
export declare const _10n: bigint;
/**
* @name _100n
* @summary BigInt constant for 100.
*/
export declare const _100n: bigint;
/**
* @name _1000n
* @summary BigInt constant for 1000.
*/
export declare const _1000n: bigint;
/**
* @name _1Mn
* @summary BigInt constant for 1,000,000 (million).
*/
export declare const _1Mn: bigint;
/**
* @name _1Bn
* @summary BigInt constant for 1,000,000,000 (billion).
*/
export declare const _1Bn: bigint;
/**
* @name _1Qn
* @summary BigInt constant for 1,000,000,000,000,000,000 (quitillion).
*/
export declare const _1Qn: bigint;
/**
* @name _2pow53n
* @summary BigInt constant for MAX_SAFE_INTEGER
*/
export declare const _2pow53n: bigint;
/**
* @name _sqrt2pow53n
* @summary BigInt constant for Math.sqrt(MAX_SAFE_INTEGER)
*/
export declare const _sqrt2pow53n: bigint;
-91
View File
@@ -1,91 +0,0 @@
import { BigInt } from '@pezkuwi/x-bigint';
/**
* @name _0n
* @summary BigInt constant for 0.
*/
export const _0n = /*#__PURE__*/ BigInt(0);
/**
* @name _1n
* @summary BigInt constant for 1.
*/
export const _1n = /*#__PURE__*/ BigInt(1);
/**
* @name _2n
* @summary BigInt constant for 2.
*/
export const _2n = /*#__PURE__*/ BigInt(2);
/**
* @name _3n
* @summary BigInt constant for 3.
*/
export const _3n = /*#__PURE__*/ BigInt(3);
/**
* @name _4n
* @summary BigInt constant for 4.
*/
export const _4n = /*#__PURE__*/ BigInt(4);
/**
* @name _5n
* @summary BigInt constant for 5.
*/
export const _5n = /*#__PURE__*/ BigInt(5);
/**
* @name _6n
* @summary BigInt constant for 6.
*/
export const _6n = /*#__PURE__*/ BigInt(6);
/**
* @name _7n
* @summary BigInt constant for 7.
*/
export const _7n = /*#__PURE__*/ BigInt(7);
/**
* @name _8n
* @summary BigInt constant for 8.
*/
export const _8n = /*#__PURE__*/ BigInt(8);
/**
* @name _9n
* @summary BigInt constant for 9.
*/
export const _9n = /*#__PURE__*/ BigInt(9);
/**
* @name _10n
* @summary BigInt constant for 10.
*/
export const _10n = /*#__PURE__*/ BigInt(10);
/**
* @name _100n
* @summary BigInt constant for 100.
*/
export const _100n = /*#__PURE__*/ BigInt(100);
/**
* @name _1000n
* @summary BigInt constant for 1000.
*/
export const _1000n = /*#__PURE__*/ BigInt(1_000);
/**
* @name _1Mn
* @summary BigInt constant for 1,000,000 (million).
*/
export const _1Mn = /*#__PURE__*/ BigInt(1_000_000);
/**
* @name _1Bn
* @summary BigInt constant for 1,000,000,000 (billion).
*/
export const _1Bn = /*#__PURE__*/ BigInt(1_000_000_000);
/**
* @name _1Qn
* @summary BigInt constant for 1,000,000,000,000,000,000 (quitillion).
*/
export const _1Qn = _1Bn * _1Bn;
/**
* @name _2pow53n
* @summary BigInt constant for MAX_SAFE_INTEGER
*/
export const _2pow53n = /*#__PURE__*/ BigInt(Number.MAX_SAFE_INTEGER);
/**
* @name _sqrt2pow53n
* @summary BigInt constant for Math.sqrt(MAX_SAFE_INTEGER)
*/
export const _sqrt2pow53n = /*#__PURE__*/ BigInt(94906265);
-2
View File
@@ -1,2 +0,0 @@
/** @internal */
export declare function createCmp<T>(cmp: (a: T, b: T) => boolean): (...items: T[]) => T;
-16
View File
@@ -1,16 +0,0 @@
/** @internal */
export function createCmp(cmp) {
return (...items) => {
const count = items.length;
if (count === 0) {
throw new Error('Must provide one or more arguments');
}
let result = items[0];
for (let i = 1; i < count; i++) {
if (cmp(items[i], result)) {
result = items[i];
}
}
return result;
};
}
-9
View File
@@ -1,9 +0,0 @@
/**
* @summary Utility methods to convert to and from `bigint` objects
*/
export { nMax, nMin } from './min.js';
export { nSqrt } from './sqrt.js';
export { nToBigInt } from './toBigInt.js';
export { nToHex } from './toHex.js';
export { nToU8a } from './toU8a.js';
export * from './consts.js';
-9
View File
@@ -1,9 +0,0 @@
/**
* @summary Utility methods to convert to and from `bigint` objects
*/
export { nMax, nMin } from './min.js';
export { nSqrt } from './sqrt.js';
export { nToBigInt } from './toBigInt.js';
export { nToHex } from './toHex.js';
export { nToU8a } from './toU8a.js';
export * from './consts.js';
-10
View File
@@ -1,10 +0,0 @@
/**
* @name nMax
* @summary Finds and returns the highest value in an array of bigint.
*/
export declare const nMax: (...items: bigint[]) => bigint;
/**
* @name nMin
* @summary Finds and returns the lowest value in an array of bigint.
*/
export declare const nMin: (...items: bigint[]) => bigint;
-11
View File
@@ -1,11 +0,0 @@
import { createCmp } from './helpers.js';
/**
* @name nMax
* @summary Finds and returns the highest value in an array of bigint.
*/
export const nMax = /*#__PURE__*/ createCmp((a, b) => a > b);
/**
* @name nMin
* @summary Finds and returns the lowest value in an array of bigint.
*/
export const nMin = /*#__PURE__*/ createCmp((a, b) => a < b);
-7
View File
@@ -1,7 +0,0 @@
import type { BN } from '../bn/index.js';
import type { ToBigInt, ToBn } from '../types.js';
/**
* @name nSqrt
* @summary Calculates the integer square root of a bigint
*/
export declare function nSqrt<ExtToBn extends ToBn | ToBigInt>(value: ExtToBn | BN | bigint | string | number | null): bigint;
-29
View File
@@ -1,29 +0,0 @@
import { BigInt } from '@pezkuwi/x-bigint';
import { _0n, _1n, _2pow53n, _sqrt2pow53n } from './consts.js';
import { nToBigInt } from './toBigInt.js';
/**
* @name nSqrt
* @summary Calculates the integer square root of a bigint
*/
export function nSqrt(value) {
const n = nToBigInt(value);
if (n < _0n) {
throw new Error('square root of negative numbers is not supported');
}
// https://stackoverflow.com/questions/53683995/javascript-big-integer-square-root/
// shortcut <= 2^53 - 1 to use the JS utils
if (n <= _2pow53n) {
// ~~ is more performant that Math.floor
return BigInt(~~Math.sqrt(Number(n)));
}
// Use sqrt(MAX_SAFE_INTEGER) as starting point. since we already know the
// output will be larger than this, we expect this to be a safe start
let x0 = _sqrt2pow53n;
while (true) {
const x1 = ((n / x0) + x0) >> _1n;
if (x0 === x1 || (x0 === (x1 - _1n))) {
return x0;
}
x0 = x1;
}
}
-7
View File
@@ -1,7 +0,0 @@
import type { BN } from '../bn/bn.js';
import type { ToBigInt, ToBn } from '../types.js';
/**
* @name nToBigInt
* @summary Creates a bigInt value from a BN, bigint, string (base 10 or hex) or number input.
*/
export declare function nToBigInt<ExtToBn extends ToBigInt | ToBn>(value?: ExtToBn | BN | bigint | string | number | null): bigint;
-25
View File
@@ -1,25 +0,0 @@
import { BigInt } from '@pezkuwi/x-bigint';
import { hexToBigInt } from '../hex/toBigInt.js';
import { isBn } from '../is/bn.js';
import { isHex } from '../is/hex.js';
import { isToBigInt } from '../is/toBigInt.js';
import { isToBn } from '../is/toBn.js';
/**
* @name nToBigInt
* @summary Creates a bigInt value from a BN, bigint, string (base 10 or hex) or number input.
*/
export function nToBigInt(value) {
return typeof value === 'bigint'
? value
: !value
? BigInt(0)
: isHex(value)
? hexToBigInt(value.toString())
: isBn(value)
? BigInt(value.toString())
: isToBigInt(value)
? value.toBigInt()
: isToBn(value)
? BigInt(value.toBn().toString())
: BigInt(value);
}
-7
View File
@@ -1,7 +0,0 @@
import type { BN } from '../bn/bn.js';
import type { HexString, NumberOptions, ToBigInt, ToBn } from '../types.js';
/**
* @name nToHex
* @summary Creates a hex value from a bigint object.
*/
export declare function nToHex<ExtToBn extends ToBn | ToBigInt>(value?: ExtToBn | BN | bigint | number | null, { bitLength, isLe, isNegative }?: NumberOptions): HexString;
-9
View File
@@ -1,9 +0,0 @@
import { u8aToHex } from '../u8a/index.js';
import { nToU8a } from './toU8a.js';
/**
* @name nToHex
* @summary Creates a hex value from a bigint object.
*/
export function nToHex(value, { bitLength = -1, isLe = false, isNegative = false } = {}) {
return u8aToHex(nToU8a(value || 0, { bitLength, isLe, isNegative }));
}
-7
View File
@@ -1,7 +0,0 @@
import type { BN } from '../bn/bn.js';
import type { NumberOptions, ToBigInt, ToBn } from '../types.js';
/**
* @name nToU8a
* @summary Creates a Uint8Array object from a bigint.
*/
export declare function nToU8a<ExtToBn extends ToBn | ToBigInt>(value?: ExtToBn | BN | bigint | number | null, { bitLength, isLe, isNegative }?: NumberOptions): Uint8Array;
-49
View File
@@ -1,49 +0,0 @@
import { BigInt } from '@pezkuwi/x-bigint';
import { _0n, _1n } from './consts.js';
import { nToBigInt } from './toBigInt.js';
const DIV = BigInt(256);
const NEG_MASK = BigInt(0xff);
function toU8a(value, isLe, isNegative) {
const arr = [];
const withSigned = isNegative && (value < _0n);
if (withSigned) {
value = (value + _1n) * -_1n;
}
while (value !== _0n) {
const mod = value % DIV;
const val = Number(withSigned
? mod ^ NEG_MASK
: mod);
if (isLe) {
arr.push(val);
}
else {
arr.unshift(val);
}
value = (value - mod) / DIV;
}
return Uint8Array.from(arr);
}
/**
* @name nToU8a
* @summary Creates a Uint8Array object from a bigint.
*/
export function nToU8a(value, { bitLength = -1, isLe = true, isNegative = false } = {}) {
const valueBi = nToBigInt(value);
if (valueBi === _0n) {
return bitLength === -1
? new Uint8Array(1)
: new Uint8Array(Math.ceil((bitLength || 0) / 8));
}
const u8a = toU8a(valueBi, isLe, isNegative);
if (bitLength === -1) {
return u8a;
}
const byteLength = Math.ceil((bitLength || 0) / 8);
const output = new Uint8Array(byteLength);
if (isNegative) {
output.fill(0xff);
}
output.set(u8a, isLe ? 0 : byteLength - u8a.length);
return output;
}
-2
View File
@@ -1,2 +0,0 @@
import BN from 'bn.js';
export { BN };
-2
View File
@@ -1,2 +0,0 @@
import BN from 'bn.js';
export { BN };
-91
View File
@@ -1,91 +0,0 @@
import { BN } from './bn.js';
/**
* @name BN_ZERO
* @summary BN constant for 0.
*/
export declare const BN_ZERO: BN;
/**
* @name BN_ONE
* @summary BN constant for 1.
*/
export declare const BN_ONE: BN;
/**
* @name BN_TWO
* @summary BN constant for 2.
*/
export declare const BN_TWO: BN;
/**
* @name BN_THREE
* @summary BN constant for 3.
*/
export declare const BN_THREE: BN;
/**
* @name BN_FOUR
* @summary BN constant for 4.
*/
export declare const BN_FOUR: BN;
/**
* @name BN_FIVE
* @summary BN constant for 5.
*/
export declare const BN_FIVE: BN;
/**
* @name BN_SIX
* @summary BN constant for 6.
*/
export declare const BN_SIX: BN;
/**
* @name BN_SEVEN
* @summary BN constant for 7.
*/
export declare const BN_SEVEN: BN;
/**
* @name BN_EIGHT
* @summary BN constant for 8.
*/
export declare const BN_EIGHT: BN;
/**
* @name BN_NINE
* @summary BN constant for 9.
*/
export declare const BN_NINE: BN;
/**
* @name BN_TEN
* @summary BN constant for 10.
*/
export declare const BN_TEN: BN;
/**
* @name BN_HUNDRED
* @summary BN constant for 100.
*/
export declare const BN_HUNDRED: BN;
/**
* @name BN_THOUSAND
* @summary BN constant for 1,000.
*/
export declare const BN_THOUSAND: BN;
/**
* @name BN_MILLION
* @summary BN constant for 1,000,000.
*/
export declare const BN_MILLION: BN;
/**
* @name BN_BILLION
* @summary BN constant for 1,000,000,000.
*/
export declare const BN_BILLION: BN;
/**
* @name BN_QUINTILL
* @summary BN constant for 1,000,000,000,000,000,000.
*/
export declare const BN_QUINTILL: BN;
/**
* @name BN_MAX_INTEGER
* @summary BN constant for MAX_SAFE_INTEGER
*/
export declare const BN_MAX_INTEGER: BN;
/**
* @name BN_SQRT_MAX_INTEGER
* @summary BN constant for Math.sqrt(MAX_SAFE_INTEGER)
*/
export declare const BN_SQRT_MAX_INTEGER: BN;
-91
View File
@@ -1,91 +0,0 @@
import { BN } from './bn.js';
/**
* @name BN_ZERO
* @summary BN constant for 0.
*/
export const BN_ZERO = /*#__PURE__*/ new BN(0);
/**
* @name BN_ONE
* @summary BN constant for 1.
*/
export const BN_ONE = /*#__PURE__*/ new BN(1);
/**
* @name BN_TWO
* @summary BN constant for 2.
*/
export const BN_TWO = /*#__PURE__*/ new BN(2);
/**
* @name BN_THREE
* @summary BN constant for 3.
*/
export const BN_THREE = /*#__PURE__*/ new BN(3);
/**
* @name BN_FOUR
* @summary BN constant for 4.
*/
export const BN_FOUR = /*#__PURE__*/ new BN(4);
/**
* @name BN_FIVE
* @summary BN constant for 5.
*/
export const BN_FIVE = /*#__PURE__*/ new BN(5);
/**
* @name BN_SIX
* @summary BN constant for 6.
*/
export const BN_SIX = /*#__PURE__*/ new BN(6);
/**
* @name BN_SEVEN
* @summary BN constant for 7.
*/
export const BN_SEVEN = /*#__PURE__*/ new BN(7);
/**
* @name BN_EIGHT
* @summary BN constant for 8.
*/
export const BN_EIGHT = /*#__PURE__*/ new BN(8);
/**
* @name BN_NINE
* @summary BN constant for 9.
*/
export const BN_NINE = /*#__PURE__*/ new BN(9);
/**
* @name BN_TEN
* @summary BN constant for 10.
*/
export const BN_TEN = /*#__PURE__*/ new BN(10);
/**
* @name BN_HUNDRED
* @summary BN constant for 100.
*/
export const BN_HUNDRED = /*#__PURE__*/ new BN(100);
/**
* @name BN_THOUSAND
* @summary BN constant for 1,000.
*/
export const BN_THOUSAND = /*#__PURE__*/ new BN(1_000);
/**
* @name BN_MILLION
* @summary BN constant for 1,000,000.
*/
export const BN_MILLION = /*#__PURE__*/ new BN(1_000_000);
/**
* @name BN_BILLION
* @summary BN constant for 1,000,000,000.
*/
export const BN_BILLION = /*#__PURE__*/ new BN(1_000_000_000);
/**
* @name BN_QUINTILL
* @summary BN constant for 1,000,000,000,000,000,000.
*/
export const BN_QUINTILL = BN_BILLION.mul(BN_BILLION);
/**
* @name BN_MAX_INTEGER
* @summary BN constant for MAX_SAFE_INTEGER
*/
export const BN_MAX_INTEGER = /*#__PURE__*/ new BN(Number.MAX_SAFE_INTEGER);
/**
* @name BN_SQRT_MAX_INTEGER
* @summary BN constant for Math.sqrt(MAX_SAFE_INTEGER)
*/
export const BN_SQRT_MAX_INTEGER = /*#__PURE__*/ new BN(94906265);
-1
View File
@@ -1 +0,0 @@
export { hexToBn as bnFromHex } from '../hex/toBn.js';
-1
View File
@@ -1 +0,0 @@
export { hexToBn as bnFromHex } from '../hex/toBn.js';
-11
View File
@@ -1,11 +0,0 @@
/**
* @summary Utility methods to convert to and from `BN` objects
*/
export { BN } from './bn.js';
export { bnFromHex } from './fromHex.js';
export { bnMax, bnMin } from './min.js';
export { bnSqrt } from './sqrt.js';
export { bnToBn } from './toBn.js';
export { bnToHex } from './toHex.js';
export { bnToU8a } from './toU8a.js';
export * from './consts.js';
-11
View File
@@ -1,11 +0,0 @@
/**
* @summary Utility methods to convert to and from `BN` objects
*/
export { BN } from './bn.js';
export { bnFromHex } from './fromHex.js';
export { bnMax, bnMin } from './min.js';
export { bnSqrt } from './sqrt.js';
export { bnToBn } from './toBn.js';
export { bnToHex } from './toHex.js';
export { bnToU8a } from './toU8a.js';
export * from './consts.js';
-29
View File
@@ -1,29 +0,0 @@
import type { BN } from './bn.js';
/**
* @name bnMax
* @summary Finds and returns the highest value in an array of BNs.
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnMax } from '@pezkuwi/util';
*
* bnMax([new BN(1), new BN(3), new BN(2)]).toString(); // => '3'
* ```
*/
export declare const bnMax: (...items: BN[]) => BN;
/**
* @name bnMin
* @summary Finds and returns the smallest value in an array of BNs.
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnMin } from '@pezkuwi/util';
*
* bnMin([new BN(1), new BN(3), new BN(2)]).toString(); // => '1'
* ```
*/
export declare const bnMin: (...items: BN[]) => BN;
-29
View File
@@ -1,29 +0,0 @@
import { createCmp } from '../bi/helpers.js';
/**
* @name bnMax
* @summary Finds and returns the highest value in an array of BNs.
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnMax } from '@pezkuwi/util';
*
* bnMax([new BN(1), new BN(3), new BN(2)]).toString(); // => '3'
* ```
*/
export const bnMax = /*#__PURE__*/ createCmp((a, b) => a.gt(b));
/**
* @name bnMin
* @summary Finds and returns the smallest value in an array of BNs.
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnMin } from '@pezkuwi/util';
*
* bnMin([new BN(1), new BN(3), new BN(2)]).toString(); // => '1'
* ```
*/
export const bnMin = /*#__PURE__*/ createCmp((a, b) => a.lt(b));
-16
View File
@@ -1,16 +0,0 @@
import type { ToBn } from '../types.js';
import { BN } from './bn.js';
/**
* @name bnSqrt
* @summary Calculates the integer square root of a BN
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnSqrt } from '@pezkuwi/util';
*
* bnSqrt(new BN(16)).toString(); // => '4'
* ```
*/
export declare function bnSqrt<ExtToBn extends ToBn>(value: ExtToBn | BN | bigint | string | number | null): BN;
-38
View File
@@ -1,38 +0,0 @@
import { BN } from './bn.js';
import { BN_MAX_INTEGER, BN_ONE, BN_SQRT_MAX_INTEGER } from './consts.js';
import { bnToBn } from './toBn.js';
/**
* @name bnSqrt
* @summary Calculates the integer square root of a BN
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnSqrt } from '@pezkuwi/util';
*
* bnSqrt(new BN(16)).toString(); // => '4'
* ```
*/
export function bnSqrt(value) {
const n = bnToBn(value);
if (n.isNeg()) {
throw new Error('square root of negative numbers is not supported');
}
// https://stackoverflow.com/questions/53683995/javascript-big-integer-square-root/
// shortcut <= 2^53 - 1 to use the JS utils
if (n.lte(BN_MAX_INTEGER)) {
// ~~ More performant version of Math.floor
return new BN(~~Math.sqrt(n.toNumber()));
}
// Use sqrt(MAX_SAFE_INTEGER) as starting point. since we already know the
// output will be larger than this, we expect this to be a safe start
let x0 = BN_SQRT_MAX_INTEGER.clone();
while (true) {
const x1 = n.div(x0).iadd(x0).ishrn(1);
if (x0.eq(x1) || x0.eq(x1.sub(BN_ONE))) {
return x0;
}
x0 = x1;
}
}
-19
View File
@@ -1,19 +0,0 @@
import type { ToBigInt, ToBn } from '../types.js';
import { BN } from './bn.js';
/**
* @name bnToBn
* @summary Creates a BN value from a BN, bigint, string (base 10 or hex) or number input.
* @description
* `null` inputs returns a `0x0` result, BN values returns the value, numbers returns a BN representation.
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnToBn } from '@pezkuwi/util';
*
* bnToBn(0x1234); // => BN(0x1234)
* bnToBn(new BN(0x1234)); // => BN(0x1234)
* ```
*/
export declare function bnToBn<ExtToBn extends ToBigInt | ToBn>(value?: ExtToBn | BN | bigint | string | number | null): BN;
-37
View File
@@ -1,37 +0,0 @@
import { hexToBn } from '../hex/toBn.js';
import { isBigInt } from '../is/bigInt.js';
import { isHex } from '../is/hex.js';
import { isToBigInt } from '../is/toBigInt.js';
import { isToBn } from '../is/toBn.js';
import { BN } from './bn.js';
/**
* @name bnToBn
* @summary Creates a BN value from a BN, bigint, string (base 10 or hex) or number input.
* @description
* `null` inputs returns a `0x0` result, BN values returns the value, numbers returns a BN representation.
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnToBn } from '@pezkuwi/util';
*
* bnToBn(0x1234); // => BN(0x1234)
* bnToBn(new BN(0x1234)); // => BN(0x1234)
* ```
*/
export function bnToBn(value) {
return value
? BN.isBN(value)
? value
: isHex(value)
? hexToBn(value.toString())
: isBigInt(value)
? new BN(value.toString())
: isToBn(value)
? value.toBn()
: isToBigInt(value)
? new BN(value.toBigInt().toString())
: new BN(value)
: new BN(0);
}
-18
View File
@@ -1,18 +0,0 @@
import type { HexString, NumberOptions, ToBn } from '../types.js';
import type { BN } from './bn.js';
/**
* @name bnToHex
* @summary Creates a hex value from a BN.js bignumber object.
* @description
* `null` inputs returns a `0x` result, BN values return the actual value as a `0x` prefixed hex value. Anything that is not a BN object throws an error. With `bitLength` set, it fixes the number to the specified length.
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnToHex } from '@pezkuwi/util';
*
* bnToHex(new BN(0x123456)); // => '0x123456'
* ```
*/
export declare function bnToHex<ExtToBn extends ToBn>(value?: ExtToBn | BN | bigint | number | null, { bitLength, isLe, isNegative }?: NumberOptions): HexString;
-20
View File
@@ -1,20 +0,0 @@
import { u8aToHex } from '../u8a/index.js';
import { bnToU8a } from './toU8a.js';
/**
* @name bnToHex
* @summary Creates a hex value from a BN.js bignumber object.
* @description
* `null` inputs returns a `0x` result, BN values return the actual value as a `0x` prefixed hex value. Anything that is not a BN object throws an error. With `bitLength` set, it fixes the number to the specified length.
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnToHex } from '@pezkuwi/util';
*
* bnToHex(new BN(0x123456)); // => '0x123456'
* ```
*/
export function bnToHex(value, { bitLength = -1, isLe = false, isNegative = false } = {}) {
return u8aToHex(bnToU8a(value, { bitLength, isLe, isNegative }));
}
-17
View File
@@ -1,17 +0,0 @@
import type { NumberOptions, ToBn } from '../types.js';
import type { BN } from './bn.js';
/**
* @name bnToU8a
* @summary Creates a Uint8Array object from a BN.
* @description
* `null`/`undefined`/`NaN` inputs returns an empty `Uint8Array` result. `BN` input values return the actual bytes value converted to a `Uint8Array`. Optionally convert using little-endian format if `isLE` is set.
* @example
* <BR>
*
* ```javascript
* import { bnToU8a } from '@pezkuwi/util';
*
* bnToU8a(new BN(0x1234)); // => [0x12, 0x34]
* ```
*/
export declare function bnToU8a<ExtToBn extends ToBn>(value?: ExtToBn | BN | bigint | number | null, { bitLength, isLe, isNegative }?: NumberOptions): Uint8Array;
-33
View File
@@ -1,33 +0,0 @@
import { bnToBn } from './toBn.js';
const DEFAULT_OPTS = { bitLength: -1, isLe: true, isNegative: false };
/**
* @name bnToU8a
* @summary Creates a Uint8Array object from a BN.
* @description
* `null`/`undefined`/`NaN` inputs returns an empty `Uint8Array` result. `BN` input values return the actual bytes value converted to a `Uint8Array`. Optionally convert using little-endian format if `isLE` is set.
* @example
* <BR>
*
* ```javascript
* import { bnToU8a } from '@pezkuwi/util';
*
* bnToU8a(new BN(0x1234)); // => [0x12, 0x34]
* ```
*/
export function bnToU8a(value, { bitLength = -1, isLe = true, isNegative = false } = DEFAULT_OPTS) {
const valueBn = bnToBn(value);
const byteLength = bitLength === -1
? Math.ceil(valueBn.bitLength() / 8)
: Math.ceil((bitLength || 0) / 8);
if (!value) {
return bitLength === -1
? new Uint8Array(1)
: new Uint8Array(byteLength);
}
const output = new Uint8Array(byteLength);
const bn = isNegative
? valueBn.toTwos(byteLength * 8)
: valueBn;
output.set(bn.toArray(isLe ? 'le' : 'be', byteLength), 0);
return output;
}
-4
View File
@@ -1,4 +0,0 @@
/**
* @summary Utility methods to convert to and from `Buffer` objects
*/
export { bufferToU8a } from './toU8a.js';
-4
View File
@@ -1,4 +0,0 @@
/**
* @summary Utility methods to convert to and from `Buffer` objects
*/
export { bufferToU8a } from './toU8a.js';
-15
View File
@@ -1,15 +0,0 @@
/**
* @name bufferToU8a
* @summary Creates a Uint8Array value from a Buffer object.
* @description
* `null` inputs returns an empty result, `Buffer` values return the actual value as a `Uint8Array`. Anything that is not a `Buffer` object throws an error.
* @example
* <BR>
*
* ```javascript
* import { bufferToU8a } from '@pezkuwi/util';
*
* bufferToU8a(Buffer.from([1, 2, 3]));
* ```
*/
export declare function bufferToU8a(buffer?: Uint8Array | number[] | null): Uint8Array;
-17
View File
@@ -1,17 +0,0 @@
/**
* @name bufferToU8a
* @summary Creates a Uint8Array value from a Buffer object.
* @description
* `null` inputs returns an empty result, `Buffer` values return the actual value as a `Uint8Array`. Anything that is not a `Buffer` object throws an error.
* @example
* <BR>
*
* ```javascript
* import { bufferToU8a } from '@pezkuwi/util';
*
* bufferToU8a(Buffer.from([1, 2, 3]));
* ```
*/
export function bufferToU8a(buffer) {
return new Uint8Array(buffer || []);
}
File diff suppressed because it is too large. Load diff
-28
View File
@@ -1,28 +0,0 @@
/**
* @summary Utility methods for this package are split into groups
*/
export { packageInfo } from './packageInfo.js';
export * from './array/index.js';
export * from './assert.js';
export * from './bi/index.js';
export * from './bn/index.js';
export * from './buffer/index.js';
export * from './compact/index.js';
export * from './detectPackage.js';
export * from './extractTime.js';
export * from './float/index.js';
export * from './format/index.js';
export * from './has.js';
export * from './hex/index.js';
export * from './is/index.js';
export * from './lazy.js';
export * from './logger.js';
export * from './memoize.js';
export * from './nextTick.js';
export * from './noop.js';
export * from './number/index.js';
export * from './object/index.js';
export * from './promisify.js';
export * from './string/index.js';
export * from './stringify.js';
export * from './u8a/index.js';
-28
View File
@@ -1,28 +0,0 @@
/**
* @summary Utility methods for this package are split into groups
*/
export { packageInfo } from './packageInfo.js';
export * from './array/index.js';
export * from './assert.js';
export * from './bi/index.js';
export * from './bn/index.js';
export * from './buffer/index.js';
export * from './compact/index.js';
export * from './detectPackage.js';
export * from './extractTime.js';
export * from './float/index.js';
export * from './format/index.js';
export * from './has.js';
export * from './hex/index.js';
export * from './is/index.js';
export * from './lazy.js';
export * from './logger.js';
export * from './memoize.js';
export * from './nextTick.js';
export * from './noop.js';
export * from './number/index.js';
export * from './object/index.js';
export * from './promisify.js';
export * from './string/index.js';
export * from './stringify.js';
export * from './u8a/index.js';
-15
View File
@@ -1,15 +0,0 @@
/**
* @name arrayChunk
* @summary Split T[] into T[][] based on the defind size
* @description
* Returns a set ao arrays based on the chunksize
* @example
* <BR>
*
* ```javascript
* import { arrayChunk } from '@pezkuwi/util';
*
* arrayChunk([1, 2, 3, 4, 5]); // [[1, 2], [3, 4], [5]]
* ```
*/
export declare function arrayChunk<T>(array: T[], chunkSize: number): T[][];
-30
View File
@@ -1,30 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayChunk = arrayChunk;
/**
* @name arrayChunk
* @summary Split T[] into T[][] based on the defind size
* @description
* Returns a set ao arrays based on the chunksize
* @example
* <BR>
*
* ```javascript
* import { arrayChunk } from '@pezkuwi/util';
*
* arrayChunk([1, 2, 3, 4, 5]); // [[1, 2], [3, 4], [5]]
* ```
*/
function arrayChunk(array, chunkSize) {
const outputSize = Math.ceil(array.length / chunkSize);
// shortcut for the single-split case
if (outputSize === 1) {
return [array];
}
const output = Array(outputSize);
for (let i = 0; i < outputSize; i++) {
const offset = i * chunkSize;
output[i] = array.slice(offset, offset + chunkSize);
}
return output;
}
-16
View File
@@ -1,16 +0,0 @@
/**
* @name arrayFilter
* @summary Filters undefined and (optionally) null values from an array
* @description
* Returns a new array with all `undefined` values removed. Optionally, when `allowNulls = false`, it removes the `null` values as well
* @example
* <BR>
*
* ```javascript
* import { arrayFilter } from '@pezkuwi/util';
*
* arrayFilter([0, void 0, true, null, false, '']); // [0, true, null, false, '']
* arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, '']
* ```
*/
export declare function arrayFilter<T = unknown>(array: readonly (T | null | undefined)[], allowNulls?: boolean): T[];
-22
View File
@@ -1,22 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayFilter = arrayFilter;
/**
* @name arrayFilter
* @summary Filters undefined and (optionally) null values from an array
* @description
* Returns a new array with all `undefined` values removed. Optionally, when `allowNulls = false`, it removes the `null` values as well
* @example
* <BR>
*
* ```javascript
* import { arrayFilter } from '@pezkuwi/util';
*
* arrayFilter([0, void 0, true, null, false, '']); // [0, true, null, false, '']
* arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, '']
* ```
*/
function arrayFilter(array, allowNulls = true) {
return array.filter((v) => v !== undefined &&
(allowNulls || v !== null));
}
-15
View File
@@ -1,15 +0,0 @@
/**
* @name arrayFlatten
* @summary Merge T[][] into T[]
* @description
* Returns a new array with all arrays merged into one
* @example
* <BR>
*
* ```javascript
* import { arrayFlatten } from '@pezkuwi/util';
*
* arrayFlatten([[1, 2], [3, 4], [5]]); // [1, 2, 3, 4, 5]
* ```
*/
export declare function arrayFlatten<T>(arrays: readonly T[][]): T[];
-42
View File
@@ -1,42 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayFlatten = arrayFlatten;
/**
* @name arrayFlatten
* @summary Merge T[][] into T[]
* @description
* Returns a new array with all arrays merged into one
* @example
* <BR>
*
* ```javascript
* import { arrayFlatten } from '@pezkuwi/util';
*
* arrayFlatten([[1, 2], [3, 4], [5]]); // [1, 2, 3, 4, 5]
* ```
*/
function arrayFlatten(arrays) {
const num = arrays.length;
// shortcuts for the empty & single-entry case
if (num === 0) {
return [];
}
else if (num === 1) {
return arrays[0];
}
// pre-allocate based on the combined size
let size = 0;
for (let i = 0; i < num; i++) {
size += arrays[i].length;
}
const output = new Array(size);
let i = -1;
for (let j = 0; j < num; j++) {
const a = arrays[j];
// instead of pushing, we just set the entries
for (let e = 0, count = a.length; e < count; e++) {
output[++i] = a[e];
}
}
return output;
}
-10
View File
@@ -1,10 +0,0 @@
/**
* @summary Utility methods that operates on arrays
*/
export { arrayChunk } from './chunk.js';
export { arrayFilter } from './filter.js';
export { arrayFlatten } from './flatten.js';
export { arrayRange } from './range.js';
export { arrayShuffle } from './shuffle.js';
export { arrayUnzip } from './unzip.js';
export { arrayZip } from './zip.js';
-20
View File
@@ -1,20 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayZip = exports.arrayUnzip = exports.arrayShuffle = exports.arrayRange = exports.arrayFlatten = exports.arrayFilter = exports.arrayChunk = void 0;
/**
* @summary Utility methods that operates on arrays
*/
var chunk_js_1 = require("./chunk.js");
Object.defineProperty(exports, "arrayChunk", { enumerable: true, get: function () { return chunk_js_1.arrayChunk; } });
var filter_js_1 = require("./filter.js");
Object.defineProperty(exports, "arrayFilter", { enumerable: true, get: function () { return filter_js_1.arrayFilter; } });
var flatten_js_1 = require("./flatten.js");
Object.defineProperty(exports, "arrayFlatten", { enumerable: true, get: function () { return flatten_js_1.arrayFlatten; } });
var range_js_1 = require("./range.js");
Object.defineProperty(exports, "arrayRange", { enumerable: true, get: function () { return range_js_1.arrayRange; } });
var shuffle_js_1 = require("./shuffle.js");
Object.defineProperty(exports, "arrayShuffle", { enumerable: true, get: function () { return shuffle_js_1.arrayShuffle; } });
var unzip_js_1 = require("./unzip.js");
Object.defineProperty(exports, "arrayUnzip", { enumerable: true, get: function () { return unzip_js_1.arrayUnzip; } });
var zip_js_1 = require("./zip.js");
Object.defineProperty(exports, "arrayZip", { enumerable: true, get: function () { return zip_js_1.arrayZip; } });
-16
View File
@@ -1,16 +0,0 @@
/**
* @name arrayRange
* @summary Returns a range of numbers ith the size and the specified offset
* @description
* Returns a new array of numbers with the specific size. Optionally, when `startAt`, is provided, it generates the range to start at a specific value.
* @example
* <BR>
*
* ```javascript
* import { arrayRange } from '@pezkuwi/util';
*
* arrayRange(5); // [0, 1, 2, 3, 4]
* arrayRange(3, 5); // [5, 6, 7]
* ```
*/
export declare function arrayRange(size: number, startAt?: number): number[];
-28
View File
@@ -1,28 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayRange = arrayRange;
/**
* @name arrayRange
* @summary Returns a range of numbers ith the size and the specified offset
* @description
* Returns a new array of numbers with the specific size. Optionally, when `startAt`, is provided, it generates the range to start at a specific value.
* @example
* <BR>
*
* ```javascript
* import { arrayRange } from '@pezkuwi/util';
*
* arrayRange(5); // [0, 1, 2, 3, 4]
* arrayRange(3, 5); // [5, 6, 7]
* ```
*/
function arrayRange(size, startAt = 0) {
if (size <= 0) {
throw new Error('Expected non-zero, positive number as a range size');
}
const result = new Array(size);
for (let i = 0; i < size; i++) {
result[i] = i + startAt;
}
return result;
}
-5
View File
@@ -1,5 +0,0 @@
/**
* @name arrayShuffle
* @description Shuffles the input array (unlike sort, this is not done in-place)
*/
export declare function arrayShuffle<T>(input: readonly T[]): T[];
-22
View File
@@ -1,22 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayShuffle = arrayShuffle;
/**
* @name arrayShuffle
* @description Shuffles the input array (unlike sort, this is not done in-place)
*/
function arrayShuffle(input) {
const result = input.slice();
let curr = result.length;
// noop for the single entry
if (curr === 1) {
return result;
}
while (curr !== 0) {
// ~~ is more performant than Math.floor
const rand = ~~(Math.random() * curr);
curr--;
[result[curr], result[rand]] = [result[rand], result[curr]];
}
return result;
}
-5
View File
@@ -1,5 +0,0 @@
/**
* @name arrayUnzip
* @description Splits a single [K, V][] into [K[], V[]]
*/
export declare function arrayUnzip<K, V>(entries: readonly [K, V][]): [K[], V[]];
-16
View File
@@ -1,16 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayUnzip = arrayUnzip;
/**
* @name arrayUnzip
* @description Splits a single [K, V][] into [K[], V[]]
*/
function arrayUnzip(entries) {
const count = entries.length;
const keys = new Array(count);
const values = new Array(count);
for (let i = 0; i < count; i++) {
[keys[i], values[i]] = entries[i];
}
return [keys, values];
}
-5
View File
@@ -1,5 +0,0 @@
/**
* @name arrayZip
* @description Combines 2 distinct key/value arrays into a single [K, V] array
*/
export declare function arrayZip<K, V>(keys: readonly K[], values: readonly V[]): [K, V][];
-15
View File
@@ -1,15 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayZip = arrayZip;
/**
* @name arrayZip
* @description Combines 2 distinct key/value arrays into a single [K, V] array
*/
function arrayZip(keys, values) {
const count = keys.length;
const result = new Array(count);
for (let i = 0; i < count; i++) {
result[i] = [keys[i], values[i]];
}
return result;
}
-29
View File
@@ -1,29 +0,0 @@
type MessageFn = () => string;
/**
* @name assert
* @summary Checks for a valid test, if not Error is thrown.
* @description
* Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an Error with the supplied `message`. When `test` passes, `true` is returned.
* @example
* <BR>
*
* ```javascript
* const { assert } from '@pezkuwi/util';
*
* assert(true, 'True should be true'); // passes
* assert(false, 'False should not be true'); // Error thrown
* assert(false, () => 'message'); // Error with 'message'
* ```
*/
export declare function assert(condition: unknown, message: string | MessageFn): asserts condition;
/**
* @name assertReturn
* @description Returns when the value is not undefined/null, otherwise throws assertion error
*/
export declare function assertReturn<T>(value: T | undefined | null, message: string | MessageFn): T;
/**
* @name assertUnreachable
* @description An assertion helper that ensures all codepaths are followed
*/
export declare function assertUnreachable(x: never): never;
export {};
-44
View File
@@ -1,44 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.assert = assert;
exports.assertReturn = assertReturn;
exports.assertUnreachable = assertUnreachable;
const function_js_1 = require("./is/function.js");
/**
* @name assert
* @summary Checks for a valid test, if not Error is thrown.
* @description
* Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an Error with the supplied `message`. When `test` passes, `true` is returned.
* @example
* <BR>
*
* ```javascript
* const { assert } from '@pezkuwi/util';
*
* assert(true, 'True should be true'); // passes
* assert(false, 'False should not be true'); // Error thrown
* assert(false, () => 'message'); // Error with 'message'
* ```
*/
function assert(condition, message) {
if (!condition) {
throw new Error((0, function_js_1.isFunction)(message)
? message()
: message);
}
}
/**
* @name assertReturn
* @description Returns when the value is not undefined/null, otherwise throws assertion error
*/
function assertReturn(value, message) {
assert(value !== undefined && value !== null, message);
return value;
}
/**
* @name assertUnreachable
* @description An assertion helper that ensures all codepaths are followed
*/
function assertUnreachable(x) {
throw new Error(`This codepath should be unreachable. Unhandled input: ${x}`);
}
-90
View File
@@ -1,90 +0,0 @@
/**
* @name _0n
* @summary BigInt constant for 0.
*/
export declare const _0n: bigint;
/**
* @name _1n
* @summary BigInt constant for 1.
*/
export declare const _1n: bigint;
/**
* @name _2n
* @summary BigInt constant for 2.
*/
export declare const _2n: bigint;
/**
* @name _3n
* @summary BigInt constant for 3.
*/
export declare const _3n: bigint;
/**
* @name _4n
* @summary BigInt constant for 4.
*/
export declare const _4n: bigint;
/**
* @name _5n
* @summary BigInt constant for 5.
*/
export declare const _5n: bigint;
/**
* @name _6n
* @summary BigInt constant for 6.
*/
export declare const _6n: bigint;
/**
* @name _7n
* @summary BigInt constant for 7.
*/
export declare const _7n: bigint;
/**
* @name _8n
* @summary BigInt constant for 8.
*/
export declare const _8n: bigint;
/**
* @name _9n
* @summary BigInt constant for 9.
*/
export declare const _9n: bigint;
/**
* @name _10n
* @summary BigInt constant for 10.
*/
export declare const _10n: bigint;
/**
* @name _100n
* @summary BigInt constant for 100.
*/
export declare const _100n: bigint;
/**
* @name _1000n
* @summary BigInt constant for 1000.
*/
export declare const _1000n: bigint;
/**
* @name _1Mn
* @summary BigInt constant for 1,000,000 (million).
*/
export declare const _1Mn: bigint;
/**
* @name _1Bn
* @summary BigInt constant for 1,000,000,000 (billion).
*/
export declare const _1Bn: bigint;
/**
* @name _1Qn
* @summary BigInt constant for 1,000,000,000,000,000,000 (quitillion).
*/
export declare const _1Qn: bigint;
/**
* @name _2pow53n
* @summary BigInt constant for MAX_SAFE_INTEGER
*/
export declare const _2pow53n: bigint;
/**
* @name _sqrt2pow53n
* @summary BigInt constant for Math.sqrt(MAX_SAFE_INTEGER)
*/
export declare const _sqrt2pow53n: bigint;
-94
View File
@@ -1,94 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._sqrt2pow53n = exports._2pow53n = exports._1Qn = exports._1Bn = exports._1Mn = exports._1000n = exports._100n = exports._10n = exports._9n = exports._8n = exports._7n = exports._6n = exports._5n = exports._4n = exports._3n = exports._2n = exports._1n = exports._0n = void 0;
const x_bigint_1 = require("@pezkuwi/x-bigint");
/**
* @name _0n
* @summary BigInt constant for 0.
*/
exports._0n = (0, x_bigint_1.BigInt)(0);
/**
* @name _1n
* @summary BigInt constant for 1.
*/
exports._1n = (0, x_bigint_1.BigInt)(1);
/**
* @name _2n
* @summary BigInt constant for 2.
*/
exports._2n = (0, x_bigint_1.BigInt)(2);
/**
* @name _3n
* @summary BigInt constant for 3.
*/
exports._3n = (0, x_bigint_1.BigInt)(3);
/**
* @name _4n
* @summary BigInt constant for 4.
*/
exports._4n = (0, x_bigint_1.BigInt)(4);
/**
* @name _5n
* @summary BigInt constant for 5.
*/
exports._5n = (0, x_bigint_1.BigInt)(5);
/**
* @name _6n
* @summary BigInt constant for 6.
*/
exports._6n = (0, x_bigint_1.BigInt)(6);
/**
* @name _7n
* @summary BigInt constant for 7.
*/
exports._7n = (0, x_bigint_1.BigInt)(7);
/**
* @name _8n
* @summary BigInt constant for 8.
*/
exports._8n = (0, x_bigint_1.BigInt)(8);
/**
* @name _9n
* @summary BigInt constant for 9.
*/
exports._9n = (0, x_bigint_1.BigInt)(9);
/**
* @name _10n
* @summary BigInt constant for 10.
*/
exports._10n = (0, x_bigint_1.BigInt)(10);
/**
* @name _100n
* @summary BigInt constant for 100.
*/
exports._100n = (0, x_bigint_1.BigInt)(100);
/**
* @name _1000n
* @summary BigInt constant for 1000.
*/
exports._1000n = (0, x_bigint_1.BigInt)(1_000);
/**
* @name _1Mn
* @summary BigInt constant for 1,000,000 (million).
*/
exports._1Mn = (0, x_bigint_1.BigInt)(1_000_000);
/**
* @name _1Bn
* @summary BigInt constant for 1,000,000,000 (billion).
*/
exports._1Bn = (0, x_bigint_1.BigInt)(1_000_000_000);
/**
* @name _1Qn
* @summary BigInt constant for 1,000,000,000,000,000,000 (quitillion).
*/
exports._1Qn = exports._1Bn * exports._1Bn;
/**
* @name _2pow53n
* @summary BigInt constant for MAX_SAFE_INTEGER
*/
exports._2pow53n = (0, x_bigint_1.BigInt)(Number.MAX_SAFE_INTEGER);
/**
* @name _sqrt2pow53n
* @summary BigInt constant for Math.sqrt(MAX_SAFE_INTEGER)
*/
exports._sqrt2pow53n = (0, x_bigint_1.BigInt)(94906265);
-2
View File
@@ -1,2 +0,0 @@
/** @internal */
export declare function createCmp<T>(cmp: (a: T, b: T) => boolean): (...items: T[]) => T;
-19
View File
@@ -1,19 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCmp = createCmp;
/** @internal */
function createCmp(cmp) {
return (...items) => {
const count = items.length;
if (count === 0) {
throw new Error('Must provide one or more arguments');
}
let result = items[0];
for (let i = 1; i < count; i++) {
if (cmp(items[i], result)) {
result = items[i];
}
}
return result;
};
}
-9
View File
@@ -1,9 +0,0 @@
/**
* @summary Utility methods to convert to and from `bigint` objects
*/
export { nMax, nMin } from './min.js';
export { nSqrt } from './sqrt.js';
export { nToBigInt } from './toBigInt.js';
export { nToHex } from './toHex.js';
export { nToU8a } from './toU8a.js';
export * from './consts.js';
-19
View File
@@ -1,19 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nToU8a = exports.nToHex = exports.nToBigInt = exports.nSqrt = exports.nMin = exports.nMax = void 0;
const tslib_1 = require("tslib");
/**
* @summary Utility methods to convert to and from `bigint` objects
*/
var min_js_1 = require("./min.js");
Object.defineProperty(exports, "nMax", { enumerable: true, get: function () { return min_js_1.nMax; } });
Object.defineProperty(exports, "nMin", { enumerable: true, get: function () { return min_js_1.nMin; } });
var sqrt_js_1 = require("./sqrt.js");
Object.defineProperty(exports, "nSqrt", { enumerable: true, get: function () { return sqrt_js_1.nSqrt; } });
var toBigInt_js_1 = require("./toBigInt.js");
Object.defineProperty(exports, "nToBigInt", { enumerable: true, get: function () { return toBigInt_js_1.nToBigInt; } });
var toHex_js_1 = require("./toHex.js");
Object.defineProperty(exports, "nToHex", { enumerable: true, get: function () { return toHex_js_1.nToHex; } });
var toU8a_js_1 = require("./toU8a.js");
Object.defineProperty(exports, "nToU8a", { enumerable: true, get: function () { return toU8a_js_1.nToU8a; } });
tslib_1.__exportStar(require("./consts.js"), exports);
-10
View File
@@ -1,10 +0,0 @@
/**
* @name nMax
* @summary Finds and returns the highest value in an array of bigint.
*/
export declare const nMax: (...items: bigint[]) => bigint;
/**
* @name nMin
* @summary Finds and returns the lowest value in an array of bigint.
*/
export declare const nMin: (...items: bigint[]) => bigint;
-14
View File
@@ -1,14 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nMin = exports.nMax = void 0;
const helpers_js_1 = require("./helpers.js");
/**
* @name nMax
* @summary Finds and returns the highest value in an array of bigint.
*/
exports.nMax = (0, helpers_js_1.createCmp)((a, b) => a > b);
/**
* @name nMin
* @summary Finds and returns the lowest value in an array of bigint.
*/
exports.nMin = (0, helpers_js_1.createCmp)((a, b) => a < b);
-7
View File
@@ -1,7 +0,0 @@
import type { BN } from '../bn/index.js';
import type { ToBigInt, ToBn } from '../types.js';
/**
* @name nSqrt
* @summary Calculates the integer square root of a bigint
*/
export declare function nSqrt<ExtToBn extends ToBn | ToBigInt>(value: ExtToBn | BN | bigint | string | number | null): bigint;
-32
View File
@@ -1,32 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nSqrt = nSqrt;
const x_bigint_1 = require("@pezkuwi/x-bigint");
const consts_js_1 = require("./consts.js");
const toBigInt_js_1 = require("./toBigInt.js");
/**
* @name nSqrt
* @summary Calculates the integer square root of a bigint
*/
function nSqrt(value) {
const n = (0, toBigInt_js_1.nToBigInt)(value);
if (n < consts_js_1._0n) {
throw new Error('square root of negative numbers is not supported');
}
// https://stackoverflow.com/questions/53683995/javascript-big-integer-square-root/
// shortcut <= 2^53 - 1 to use the JS utils
if (n <= consts_js_1._2pow53n) {
// ~~ is more performant that Math.floor
return (0, x_bigint_1.BigInt)(~~Math.sqrt(Number(n)));
}
// Use sqrt(MAX_SAFE_INTEGER) as starting point. since we already know the
// output will be larger than this, we expect this to be a safe start
let x0 = consts_js_1._sqrt2pow53n;
while (true) {
const x1 = ((n / x0) + x0) >> consts_js_1._1n;
if (x0 === x1 || (x0 === (x1 - consts_js_1._1n))) {
return x0;
}
x0 = x1;
}
}
-7
View File
@@ -1,7 +0,0 @@
import type { BN } from '../bn/bn.js';
import type { ToBigInt, ToBn } from '../types.js';
/**
* @name nToBigInt
* @summary Creates a bigInt value from a BN, bigint, string (base 10 or hex) or number input.
*/
export declare function nToBigInt<ExtToBn extends ToBigInt | ToBn>(value?: ExtToBn | BN | bigint | string | number | null): bigint;
-28
View File
@@ -1,28 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nToBigInt = nToBigInt;
const x_bigint_1 = require("@pezkuwi/x-bigint");
const toBigInt_js_1 = require("../hex/toBigInt.js");
const bn_js_1 = require("../is/bn.js");
const hex_js_1 = require("../is/hex.js");
const toBigInt_js_2 = require("../is/toBigInt.js");
const toBn_js_1 = require("../is/toBn.js");
/**
* @name nToBigInt
* @summary Creates a bigInt value from a BN, bigint, string (base 10 or hex) or number input.
*/
function nToBigInt(value) {
return typeof value === 'bigint'
? value
: !value
? (0, x_bigint_1.BigInt)(0)
: (0, hex_js_1.isHex)(value)
? (0, toBigInt_js_1.hexToBigInt)(value.toString())
: (0, bn_js_1.isBn)(value)
? (0, x_bigint_1.BigInt)(value.toString())
: (0, toBigInt_js_2.isToBigInt)(value)
? value.toBigInt()
: (0, toBn_js_1.isToBn)(value)
? (0, x_bigint_1.BigInt)(value.toBn().toString())
: (0, x_bigint_1.BigInt)(value);
}
-7
View File
@@ -1,7 +0,0 @@
import type { BN } from '../bn/bn.js';
import type { HexString, NumberOptions, ToBigInt, ToBn } from '../types.js';
/**
* @name nToHex
* @summary Creates a hex value from a bigint object.
*/
export declare function nToHex<ExtToBn extends ToBn | ToBigInt>(value?: ExtToBn | BN | bigint | number | null, { bitLength, isLe, isNegative }?: NumberOptions): HexString;
-12
View File
@@ -1,12 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nToHex = nToHex;
const index_js_1 = require("../u8a/index.js");
const toU8a_js_1 = require("./toU8a.js");
/**
* @name nToHex
* @summary Creates a hex value from a bigint object.
*/
function nToHex(value, { bitLength = -1, isLe = false, isNegative = false } = {}) {
return (0, index_js_1.u8aToHex)((0, toU8a_js_1.nToU8a)(value || 0, { bitLength, isLe, isNegative }));
}
-7
View File
@@ -1,7 +0,0 @@
import type { BN } from '../bn/bn.js';
import type { NumberOptions, ToBigInt, ToBn } from '../types.js';
/**
* @name nToU8a
* @summary Creates a Uint8Array object from a bigint.
*/
export declare function nToU8a<ExtToBn extends ToBn | ToBigInt>(value?: ExtToBn | BN | bigint | number | null, { bitLength, isLe, isNegative }?: NumberOptions): Uint8Array;
-52
View File
@@ -1,52 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nToU8a = nToU8a;
const x_bigint_1 = require("@pezkuwi/x-bigint");
const consts_js_1 = require("./consts.js");
const toBigInt_js_1 = require("./toBigInt.js");
const DIV = (0, x_bigint_1.BigInt)(256);
const NEG_MASK = (0, x_bigint_1.BigInt)(0xff);
function toU8a(value, isLe, isNegative) {
const arr = [];
const withSigned = isNegative && (value < consts_js_1._0n);
if (withSigned) {
value = (value + consts_js_1._1n) * -consts_js_1._1n;
}
while (value !== consts_js_1._0n) {
const mod = value % DIV;
const val = Number(withSigned
? mod ^ NEG_MASK
: mod);
if (isLe) {
arr.push(val);
}
else {
arr.unshift(val);
}
value = (value - mod) / DIV;
}
return Uint8Array.from(arr);
}
/**
* @name nToU8a
* @summary Creates a Uint8Array object from a bigint.
*/
function nToU8a(value, { bitLength = -1, isLe = true, isNegative = false } = {}) {
const valueBi = (0, toBigInt_js_1.nToBigInt)(value);
if (valueBi === consts_js_1._0n) {
return bitLength === -1
? new Uint8Array(1)
: new Uint8Array(Math.ceil((bitLength || 0) / 8));
}
const u8a = toU8a(valueBi, isLe, isNegative);
if (bitLength === -1) {
return u8a;
}
const byteLength = Math.ceil((bitLength || 0) / 8);
const output = new Uint8Array(byteLength);
if (isNegative) {
output.fill(0xff);
}
output.set(u8a, isLe ? 0 : byteLength - u8a.length);
return output;
}
-2
View File
@@ -1,2 +0,0 @@
import BN from 'bn.js';
export { BN };
-6
View File
@@ -1,6 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BN = void 0;
const tslib_1 = require("tslib");
const bn_js_1 = tslib_1.__importDefault(require("bn.js"));
exports.BN = bn_js_1.default;
-91
View File
@@ -1,91 +0,0 @@
import { BN } from './bn.js';
/**
* @name BN_ZERO
* @summary BN constant for 0.
*/
export declare const BN_ZERO: BN;
/**
* @name BN_ONE
* @summary BN constant for 1.
*/
export declare const BN_ONE: BN;
/**
* @name BN_TWO
* @summary BN constant for 2.
*/
export declare const BN_TWO: BN;
/**
* @name BN_THREE
* @summary BN constant for 3.
*/
export declare const BN_THREE: BN;
/**
* @name BN_FOUR
* @summary BN constant for 4.
*/
export declare const BN_FOUR: BN;
/**
* @name BN_FIVE
* @summary BN constant for 5.
*/
export declare const BN_FIVE: BN;
/**
* @name BN_SIX
* @summary BN constant for 6.
*/
export declare const BN_SIX: BN;
/**
* @name BN_SEVEN
* @summary BN constant for 7.
*/
export declare const BN_SEVEN: BN;
/**
* @name BN_EIGHT
* @summary BN constant for 8.
*/
export declare const BN_EIGHT: BN;
/**
* @name BN_NINE
* @summary BN constant for 9.
*/
export declare const BN_NINE: BN;
/**
* @name BN_TEN
* @summary BN constant for 10.
*/
export declare const BN_TEN: BN;
/**
* @name BN_HUNDRED
* @summary BN constant for 100.
*/
export declare const BN_HUNDRED: BN;
/**
* @name BN_THOUSAND
* @summary BN constant for 1,000.
*/
export declare const BN_THOUSAND: BN;
/**
* @name BN_MILLION
* @summary BN constant for 1,000,000.
*/
export declare const BN_MILLION: BN;
/**
* @name BN_BILLION
* @summary BN constant for 1,000,000,000.
*/
export declare const BN_BILLION: BN;
/**
* @name BN_QUINTILL
* @summary BN constant for 1,000,000,000,000,000,000.
*/
export declare const BN_QUINTILL: BN;
/**
* @name BN_MAX_INTEGER
* @summary BN constant for MAX_SAFE_INTEGER
*/
export declare const BN_MAX_INTEGER: BN;
/**
* @name BN_SQRT_MAX_INTEGER
* @summary BN constant for Math.sqrt(MAX_SAFE_INTEGER)
*/
export declare const BN_SQRT_MAX_INTEGER: BN;
-94
View File
@@ -1,94 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BN_SQRT_MAX_INTEGER = exports.BN_MAX_INTEGER = exports.BN_QUINTILL = exports.BN_BILLION = exports.BN_MILLION = exports.BN_THOUSAND = exports.BN_HUNDRED = exports.BN_TEN = exports.BN_NINE = exports.BN_EIGHT = exports.BN_SEVEN = exports.BN_SIX = exports.BN_FIVE = exports.BN_FOUR = exports.BN_THREE = exports.BN_TWO = exports.BN_ONE = exports.BN_ZERO = void 0;
const bn_js_1 = require("./bn.js");
/**
* @name BN_ZERO
* @summary BN constant for 0.
*/
exports.BN_ZERO = new bn_js_1.BN(0);
/**
* @name BN_ONE
* @summary BN constant for 1.
*/
exports.BN_ONE = new bn_js_1.BN(1);
/**
* @name BN_TWO
* @summary BN constant for 2.
*/
exports.BN_TWO = new bn_js_1.BN(2);
/**
* @name BN_THREE
* @summary BN constant for 3.
*/
exports.BN_THREE = new bn_js_1.BN(3);
/**
* @name BN_FOUR
* @summary BN constant for 4.
*/
exports.BN_FOUR = new bn_js_1.BN(4);
/**
* @name BN_FIVE
* @summary BN constant for 5.
*/
exports.BN_FIVE = new bn_js_1.BN(5);
/**
* @name BN_SIX
* @summary BN constant for 6.
*/
exports.BN_SIX = new bn_js_1.BN(6);
/**
* @name BN_SEVEN
* @summary BN constant for 7.
*/
exports.BN_SEVEN = new bn_js_1.BN(7);
/**
* @name BN_EIGHT
* @summary BN constant for 8.
*/
exports.BN_EIGHT = new bn_js_1.BN(8);
/**
* @name BN_NINE
* @summary BN constant for 9.
*/
exports.BN_NINE = new bn_js_1.BN(9);
/**
* @name BN_TEN
* @summary BN constant for 10.
*/
exports.BN_TEN = new bn_js_1.BN(10);
/**
* @name BN_HUNDRED
* @summary BN constant for 100.
*/
exports.BN_HUNDRED = new bn_js_1.BN(100);
/**
* @name BN_THOUSAND
* @summary BN constant for 1,000.
*/
exports.BN_THOUSAND = new bn_js_1.BN(1_000);
/**
* @name BN_MILLION
* @summary BN constant for 1,000,000.
*/
exports.BN_MILLION = new bn_js_1.BN(1_000_000);
/**
* @name BN_BILLION
* @summary BN constant for 1,000,000,000.
*/
exports.BN_BILLION = new bn_js_1.BN(1_000_000_000);
/**
* @name BN_QUINTILL
* @summary BN constant for 1,000,000,000,000,000,000.
*/
exports.BN_QUINTILL = exports.BN_BILLION.mul(exports.BN_BILLION);
/**
* @name BN_MAX_INTEGER
* @summary BN constant for MAX_SAFE_INTEGER
*/
exports.BN_MAX_INTEGER = new bn_js_1.BN(Number.MAX_SAFE_INTEGER);
/**
* @name BN_SQRT_MAX_INTEGER
* @summary BN constant for Math.sqrt(MAX_SAFE_INTEGER)
*/
exports.BN_SQRT_MAX_INTEGER = new bn_js_1.BN(94906265);
-1
View File
@@ -1 +0,0 @@
export { hexToBn as bnFromHex } from '../hex/toBn.js';
-5
View File
@@ -1,5 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bnFromHex = void 0;
var toBn_js_1 = require("../hex/toBn.js");
Object.defineProperty(exports, "bnFromHex", { enumerable: true, get: function () { return toBn_js_1.hexToBn; } });
Loaded 100 of 1498 files, more files were not shown because too many files have changed in this diff. Show more