@numio/bigmath 2.1.3 → 2.2.1

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,13 @@
1
+ ### 2.2.1
2
+ Add Number format validation examples (README.md)
3
+
4
+ ### 2.2.0
5
+ Added `isHex(str: string): boolean` - Checks if a string is a valid hexadecimal number (prefixed with `0x` or `-0x`).
6
+ Added `isBinary(str: string): boolean` - Checks if a string is a valid binary number (prefixed with `0b` or `-0b`).
7
+ Added `isDecimal(str: string): boolean` - Checks if a string is a valid decimal number.
8
+ Added `isOctal(str: string): boolean` - Checks if a string is a valid octal number (prefixed with `0o` or `-0o`).
9
+ 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).
10
+
1
11
  ### 2.1.3
2
12
  Optimize performance for small numbers
3
13
 
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
 
@@ -370,6 +377,40 @@ toBase({ value: "0b1101", toBase: 16 }) // d
370
377
  toBase({ value: "0o11", toBase: 10 }) // 9
371
378
  ```
372
379
 
380
+ ### Number format validation
381
+
382
+ ```javascript
383
+ import { isHex, isBinary, isDecimal, isOctal, isNumber } from "@numio/bigmath";
384
+
385
+ console.log(isHex("0x1A")); // true
386
+ console.log(isHex("1A")); // false (no 0x prefix)
387
+ console.log(isHex("-0x2f")); // true
388
+ console.log(isHex("0xG")); // false (invalid hex digit)
389
+
390
+ console.log(isBinary("0b101")); // true
391
+ console.log(isBinary("101")); // false (no 0b prefix)
392
+ console.log(isBinary("-0b11")); // true
393
+ console.log(isBinary("0b12")); // false (invalid binary digit)
394
+
395
+ console.log(isDecimal("123")); // true
396
+ console.log(isDecimal("123.45"));// true
397
+ console.log(isDecimal("-0.5")); // true
398
+ console.log(isDecimal(".5")); // false (leading dot)
399
+ console.log(isDecimal("10.")); // false (trailing dot)
400
+
401
+ console.log(isOctal("0o77")); // true
402
+ console.log(isOctal("77")); // false (no 0o prefix)
403
+ console.log(isOctal("-0o12")); // true
404
+ console.log(isOctal("0o19")); // false (invalid octal digit)
405
+
406
+ console.log(isNumber("0x1A")); // true (hex)
407
+ console.log(isNumber("0b101")); // true (binary)
408
+ console.log(isNumber("123.45"));// true (decimal)
409
+ console.log(isNumber("0o77")); // true (octal)
410
+ console.log(isNumber("123")); // true (decimal)
411
+ console.log(isNumber("abc")); // false (not a valid number)
412
+ ```
413
+
373
414
  Does not have a limitation on the number of digits. You can use any length you'd
374
415
  like
375
416
 
@@ -392,4 +433,6 @@ Download from JSR - https://jsr.io/@numio/bigmath
392
433
 
393
434
  Home page - https://github.com/shpunter/numio-bigmath/blob/main/README.md
394
435
 
436
+ Change log - https://github.com/shpunter/numio-bigmath/blob/main/CHANGELOG.md
437
+
395
438
  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.1",
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;