@numio/bigmath 2.2.0 → 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 +3 -0
- package/README.md +34 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
### 2.2.1
|
2
|
+
Add Number format validation examples (README.md)
|
3
|
+
|
1
4
|
### 2.2.0
|
2
5
|
Added `isHex(str: string): boolean` - Checks if a string is a valid hexadecimal number (prefixed with `0x` or `-0x`).
|
3
6
|
Added `isBinary(str: string): boolean` - Checks if a string is a valid binary number (prefixed with `0b` or `-0b`).
|
package/README.md
CHANGED
@@ -377,6 +377,40 @@ toBase({ value: "0b1101", toBase: 16 }) // d
|
|
377
377
|
toBase({ value: "0o11", toBase: 10 }) // 9
|
378
378
|
```
|
379
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
|
+
|
380
414
|
Does not have a limitation on the number of digits. You can use any length you'd
|
381
415
|
like
|
382
416
|
|
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.2.
|
4
|
+
"version": "2.2.1",
|
5
5
|
"keywords": [
|
6
6
|
"precision",
|
7
7
|
"arithmetic",
|