big.esm 1.3.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,17 @@
1
- import type { Big } from "../big";
1
+ import { Big } from '../big';
2
2
  /**
3
3
  * Returns the minimum of two Big numbers.
4
4
  *
5
5
  * @param {Big} a - The first Big number.
6
6
  * @param {Big} b - The second Big number.
7
- * @param {boolean} [mutable=false] - Whether to return same Big instance. Defaults to false.
8
7
  *
9
- * @returns {Big} - The minimum of the two Big numbers. If the two Big numbers are equal, the first Big number is returned.
8
+ * @returns {Big} - Returns either `a` or `b`. If the two numbers are equal, `a` is returned.
10
9
  *
11
10
  * @category Operations
12
11
  *
13
12
  * @example
14
- * minBig(new Big(1), new Big(2)); // new Big instance with value 1 (first Big number)
15
- * minBig(new Big(2), new Big(1)); // new Big instance with value 1 (second Big number)
16
- * minBig(new Big(1), new Big(1)); // new Big instance with value 1 (first Big number)
17
- * minBig(new Big(1), new Big(1), true); // first Big number with value 1 and same instance
13
+ * minBig(new Big(1), new Big(2)); // returns the first Big number
14
+ * minBig(new Big(2), new Big(1)); // returns the second Big number
15
+ * minBig(new Big(1), new Big(1)); // returns the first Big number
18
16
  */
19
- export declare const minBig: (a: Big, b: Big, mutable?: boolean) => Big;
17
+ export declare function minBig(a: Big, b: Big): Big;
@@ -1,11 +1,10 @@
1
- import type { Big } from "../big";
1
+ import { Big } from '../big';
2
2
  /**
3
3
  * Performs the modulo operation (remainder of division) for two Big instances.
4
4
  *
5
5
  * @param dividend The Big instance representing the dividend.
6
6
  * @param divisor The Big instance representing the divisor.
7
- * @param {boolean} [mutable=false] - Whether to mutate the first Big instance. Defaults to false.
8
- * @returns A new Big instance representing the remainder of the division.
7
+ * @returns The mutated dividend instance representing the remainder of the division.
9
8
  * @throws {Error} Division by zero is not allowed.
10
9
  *
11
10
  * @category Operations
@@ -17,4 +16,4 @@ import type { Big } from "../big";
17
16
  * console.log(modBig(big2, big1).toString()); // "3"
18
17
  * console.log(modBig(big1, big1).toString()); // "0"
19
18
  */
20
- export declare function modBig(dividend: Big, divisor: Big, mutable?: boolean): Big;
19
+ export declare function modBig(dividend: Big, divisor: Big): Big;
@@ -1,17 +1,5 @@
1
- import type { Big } from "../big";
1
+ import { Big } from '../big';
2
2
  /**
3
- * Multiplies two Big instances and returns the result as a new Big instance.
4
- *
5
- * @param {Big} a - The first Big instance.
6
- * @param {Big} b - The second Big instance.
7
- * @param {boolean} [mutable=false] - Whether to mutate the first Big instance. Defaults to false.
8
- * @returns {Big} The result of the multiplication.
9
- *
10
- * @category Operations
11
- *
12
- * @example
13
- * mulBig(new Big(1), new Big(2)); // new Big instance with value 2
14
- * mulBig(new Big(1.1), new Big(2.2)); // new Big instance with value 2.42
15
- * mulBig(new Big(1.1), new Big(2)); // new Big instance with value 2.2
3
+ * Multiplies two Big instances and mutates the first one.
16
4
  */
17
- export declare function mulBig(a: Big, b: Big, mutable?: boolean): Big;
5
+ export declare function mulBig(a: Big, b: Big): Big;
@@ -1,20 +1,5 @@
1
- import type { Big } from "../big";
1
+ import { Big } from '../big';
2
2
  /**
3
- * Raises a Big number to the power of another Big number.
4
- *
5
- * @param {Big} big - The base Big number.
6
- * @param {number} exp - The exponent (non-negative integer). Defaults to 2.
7
- * @param {boolean} [mutable=false] - Whether to mutate the first Big instance. Defaults to false.
8
- * @returns {Big} - The result of a raised to the power of b.
9
- * @throws {Error} - If the exponent is not a non-negative integer.
10
- *
11
- * @category Operations
12
- *
13
- * @example
14
- * powBig(new Big(2), 0); // new Big instance with value 1
15
- * powBig(new Big(2), 1); // new Big instance with value 2
16
- * powBig(new Big(2), 3); // new Big instance with value 8
17
- * powBig(new Big(2), 3.3); // throws Error
18
- * powBig(new Big(2), -3); // throws Error
3
+ * Raises a Big number to the power and mutates the base instance.
19
4
  */
20
- export declare function powBig(big: Big, exp?: number, mutable?: boolean): Big;
5
+ export declare function powBig(big: Big, exp?: number): Big;
@@ -1,28 +1,7 @@
1
- import type { Big } from "../big";
1
+ import { Big } from '../big';
2
2
  /**
3
- * Calculates the nth root of a Big instance with custom precision and rounding mode.
4
- *
5
- * Note: it's the most weighted function in the library. It's reusing a lot of other functions, and it's not perfect in performance, recommended to use it only when you need it and with default precision and rounding mode. It uses the Newton's method to calculate the root.
6
- *
7
- * @param {Big} big - The Big instance.
8
- * @param {number} root - The root to calculate. Must be an integer. Defaults to 2.
9
- * @param {number} precision - The number of decimal places to keep in the result (optional). Defaults to 20.
10
- * @param {boolean} [mutable=false] - Whether to mutate the first Big instance. Defaults to false.
11
- * @returns {Big} The nth root of the Big instance with the specified precision and rounding mode.
12
- * @throws {Error} - If the root is not an integer.
3
+ * Calculates the nth root of a Big instance and mutates it with the result.
13
4
  *
14
5
  * @category Operations
15
- *
16
- * @example
17
- * const big1 = new Big(16);
18
- * console.log(sqrtBig(big1).toString()); // 4.00000000000000000000
19
- * console.log(sqrtBig(big1, 4, 0).toString()); // 2
20
- * console.log(sqrtBig(big1, 4, 1).toString()); // 2.0
21
- * console.log(sqrtBig(Big(0), 4).toString()); // 0
22
- * console.log(sqrtBig(Big(1), 4).toString()); // 1
23
- * console.log(sqrtBig(Big(-1), 4).toString()); // throws Error
24
- * console.log(sqrtBig(Big(16), 0.5).toString()); // throws Error
25
- * console.log(sqrtBig(Big(16), -2).toString()); // throws Error
26
- * console.log(sqrtBig(Big(16), 4, -1).toString()); // throws Error
27
6
  */
28
- export declare function sqrtBig(big: Big, root?: number, precision?: number, mutable?: boolean): Big;
7
+ export declare function sqrtBig(big: Big, root?: number, precision?: number): Big;
@@ -1,16 +1,5 @@
1
- import type { Big } from "../big";
1
+ import { Big } from '../big';
2
2
  /**
3
- * Subtracts two big values and returns the result as a new Big instance.
4
- *
5
- * @param {Big} a - The first Big instance.
6
- * @param {Big} b - The second Big instance.
7
- * @param {boolean} [mutable=false] - Whether to mutate the first Big instance. Defaults to false.
8
- * @returns {Big} The result of the subtraction.
9
- *
10
- * @category Operations
11
- *
12
- * @example
13
- * subBig(new Big(1), new Big(2)); // new Big instance with value -1
14
- * subBig(new Big(1.1), new Big(2.2)); // new Big instance with value -1.1
3
+ * Subtracts two Big instances and mutates the first one.
15
4
  */
16
- export declare function subBig(a: Big, b: Big, mutable?: boolean): Big;
5
+ export declare function subBig(a: Big, b: Big): Big;
@@ -0,0 +1,42 @@
1
+ import { Big } from './big';
2
+ import { BigValue, RoundingMode } from './types';
3
+ export type BigPipeline = {
4
+ /**
5
+ * The current Big value inside the pipeline.
6
+ */
7
+ readonly current: Big;
8
+ add: (value: BigValue) => BigPipeline;
9
+ sub: (value: BigValue) => BigPipeline;
10
+ mul: (value: BigValue) => BigPipeline;
11
+ div: (value: BigValue, precision?: number, roundingMode?: RoundingMode) => BigPipeline;
12
+ mod: (value: BigValue) => BigPipeline;
13
+ pow: (exp?: number) => BigPipeline;
14
+ sqrt: (root?: number, precision?: number) => BigPipeline;
15
+ /**
16
+ * Returns the current Big value. Alias to avoid accessing the getter directly.
17
+ */
18
+ value: () => Big;
19
+ /**
20
+ * String representation of the current value.
21
+ */
22
+ toString: (trimZeros?: boolean) => string;
23
+ };
24
+ export declare class BigPipe implements BigPipeline {
25
+ current: Big;
26
+ constructor(initial: BigValue);
27
+ add(value: BigValue): this;
28
+ sub(value: BigValue): this;
29
+ mul(value: BigValue): this;
30
+ div(value: BigValue, precision?: number, roundingMode?: RoundingMode): this;
31
+ mod(value: BigValue): this;
32
+ pow(exp?: number): this;
33
+ sqrt(root?: number, precision?: number): this;
34
+ value(): Big;
35
+ toString(trimZeros?: boolean): string;
36
+ }
37
+ /**
38
+ * Creates a pipeline for chaining Big operations.
39
+ * The pipeline owns and mutates its `Big` instance in-place.
40
+ * Passing an existing `Big` will mutate that instance.
41
+ */
42
+ export declare function pipeBig(initial: BigValue): BigPipeline;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Big } from "./big";
1
+ import { Big } from './big';
2
2
  /**
3
3
  * The object type for the Big class.
4
4
  *
@@ -1,15 +1,12 @@
1
- import type { Big } from "../big";
1
+ import { Big } from '../big';
2
2
  /**
3
3
  * Aligns the scale(decimal places) of two Big instances before performing arithmetic operations.
4
- * It takes two Big instances as input and returns a tuple (array) of two new Big instances with the same scale.
4
+ * It takes two Big instances as input and mutates the one with the smaller scale to match the other.
5
5
  *
6
6
  * When the scales of the two input instances are different, the function adjusts the value and scale of one of the instances so that their scales are equal, allowing the arithmetic operations to be performed correctly.
7
7
  *
8
- * Note: This function does not modify the input instances. It creates new instances with the aligned scales.
9
- *
10
8
  * @param {Big} a - The first Big instance.
11
9
  * @param {Big} b - The second Big instance.
12
- * @param {boolean} [mutable=false] - Whether to mutate the both Big instances. Defaults to false.
13
10
  * @returns {[Big, Big]} A tuple of two Big instances with the same scale.
14
11
  *
15
12
  * @category Utilities
@@ -21,4 +18,4 @@ import type { Big } from "../big";
21
18
  * console.log(x.toString()); // "123.456000"
22
19
  * console.log(y.toString()); // "123.456789"
23
20
  */
24
- export declare function alignScale(a: Big, b: Big, mutable?: boolean): [Big, Big];
21
+ export declare function alignScale(a: Big, b: Big): [Big, Big];
@@ -1,4 +1,4 @@
1
- import { Big } from "../big";
1
+ import { Big } from '../big';
2
2
  /**
3
3
  * Clone a Big instance
4
4
  * @param {Big} big - The Big instance to clone.
@@ -9,17 +9,17 @@ export declare const DEFAULT_PRECISION = 20;
9
9
  *
10
10
  * @category Constants
11
11
  */
12
- export declare const ZERO_BIGINT: bigint;
12
+ export declare const ZERO_BIGINT = 0n;
13
13
  /**
14
14
  * One as a BigInt.
15
15
  *
16
16
  * @category Constants
17
17
  */
18
- export declare const ONE_BIGINT: bigint;
18
+ export declare const ONE_BIGINT = 1n;
19
19
  /**
20
20
  * Ten as a BigInt.
21
21
  * Often used as scale multiplier to adjust the scale of a Big instance.
22
22
  *
23
23
  * @category Constants
24
24
  */
25
- export declare const TEN_BIGINT: bigint;
25
+ export declare const TEN_BIGINT = 10n;
@@ -1,5 +1,5 @@
1
- import { Big } from "../big";
2
- import type { BigObject, PossibleNumber } from "../types";
1
+ import { Big } from '../big';
2
+ import { BigObject, BigValue, PossibleNumber } from '../types';
3
3
  /**
4
4
  * Creates a new Big instance from the given value.
5
5
  * If the value is already a Big instance, it returns the value itself.
@@ -35,3 +35,7 @@ export declare function createBig(value: PossibleNumber): Big;
35
35
  * const big3 = createBig(123.456, 2); // 1.23, because the scale is 2 and it removes the fractional part
36
36
  */
37
37
  export declare function createBig(value: PossibleNumber, scale: number | string | undefined): Big;
38
+ /**
39
+ * Overload accepting the full BigValue union. Useful for helpers that accept any supported input.
40
+ */
41
+ export declare function createBig(value: BigValue, scale?: number | string | undefined): Big;
@@ -1,11 +1,11 @@
1
- import { Big } from "../big";
2
- import { BigObject } from "../types";
1
+ import { Big } from '../big';
2
+ import { BigObject } from '../types';
3
3
  /**
4
4
  * Convert a number or string to normal string number. Supports scientific notation.
5
5
  *
6
6
  * @param {string | number} num - The number to convert
7
7
  * @param {boolean} [ignoreFraction=false] - Whether to ignore the fractional part of the number. Defaults to false.
8
- * @param {boolean} [returnInstance=false] - Whether to return a Big instance or BigObject. Defaults to true.
8
+ * @param {boolean} [returnInstance=true] - Whether to return a Big instance or BigObject. Defaults to true.
9
9
  *
10
10
  * @return {Big | BigObject} - A Big instance or BigObject representing the number
11
11
  * @throws {Error} - If the number is too big or too small
@@ -1,5 +1,4 @@
1
- import type { BigObject } from "../types";
2
- import type { Big } from "../big";
1
+ import { BigObject } from '../types';
3
2
  /**
4
3
  * Determines if the value is a BigObject. A BigObject is an object with a value property of type bigint and a scale property of type number. It usually represents a Big instance.
5
4
  *
@@ -17,4 +16,4 @@ import type { Big } from "../big";
17
16
  * isBigObject(123456n); // false
18
17
  * isBigObject({ value: "abc", scale: "2"}); // false
19
18
  */
20
- export declare function isBigObject(value: Big | BigObject | unknown): value is BigObject;
19
+ export declare function isBigObject(value: unknown): value is BigObject;
@@ -1,4 +1,4 @@
1
- import type { Big } from "../big";
1
+ import { Big } from '../big';
2
2
  /**
3
3
  * Checks if a Big instance is zero.
4
4
  *
@@ -0,0 +1 @@
1
+ export declare function pow10(exp: number): bigint;
package/package.json CHANGED
@@ -1,22 +1,23 @@
1
1
  {
2
2
  "name": "big.esm",
3
- "version": "1.3.1",
3
+ "version": "2.0.0",
4
4
  "description": "A small, fast JavaScript library for arbitrary-precision decimal arithmetic.",
5
5
  "type": "module",
6
6
  "scripts": {
7
- "dev": "vite",
8
- "build": "tsc && vite build",
9
- "preview": "vite preview",
10
- "test": "vitest",
11
- "test:ui": "vitest --ui",
12
- "test:run": "vitest run",
13
- "coverage": "vitest run --coverage",
14
- "docs": "typedoc --out docs",
15
- "lint": "eslint --ext .ts,.js,.json ./src",
16
- "lint:fix": "eslint --fix --ext .ts,.js,.json ./src",
17
- "benchmark": "node --expose-gc ./benchmark.js",
18
- "semantic-release": "semantic-release",
19
- "prepare": "is-ci || husky install"
7
+ "dev": "bunx vite",
8
+ "build": "bunx tsc && bunx vite build",
9
+ "preview": "bunx vite preview",
10
+ "test": "bunx vitest",
11
+ "test:ui": "bunx vitest --ui",
12
+ "test:run": "bunx vitest run",
13
+ "coverage": "bunx vitest run --coverage",
14
+ "docs": "bunx typedoc --out docs",
15
+ "lint": "bunx biome check",
16
+ "lint:fix": "bun run lint -- --write",
17
+ "benchmark": "bun benchmarks/benchmark.js",
18
+ "benchmark:weight": "bun benchmarks/size-compare.js",
19
+ "semantic-release": "bunx semantic-release",
20
+ "prepare": "bunx is-ci || bunx husky"
20
21
  },
21
22
  "main": "dist/big.esm.umd.cjs",
22
23
  "module": "dist/big.esm.js",
@@ -46,37 +47,32 @@
46
47
  "url": "https://github.com/dschewchenko/big.esm/issues"
47
48
  },
48
49
  "homepage": "https://github.com/dschewchenko/big.esm#readme",
50
+ "packageManager": "bun@1.3.1",
49
51
  "engines": {
52
+ "bun": ">=1.0.0",
50
53
  "node": ">=16"
51
54
  },
52
55
  "devDependencies": {
53
- "@commitlint/cli": "^17.6.6",
54
- "@commitlint/config-conventional": "^17.6.6",
56
+ "@biomejs/biome": "2.3.0",
57
+ "@commitlint/cli": "^20.1.0",
58
+ "@commitlint/config-conventional": "^20.0.0",
55
59
  "@semantic-release/changelog": "^6.0.3",
56
60
  "@semantic-release/git": "^10.0.1",
57
- "@types/jest": "^29.5.1",
58
- "@types/node": "^18.15.3",
59
- "@typescript-eslint/eslint-plugin": "^5.59.5",
60
- "@typescript-eslint/parser": "^5.59.5",
61
- "@vitest/coverage-c8": "^0.31.0",
62
- "@vitest/ui": "^0.31.0",
63
- "big.js": "^6.2.1",
64
- "eslint": "^8.40.0",
65
- "eslint-config-prettier": "^8.8.0",
66
- "eslint-plugin-prettier": "^4.2.1",
67
- "husky": "^8.0.3",
68
- "is-ci": "^3.0.1",
69
- "prettier": "^2.8.8",
70
- "rollup-plugin-visualizer": "^5.9.0",
71
- "semantic-release": "^21.0.5",
72
- "ts-jest": "^29.1.0",
73
- "typedoc": "^0.24.8",
74
- "typedoc-plugin-mdn-links": "^3.0.3",
75
- "typedoc-plugin-merge-modules": "^5.0.1",
61
+ "@types/node": "^24.9.1",
62
+ "@vitest/ui": "^4.0.3",
63
+ "@vitest/coverage-v8": "^4.0.3",
64
+ "big.js": "^7.0.1",
65
+ "husky": "^9.1.7",
66
+ "is-ci": "^4.1.0",
67
+ "rollup-plugin-visualizer": "^6.0.5",
68
+ "semantic-release": "^25.0.1",
69
+ "typedoc": "^0.28.14",
70
+ "typedoc-plugin-mdn-links": "^5.0.10",
71
+ "typedoc-plugin-merge-modules": "^7.0.0",
76
72
  "typedoc-plugin-pages": "^1.1.0",
77
- "typescript": "^5.0.4",
78
- "vite": "^4.3.9",
79
- "vite-plugin-dts": "^2.3.0",
80
- "vitest": "^0.31.0"
73
+ "typescript": "^5.9.3",
74
+ "vite": "^7.1.12",
75
+ "vite-plugin-dts": "^4.5.4",
76
+ "vitest": "^4.0.3"
81
77
  }
82
78
  }