ts-prims
Version:
Typescript Primitives
39 lines • 1.55 kB
JavaScript
import { widthConstraint } from './width.js';
import { Prim } from './prim.js';
import { isInteger } from './varint.js';
/**
* Returns a constructor for `big` integer numbers with the given Width `W`.
*
* `big` numbers are always backed by `bigint` values, which is less performant
* than `number`, so for small `W`, prefer `int` instead. If you need a type
* that uses either `number` or `bigint` depending on the width, use `varint`.
*
* @template W The `Width`, inferred from parameter `w`.
*
* @param w The width of this type
* @returns The constructor for `big<W>`
*
* @see {@link big} For the prim type
* @see {@link Width} The widths of the big int types
* @see {@link isInteger} constraint that values must be integer
* @see {@link widthConstraint} constraint that values must be within width `W`
* @see {@link varint} for the low-level type that accepts all widths
*/
export const Big = (w) => Prim(`big<${w}>`, BigInt, [isInteger, widthConstraint(w)]);
/** Constructor for {@link big64} */
export const Big64 = Big(8);
/** Constructor for {@link big96} */
export const Big96 = Big(9);
/** Constructor for {@link big128} */
export const Big128 = Big(10);
/** Constructor for {@link big160} */
export const Big160 = Big(11);
/** Constructor for {@link big192} */
export const Big192 = Big(12);
/** Constructor for {@link big256} */
export const Big256 = Big(13);
/** Constructor for {@link big512} */
export const Big512 = Big(14);
/** Constructor for {@link big4K} */
export const Big4K = Big(15);
//# sourceMappingURL=big.js.map