@numio/bigmath 2.1.3 → 2.2.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 2.2.0
2
+ Added `isHex(str: string): boolean` - Checks if a string is a valid hexadecimal number (prefixed with `0x` or `-0x`).
3
+ Added `isBinary(str: string): boolean` - Checks if a string is a valid binary number (prefixed with `0b` or `-0b`).
4
+ Added `isDecimal(str: string): boolean` - Checks if a string is a valid decimal number.
5
+ Added `isOctal(str: string): boolean` - Checks if a string is a valid octal number (prefixed with `0o` or `-0o`).
6
+ Added `isNumber(str: string): boolean` - Checks if a string is a valid number in any of the formats supported by the library (decimal, hexadecimal, binary, octal).
7
+
1
8
  ### 2.1.3
2
9
  Optimize performance for small numbers
3
10
 
package/README.md CHANGED
@@ -12,6 +12,8 @@
12
12
  * **Eliminate Precision Loss:** Achieve accurate results even with numeric literals exceeding 15 significant digits, ensuring the integrity of your calculations.
13
13
  * **Precise Decimal Operations:** Execute addition, subtraction, multiplication, and division on decimal numbers with guaranteed accuracy, including scenarios with negative values.
14
14
  * ****NEW! Multi-Base Number Support:** Seamlessly perform arithmetic operations involving **hexadecimal (HEX), octal, binary, and decimal numbers**, offering unparalleled flexibility in handling various number formats.
15
+ * ****NEW! Number Format Validation:** Easily validate if a string represents a valid **hexadecimal (`isHex`)**, **binary (`isBinary`)**, **decimal (`isDecimal`)**, **octal (`isOctal`)**, or any valid **number (`isNumber`)** format supported by the library.
16
+
15
17
 
16
18
 
17
19
  **Unlock Advanced Numerical Operations:**
@@ -54,8 +56,13 @@ With `@numio/bigmath`, you can confidently perform complex arithmetic operations
54
56
 
55
57
  ### Latest update
56
58
 
57
- The performance was improved. Adding, subtracting, dividing, and multiplying are now **2** to **5** times faster than before.\
58
- Adding, subtracting, dividing, and multiplying support operations on HEX, octal, binary, and decimal numbers. Mixed-type calculations are allowed, with the final result converted to decimal.
59
+ **New Functions added:**
60
+
61
+ * `isHex` - Checks if a string is a valid hexadecimal number (prefixed with `0x` or `-0x`).
62
+ * `isBinary` - Checks if a string is a valid binary number (prefixed with `0b` or `-0b`).
63
+ * `isDecimal` - Checks if a string is a valid decimal number.
64
+ * `isOctal` - Checks if a string is a valid octal number (prefixed with `0o` or `-0o`).
65
+ * `isNumber` - Checks if a string is a valid number in any of the formats supported by the library (decimal, hexadecimal, binary, octal).
59
66
 
60
67
  # Install:
61
68
 
@@ -392,4 +399,6 @@ Download from JSR - https://jsr.io/@numio/bigmath
392
399
 
393
400
  Home page - https://github.com/shpunter/numio-bigmath/blob/main/README.md
394
401
 
402
+ Change log - https://github.com/shpunter/numio-bigmath/blob/main/CHANGELOG.md
403
+
395
404
  License - https://github.com/shpunter/numio-bigmath/blob/main/LICENSE
package/index.d.ts CHANGED
@@ -18,4 +18,9 @@ import { sqrt } from "./src/sqrt/sqrt.d.ts";
18
18
  import { cbrt } from "./src/cbrt/cbrt.d.ts";
19
19
  import { abs } from "./src/abs/abs.d.ts";
20
20
  import { toBase } from "./src/toBase/toBase.d.ts";
21
- export { abs, add, cbrt, div, IQR, isEqual, isLeftGreater, isLeftGreaterOrEqual, MAD, max, mean, min, mul, Pipe, quartile, round, sort, sqrt, sub, toBase, };
21
+ import { isHex } from "./src/isValid/isHex.d.ts";
22
+ import { isBinary } from "./src/isValid/isBinary.d.ts";
23
+ import { isDecimal } from "./src/isValid/isDecimal.d.ts";
24
+ import { isOctal } from "./src/isValid/isOctal.d.ts";
25
+ import { isNumber } from "./src/isValid/isNumber.d.ts";
26
+ export { abs, add, cbrt, div, IQR, isEqual, isLeftGreater, isLeftGreaterOrEqual, MAD, max, mean, min, mul, Pipe, quartile, round, sort, sqrt, sub, toBase, isHex, isBinary, isDecimal, isOctal, isNumber };
package/index.js CHANGED
@@ -18,4 +18,9 @@ import { sqrt } from "./src/sqrt/sqrt.js";
18
18
  import { cbrt } from "./src/cbrt/cbrt.js";
19
19
  import { abs } from "./src/abs/abs.js";
20
20
  import { toBase } from "./src/toBase/toBase.js";
21
- export { abs, add, cbrt, div, IQR, isEqual, isLeftGreater, isLeftGreaterOrEqual, MAD, max, mean, min, mul, Pipe, quartile, round, sort, sqrt, sub, toBase, };
21
+ import { isHex } from "./src/isValid/isHex.js";
22
+ import { isBinary } from "./src/isValid/isBinary.js";
23
+ import { isDecimal } from "./src/isValid/isDecimal.js";
24
+ import { isOctal } from "./src/isValid/isOctal.js";
25
+ import { isNumber } from "./src/isValid/isNumber.js";
26
+ export { abs, add, cbrt, div, IQR, isEqual, isLeftGreater, isLeftGreaterOrEqual, MAD, max, mean, min, mul, Pipe, quartile, round, sort, sqrt, sub, toBase, isHex, isBinary, isDecimal, isOctal, isNumber };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@numio/bigmath",
3
3
  "description": "@numio/bigmath is an arbitrary-precision arithmetic library. It can be used for basic operations with decimal numbers (integers and float)",
4
- "version": "2.1.3",
4
+ "version": "2.2.0",
5
5
  "keywords": [
6
6
  "precision",
7
7
  "arithmetic",
@@ -0,0 +1,2 @@
1
+ import type { IsValid } from "./types.d.ts";
2
+ export declare const isBinary: IsValid;
@@ -0,0 +1,3 @@
1
+ export const isBinary = (str) => {
2
+ return /^-?(0b)[01]+$/i.test(str);
3
+ };
@@ -0,0 +1,2 @@
1
+ import type { IsValid } from "./types.d.ts";
2
+ export declare const isDecimal: IsValid;
@@ -0,0 +1,3 @@
1
+ export const isDecimal = (str) => {
2
+ return /^-?(?![\.])\d+(\.\d+)?$/.test(str);
3
+ };
@@ -0,0 +1,2 @@
1
+ import type { IsValid } from "./types.d.ts";
2
+ export declare const isHex: IsValid;
@@ -0,0 +1,3 @@
1
+ export const isHex = (str) => {
2
+ return /^-?(0x)[0-9a-fA-F]+$/i.test(str);
3
+ };
@@ -0,0 +1,2 @@
1
+ import type { IsValid } from "./types.d.ts";
2
+ export declare const isNumber: IsValid;
@@ -0,0 +1,7 @@
1
+ import { isBinary } from "./isBinary.js";
2
+ import { isDecimal } from "./isDecimal.js";
3
+ import { isHex } from "./isHex.js";
4
+ import { isOctal } from "./isOctal.js";
5
+ export const isNumber = (str) => {
6
+ return isBinary(str) || isHex(str) || isOctal(str) || isDecimal(str);
7
+ };
@@ -0,0 +1,2 @@
1
+ import type { IsValid } from "./types.d.ts";
2
+ export declare const isOctal: IsValid;
@@ -0,0 +1,3 @@
1
+ export const isOctal = (str) => {
2
+ return /^-?(0o)[0-7]+$/i.test(str);
3
+ };
@@ -0,0 +1 @@
1
+ export type IsValid = (str: string) => boolean;