@jarenjs/core 0.9.2
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/ARCHITECTURE.md +800 -0
- package/LICENSE +21 -0
- package/README.md +68 -0
- package/dist/types/array.d.ts +28 -0
- package/dist/types/bigint.d.ts +5 -0
- package/dist/types/dates.d.ts +79 -0
- package/dist/types/float.d.ts +32 -0
- package/dist/types/function.d.ts +22 -0
- package/dist/types/index.d.ts +119 -0
- package/dist/types/integer.d.ts +24 -0
- package/dist/types/math/float64.d.ts +121 -0
- package/dist/types/math/index.d.ts +5 -0
- package/dist/types/math/int32.d.ts +41 -0
- package/dist/types/math/vec2f64.d.ts +346 -0
- package/dist/types/math/vec2i32.d.ts +43 -0
- package/dist/types/math/vec3f64.d.ts +61 -0
- package/dist/types/number.d.ts +39 -0
- package/dist/types/object.d.ts +44 -0
- package/dist/types/scan.d.ts +64 -0
- package/dist/types/string.d.ts +65 -0
- package/dist/types/text/base64.d.ts +4 -0
- package/dist/types/text/basic.d.ts +5 -0
- package/dist/types/text/email.d.ts +3 -0
- package/dist/types/text/host.d.ts +14 -0
- package/dist/types/text/i18n.d.ts +13 -0
- package/dist/types/text/identifiers.d.ts +5 -0
- package/dist/types/text/index.d.ts +8 -0
- package/dist/types/text/iregexp.d.ts +36 -0
- package/dist/types/text/misc.d.ts +4 -0
- package/dist/types/text/punycode.d.ts +86 -0
- package/package.json +101 -0
- package/src/array.js +57 -0
- package/src/bigint.js +30 -0
- package/src/dates.js +371 -0
- package/src/float.js +107 -0
- package/src/function.js +56 -0
- package/src/index.js +223 -0
- package/src/integer.js +77 -0
- package/src/math/float64.js +316 -0
- package/src/math/index.js +5 -0
- package/src/math/int32.js +235 -0
- package/src/math/vec2f64.js +706 -0
- package/src/math/vec2i32.js +250 -0
- package/src/math/vec3f64.js +225 -0
- package/src/number.js +63 -0
- package/src/object.js +240 -0
- package/src/scan.js +96 -0
- package/src/string.js +194 -0
- package/src/text/base64.js +54 -0
- package/src/text/basic.js +23 -0
- package/src/text/email.js +61 -0
- package/src/text/host.js +335 -0
- package/src/text/i18n.js +294 -0
- package/src/text/identifiers.js +27 -0
- package/src/text/index.js +11 -0
- package/src/text/iregexp.js +308 -0
- package/src/text/misc.js +19 -0
- package/src/text/punycode.js +407 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Joham
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @jarenjs/core
|
|
2
|
+
|
|
3
|
+
The zero-dependency foundation of [Jaren](https://github.com/jklarenbeek/jarenjs). Everything the validator, the formats package and the forms package are built on lives here — type guards, Unicode-aware string handling, a large text-validation toolbox, number range helpers, and fixed-point and vector math.
|
|
4
|
+
|
|
5
|
+
None of it depends on JSON Schema: every module can be used standalone in any JavaScript project.
|
|
6
|
+
|
|
7
|
+
## Modules
|
|
8
|
+
|
|
9
|
+
| Import | Contents |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `@jarenjs/core` | type guards and getters (`isStringType`, `isObjectClass`, `getIntegerType`, ...) |
|
|
12
|
+
| `@jarenjs/core/array` | array helpers (`isUniqueArray`, `getUniqueArray`, `includesAll`, ...) |
|
|
13
|
+
| `@jarenjs/core/object` | deep equality (`equalsDeep`, JSON-only `equalsJson`), map/set merging |
|
|
14
|
+
| `@jarenjs/core/string` | Unicode string helpers (`countCodePoints`, `compareCodePoints`, ...), cached regex compilation |
|
|
15
|
+
| `@jarenjs/core/scan` | char-code constants and predicates for recursive-descent parsers |
|
|
16
|
+
| `@jarenjs/core/number` | boolean/number/integer coercion helpers (`isIntishType`, ...) |
|
|
17
|
+
| `@jarenjs/core/integer` | `int8` ... `uint64` ranges and validators |
|
|
18
|
+
| `@jarenjs/core/float` | `float16` ... `float64` constants, validators, increment/decrement |
|
|
19
|
+
| `@jarenjs/core/bigint` | bigint helpers (`BigInt_min`, `BigInt_MinMax`, ...) |
|
|
20
|
+
| `@jarenjs/core/dates` | RFC 3339 / ISO 8601 date-time parsing and validation |
|
|
21
|
+
| `@jarenjs/core/text` | text validators: emails, hostnames, IPs, URIs/IRIs, UUIDs, punycode, ... |
|
|
22
|
+
| `@jarenjs/core/math` | int32/float64 math and 2D/3D vector classes |
|
|
23
|
+
|
|
24
|
+
Deep imports work too (`@jarenjs/core/text/email`, `@jarenjs/core/math/vec2f64`, ...).
|
|
25
|
+
|
|
26
|
+
## Strings and Unicode
|
|
27
|
+
|
|
28
|
+
`@jarenjs/core/string` counts string length the way JSON Schema expects — by grapheme cluster, not UTF-16 code units — without paying for `Intl.Segmenter` unless the string actually needs it:
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
import { getStringLength, isAsciiString, createRegExp } from '@jarenjs/core/string';
|
|
32
|
+
|
|
33
|
+
getStringLength('hello', true); // 5 (ASCII fast path: str.length)
|
|
34
|
+
getStringLength('héllo', true); // 5 (surrogate-aware code point count)
|
|
35
|
+
getStringLength('👨👩👧👦', true); // 1 (grapheme segmentation, only when clusters can form)
|
|
36
|
+
getStringLength('👨👩👧👦'); // 11 (default: plain UTF-16 length)
|
|
37
|
+
|
|
38
|
+
createRegExp('^\\p{L}+$'); // cached, unicode-flagged RegExp
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Text validation
|
|
42
|
+
|
|
43
|
+
`@jarenjs/core/text` is a validation toolbox that backs the [`@jarenjs/formats`](../formats) package but stands on its own — every function takes a string and returns a boolean, with cheap common-case fast paths before comprehensive parsing:
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
import { isValidEmail, isValidIdnHostname, isValidIPv6, isValidUriTemplate } from '@jarenjs/core/text';
|
|
47
|
+
|
|
48
|
+
isValidEmail('"joe bloggs"@example.com'); // true (RFC 5321, quoted-string form)
|
|
49
|
+
isValidIdnHostname('실례.테스트'); // true (IDNA contextual rules included)
|
|
50
|
+
isValidIPv6('::ffff:192.168.0.1'); // true
|
|
51
|
+
isValidUriTemplate('/users{/id}{?q}'); // true (RFC 6570)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Grouped by file: `email` (RFC 5321 + internationalized addresses), `host` (hostnames, IDN hostnames, IPv4/IPv6, MAC, URI/URL/IRI and references, URI templates), `identifiers` (UUID, GUID, C/HTML/CSS identifiers), `iregexp` (I-Regexp / RFC 9485 validation and translation to `RegExp`: `isValidIRegexp`, `compileIRegexp`), `base64`, `basic` (alpha, numeric, hex, web colors), `misc` (ISBN-10/13, ISO 3166 country codes, IBAN), `i18n` (Unicode script tests and IDNA context checks) and a complete `punycode` implementation.
|
|
55
|
+
|
|
56
|
+
## Dates, numbers and math
|
|
57
|
+
|
|
58
|
+
- `dates` — RFC 3339 date/time/date-time validation and parsing into `Date` (leap years and month lengths included), ISO 8601 durations, and the more lenient ISO date-time forms.
|
|
59
|
+
- `integer`/`float`/`bigint` — range constants and validators for every fixed-width type from `int8` to `uint64` and `float16` to `float64`, including float increment/decrement in representable steps.
|
|
60
|
+
- `math` — asm.js-style typed math (`Int32`, `Float64`) and vector classes (`Vec2i32`, `Vec2f64`, `Vec3f64`) with a fast integer sine approximation.
|
|
61
|
+
|
|
62
|
+
## JSON addressing standards
|
|
63
|
+
|
|
64
|
+
The JSON addressing and query standards — JSON validation helpers, JSON Pointer (RFC 6901), the compiling JSONPath engine (RFC 9535), and the Jaren JSON Query language with its XQuery front-end — live in [`@jarenjs/json`](../json). This package supplies their foundations: the char-code scanner (`@jarenjs/core/scan`), `equalsJson` deep equality, code-point ordering, and the I-Regexp (RFC 9485) toolbox.
|
|
65
|
+
|
|
66
|
+
## Development
|
|
67
|
+
|
|
68
|
+
Unit tests live in `test/core/` at the repository root (`npm run test:core`). This package's internals are described in its own [ARCHITECTURE](./ARCHITECTURE.md) document; see the repository [README](../../README.md) and [ARCHITECTURE](../../ARCHITECTURE.md) for the monorepo picture, and the [ROADMAP](../../ROADMAP.md) for planned work.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief test if object is instanceof Array, Set or TypedArray!
|
|
3
|
+
* @param {*} data the data to test
|
|
4
|
+
* @returns boolean
|
|
5
|
+
*/
|
|
6
|
+
export declare function isArrayish(data: any): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Returns a new array containing only the unique elements from the input array.
|
|
9
|
+
* If the input is an array, it filters out duplicate elements.
|
|
10
|
+
* If the input is a Set, it converts it to an array.
|
|
11
|
+
* @param {Array|Set} arr - The input array or Set.
|
|
12
|
+
* @param {Array|undefined} [def=undefined] - The default value to return if the input is neither an array nor a Set.
|
|
13
|
+
* @returns {Array|undefined} A new array with unique elements, or the default value if the input is not an array or Set.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getUniqueArray(arr: any[] | Set<any>, def?: any[] | undefined): any[] | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if all elements in the input array are unique.
|
|
18
|
+
* @param {Array} arr - The input array to check for uniqueness.
|
|
19
|
+
* @returns {boolean} True if all elements are unique, false otherwise.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isUniqueArray(arr: any[]): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if all elements in the 'values' array are included in the 'arr' array.
|
|
24
|
+
* @param {Array} arr - The array to check against.
|
|
25
|
+
* @param {Array} values - The array of values to check for inclusion.
|
|
26
|
+
* @returns {boolean} True if all 'values' are included in 'arr', false otherwise.
|
|
27
|
+
*/
|
|
28
|
+
export declare function includesAll(arr: any[], values: any[]): boolean;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function isBigIntishType(data: any): boolean;
|
|
2
|
+
export declare function getBigIntishType(obj: any, def?: undefined): any;
|
|
3
|
+
export declare function BigInt_min(...args: any[]): any;
|
|
4
|
+
export declare function BigInt_max(...args: any[]): any;
|
|
5
|
+
export declare function BigInt_MinMax(...args: any[]): any;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export declare const CONST_TICKS_SECOND = 1000;
|
|
2
|
+
export declare const CONST_TICKS_HOUR: number;
|
|
3
|
+
export declare const CONST_TICKS_DAY: number;
|
|
4
|
+
export declare const CONST_TIME_INSERTDATE = "1970-01-01T";
|
|
5
|
+
export declare const CONST_DATE_APPENDTIME = "T00:00:00Z";
|
|
6
|
+
export declare const CONST_RFC3339_DAYS: readonly number[];
|
|
7
|
+
export declare const CONST_RFC3339_REGEX_ISDATE: RegExp;
|
|
8
|
+
export declare const CONST_RFC3339_REGEX_ISTIME: RegExp;
|
|
9
|
+
export declare function isDateType(data: any): boolean;
|
|
10
|
+
export declare function isDateishType(data: any): boolean;
|
|
11
|
+
export declare function isLeapYear(year: any): boolean;
|
|
12
|
+
export declare function isDateOnlyInRange(year?: number, month?: number, day?: number): boolean;
|
|
13
|
+
export declare function isDateOnlyRFC3339(str: any): boolean;
|
|
14
|
+
export declare function isTimeOnlyInRange(hrs?: number, min?: number, sec?: number, tzh?: number, tzm?: number, tzSign?: number): boolean;
|
|
15
|
+
export declare function isTimeOnlyRFC3339(str: any): boolean;
|
|
16
|
+
export declare function isDateTimeRFC3339(str: any): boolean;
|
|
17
|
+
export declare function getDateTypeOfDateOnlyRFC3339(str: any, def?: undefined): Date | undefined;
|
|
18
|
+
export declare function getDateTypeOfTimeOnlyRFC3339(str: any, def?: undefined): Date | undefined;
|
|
19
|
+
export declare function getDateTypeOfDateTimeRFC3339(str: any, def?: undefined): Date | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Validates a duration string per RFC 3339.
|
|
22
|
+
* Duration format: P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W
|
|
23
|
+
*
|
|
24
|
+
* @param {string} str - The duration string to validate
|
|
25
|
+
* @returns {boolean} - True if the string is a valid duration
|
|
26
|
+
* @example
|
|
27
|
+
* isValidDuration('P1Y2M3DT4H5M6S'); // true (1 year, 2 months, 3 days, 4 hours, 5 minutes, 6 seconds)
|
|
28
|
+
* isValidDuration('P1W'); // true (1 week)
|
|
29
|
+
* isValidDuration('PT1H'); // true (1 hour)
|
|
30
|
+
* isValidDuration('P1Y'); // true (1 year)
|
|
31
|
+
* isValidDuration('P'); // false (empty duration)
|
|
32
|
+
* isValidDuration('1Y'); // false (missing P)
|
|
33
|
+
*/
|
|
34
|
+
export declare function isValidDuration(str: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Validates an ISO 8601 date-time string with optional timezone.
|
|
37
|
+
* Unlike RFC 3339, the timezone is optional.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} str - The date-time string to validate
|
|
40
|
+
* @returns {boolean} - True if the string is a valid ISO date-time
|
|
41
|
+
* @example
|
|
42
|
+
* isValidISODateTime('2024-01-15T12:30:00Z'); // true
|
|
43
|
+
* isValidISODateTime('2024-01-15T12:30:00+01:00'); // true
|
|
44
|
+
* isValidISODateTime('2024-01-15T12:30:00'); // true (no timezone)
|
|
45
|
+
* isValidISODateTime('2024-01-15 12:30:00'); // true (space separator)
|
|
46
|
+
* isValidISODateTime('2024-13-15T12:30:00'); // false (invalid month)
|
|
47
|
+
*/
|
|
48
|
+
export declare function isValidISODateTime(str: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Validates an ISO 8601 time string with optional timezone.
|
|
51
|
+
* Unlike RFC 3339, the timezone is optional.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} str - The time string to validate
|
|
54
|
+
* @returns {boolean} - True if the string is a valid ISO time
|
|
55
|
+
* @example
|
|
56
|
+
* isValidISOTime('12:30:00Z'); // true
|
|
57
|
+
* isValidISOTime('12:30:00+01:00'); // true
|
|
58
|
+
* isValidISOTime('12:30:00'); // true (no timezone)
|
|
59
|
+
* isValidISOTime('25:00:00'); // false (invalid hour)
|
|
60
|
+
*/
|
|
61
|
+
export declare function isValidISOTime(str: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Parses an ISO 8601 date-time string with optional timezone.
|
|
64
|
+
* Returns a Date object if valid, otherwise undefined.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} str - The date-time string to parse
|
|
67
|
+
* @param {any} [def=undefined] - Default value to return if invalid
|
|
68
|
+
* @returns {Date|undefined} - The parsed Date or default value
|
|
69
|
+
*/
|
|
70
|
+
export declare function getDateTypeOfISODateTime(str: string, def?: any): Date | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Parses an ISO 8601 time string with optional timezone.
|
|
73
|
+
* Returns a Date object (with 1970-01-01 as date) if valid, otherwise undefined.
|
|
74
|
+
*
|
|
75
|
+
* @param {string} str - The time string to parse
|
|
76
|
+
* @param {any} [def=undefined] - Default value to return if invalid
|
|
77
|
+
* @returns {Date|undefined} - The parsed Date or default value
|
|
78
|
+
*/
|
|
79
|
+
export declare function getDateTypeOfISOTime(str: string, def?: any): Date | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const FLOAT16_MAX = 65504;
|
|
2
|
+
export declare const FLOAT16_MIN = 0.00006103515625;
|
|
3
|
+
export declare const FLOAT16_EPS = 0.0009765625;
|
|
4
|
+
export declare const FLOAT16_EXBITS = 5;
|
|
5
|
+
export declare const FLOAT16_FRBITS = 10;
|
|
6
|
+
export declare function isValidFloat16(value: any): boolean;
|
|
7
|
+
export declare function getValidFloat16(value: any, defVal?: number): any;
|
|
8
|
+
export declare function Float16_increment(value: any): any;
|
|
9
|
+
export declare function Float16_decrement(value: any): number;
|
|
10
|
+
export declare const FLOAT32_MAX = 3.4028234663852886e+38;
|
|
11
|
+
export declare const FLOAT32_MIN = 1.1754943508222875e-38;
|
|
12
|
+
export declare const FLOAT32_EPS = 1.1920928955078125e-7;
|
|
13
|
+
export declare const FLOAT32_EXBITS = 8;
|
|
14
|
+
export declare const FLOAT32_FRBITS = 23;
|
|
15
|
+
export declare function isValidFloat32(value: any): boolean;
|
|
16
|
+
export declare function getValidFloat32(value: any, defVal?: number): any;
|
|
17
|
+
export declare function Float32_increment(value: any): any;
|
|
18
|
+
export declare function Float32_decrement(value: any): number;
|
|
19
|
+
export declare const FLOAT64_MAX: number;
|
|
20
|
+
export declare const FLOAT64_MIN: number;
|
|
21
|
+
export declare const FLOAT64_EPS: number;
|
|
22
|
+
export declare const FLOAT64_EXBITS = 11;
|
|
23
|
+
export declare const FLOAT64_FRBITS = 52;
|
|
24
|
+
export declare function isValidFloat64(value: any): boolean;
|
|
25
|
+
export declare function getValidFloat64(value: any, defVal?: number): any;
|
|
26
|
+
export declare function Float64_increment(value: any): any;
|
|
27
|
+
export declare function Float64_decrement(value: any): number;
|
|
28
|
+
export declare const FLOAT128_MAX = 0;
|
|
29
|
+
export declare const FLOAT128_MIN = 0;
|
|
30
|
+
export declare const FLOAT128_EPS = 0;
|
|
31
|
+
export declare const FLOAT128_EXBITS = 15;
|
|
32
|
+
export declare const FLOAT128_FRBITS = 112;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* trueThat
|
|
3
|
+
* acts as a dummy validator that always returns true
|
|
4
|
+
* @param {any} whatever any json data input
|
|
5
|
+
* @param {string | undefined} _path the current json path to the data
|
|
6
|
+
* @param {any | undefined} _root the root of the json data
|
|
7
|
+
* @param {string | string[] | undefined} _key a key or an array of keys
|
|
8
|
+
* @returns {boolean} returns always true
|
|
9
|
+
*/
|
|
10
|
+
export declare function trueThat(whatever: any, _path?: string | undefined, _root?: any | undefined, _key?: string | string[] | undefined): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* falseThat
|
|
13
|
+
* acts as a dummy validator that always returns false
|
|
14
|
+
* @param {any} whatever any json data input
|
|
15
|
+
* @param {string | undefined} _path the current json path to the data
|
|
16
|
+
* @param {any | undefined} _root the root of the json data
|
|
17
|
+
* @param {string | string[] | undefined} _key a key or an array of keys
|
|
18
|
+
* @returns {boolean} returns always true
|
|
19
|
+
*/
|
|
20
|
+
export declare function falseThat(whatever: any, _path?: string | undefined, _root?: any | undefined, _key?: string | string[] | undefined): boolean;
|
|
21
|
+
export declare function fallbackFn(compiled: any, fallback?: typeof trueThat): any;
|
|
22
|
+
export declare function addFunctionToArray(arr: any[] | undefined, fn: any): any[];
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export declare function isFn(data: any): boolean;
|
|
2
|
+
export declare function isScalarType(data: any): boolean;
|
|
3
|
+
export declare function isStringType(data: any): data is string;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the given data is of boolean type.
|
|
6
|
+
* @param {any} data - The data to check.
|
|
7
|
+
* @returns {boolean} - True if the data is a boolean, otherwise false.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isBooleanType(data: any): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the given data is of number type.
|
|
12
|
+
* @param {any} data - The data to check.
|
|
13
|
+
* @returns {boolean} - True if the data is a number, otherwise false.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isNumberType(data: any): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the given data is an integer type.
|
|
18
|
+
* @param {any} data - The data to check.
|
|
19
|
+
* @returns {boolean} - True if the data is an integer, otherwise false.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isIntegerType(data: any): boolean;
|
|
22
|
+
export declare function isBigIntType(data: any): data is bigint;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the string type of the input object if it is a string; otherwise, returns the default value.
|
|
25
|
+
*
|
|
26
|
+
* @param {any} obj - The input object to check its type.
|
|
27
|
+
* @param {string|undefined} [def=undefined] - The default value to return if the input object is not a string.
|
|
28
|
+
* @returns {string} The string type of the input object or the default value.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getStringType(obj: any, def?: string | undefined): string;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the given object is a boolean type and returns it, otherwise returns the default value.
|
|
33
|
+
* @param {any} obj - The object to check.
|
|
34
|
+
* @param {boolean|undefined} [def=undefined] - The default value to return if the object is not a boolean.
|
|
35
|
+
* @returns {boolean|undefined} - The boolean value or the default value.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getBooleanType(obj: any, def?: boolean | undefined): boolean | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Checks if the given object is a number type and returns it, otherwise returns the default value.
|
|
40
|
+
* @param {any} obj - The object to check.
|
|
41
|
+
* @param {number|undefined} [def=undefined] - The default value to return if the object is not a number.
|
|
42
|
+
* @returns {number|undefined} - The number value or the default value.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getNumberType(obj: any, def?: number | undefined): number | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Checks if the given object is an integer type and returns it, otherwise returns the default value.
|
|
47
|
+
* @param {any} obj - The object to check.
|
|
48
|
+
* @param {number|undefined} [def=undefined] - The default value to return if the object is not an integer.
|
|
49
|
+
* @returns {number|undefined} - The integer value or the default value.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getIntegerType(obj: any, def?: number | undefined): number | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Checks if the given object is a bigint type and returns it, otherwise returns the default value.
|
|
54
|
+
* @param {any} obj - The object to check.
|
|
55
|
+
* @param {bigint|undefined} [def=undefined] - The default value to return if the object is not a bigint.
|
|
56
|
+
* @returns {bigint|undefined} - The bigint value or the default value.
|
|
57
|
+
*/
|
|
58
|
+
export declare function getBigIntType(obj: any, def?: bigint | undefined): bigint | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Checks if the input data is null.
|
|
61
|
+
*
|
|
62
|
+
* @param {any} data - The data to be checked.
|
|
63
|
+
* @returns {boolean} - Returns true if the data is null, otherwise false.
|
|
64
|
+
*/
|
|
65
|
+
export declare function isNullValue(data: any): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Checks if the given data is an object of a specific class.
|
|
68
|
+
*
|
|
69
|
+
* @param {any} data - The data to check.
|
|
70
|
+
* @param {Function} type - The class type to compare against.
|
|
71
|
+
* @returns {boolean} Returns true if the data is an object of the specified class; otherwise, false.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isObjectOfClass(data: any, type: Function): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* @brief test if data is an object literal
|
|
76
|
+
* @param {*} data the data to test
|
|
77
|
+
* @returns boolean
|
|
78
|
+
*/
|
|
79
|
+
export declare function isObjectClass(data: any): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Checks if the input data is of type Map.
|
|
82
|
+
*
|
|
83
|
+
* @param {any} data - The data to be checked.
|
|
84
|
+
* @returns {boolean} - Returns true if the data is an instance of the Map class, otherwise false.
|
|
85
|
+
*/
|
|
86
|
+
export declare function isMapClass(data: any): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* @brief test if data is typeof object but not an Array
|
|
89
|
+
* @param {*} data the data to test
|
|
90
|
+
* @returns boolean
|
|
91
|
+
*/
|
|
92
|
+
export declare function isObjectType(data: any): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Checks if the input data is of type Array.
|
|
95
|
+
*
|
|
96
|
+
* @param {any} data - The data to be checked.
|
|
97
|
+
* @returns {boolean} - Returns true if the data is an instance of the Array class, otherwise false.
|
|
98
|
+
*/
|
|
99
|
+
export declare function isArrayClass(data: any): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Checks if the input data is of type Set.
|
|
102
|
+
*
|
|
103
|
+
* @param {any} data - The data to be checked.
|
|
104
|
+
* @returns {boolean} - Returns true if the data is an instance of the Set class, otherwise false.
|
|
105
|
+
*/
|
|
106
|
+
export declare function isSetClass(data: any): boolean;
|
|
107
|
+
export declare const TypedArray: any;
|
|
108
|
+
export declare function isTypedArray(data: any): boolean;
|
|
109
|
+
export declare function getObjectType(obj: any, def?: undefined): any;
|
|
110
|
+
export declare function getArrayClass(obj: any, def?: undefined): any;
|
|
111
|
+
/**
|
|
112
|
+
* Calculates the inclusive and exclusive bounds based on the provided parameters.
|
|
113
|
+
*
|
|
114
|
+
* @param {function} getType - A function to determine the type of the inclusive and exclusive bounds.
|
|
115
|
+
* @param {number|string|undefined} inclusive - The inclusive bound value.
|
|
116
|
+
* @param {number|string|boolean|undefined} exclusive - The exclusive bound value.
|
|
117
|
+
* @returns {Array} An array containing the inclusive and exclusive bounds.
|
|
118
|
+
*/
|
|
119
|
+
export declare function getInclusiveExclusiveBounds(getType: Function, inclusive: number | string | undefined, exclusive: number | string | boolean | undefined): any[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const INT8_MIN = -128;
|
|
2
|
+
export declare const INT8_MAX = 127;
|
|
3
|
+
export declare function isValidInt8(value: any): boolean;
|
|
4
|
+
export declare const UINT8_MIN = 0;
|
|
5
|
+
export declare const UINT8_MAX = 255;
|
|
6
|
+
export declare function isValidUInt8(value: any): boolean;
|
|
7
|
+
export declare const INT16_MIN = -32768;
|
|
8
|
+
export declare const INT16_MAX = 32767;
|
|
9
|
+
export declare function isValidInt16(value: any): boolean;
|
|
10
|
+
export declare const UINT16_MIN = 0;
|
|
11
|
+
export declare const UINT16_MAX = 65535;
|
|
12
|
+
export declare function isValidUInt16(value: any): boolean;
|
|
13
|
+
export declare const INT32_MIN: number;
|
|
14
|
+
export declare const INT32_MAX: number;
|
|
15
|
+
export declare function isValidInt32(value: any): boolean;
|
|
16
|
+
export declare const UINT32_MIN = 0;
|
|
17
|
+
export declare const UINT32_MAX: number;
|
|
18
|
+
export declare function isValidUInt32(value: any): boolean;
|
|
19
|
+
export declare const INT64_MIN: number;
|
|
20
|
+
export declare const INT64_MAX: number;
|
|
21
|
+
export declare function isValidInt64(value: any): boolean;
|
|
22
|
+
export declare const UINT64_MIN = 0;
|
|
23
|
+
export declare const UINT64_MAX: number;
|
|
24
|
+
export declare function isValidUInt64(value: any): boolean;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export declare const mathf64_abs: (x: number) => number;
|
|
2
|
+
export declare const mathf64_sqrt: (x: number) => number;
|
|
3
|
+
export declare const mathf64_pow: (x: number, y: number) => number;
|
|
4
|
+
export declare const mathf64_sin: (x: number) => number;
|
|
5
|
+
export declare const mathf64_cos: (x: number) => number;
|
|
6
|
+
export declare const mathf64_atan2: (y: number, x: number) => number;
|
|
7
|
+
export declare const mathf64_asin: (x: number) => number;
|
|
8
|
+
export declare const mathf64_ceil: (x: number) => number;
|
|
9
|
+
export declare const mathf64_floor: (x: number) => number;
|
|
10
|
+
export declare const mathf64_round: (x: number) => number;
|
|
11
|
+
export declare const mathf64_min: (...values: number[]) => number;
|
|
12
|
+
export declare const mathf64_max: (...values: number[]) => number;
|
|
13
|
+
export declare const mathf64_random: () => number;
|
|
14
|
+
export declare const mathf64_EPSILON = 0.000001;
|
|
15
|
+
export declare const mathf64_SQRTFIVE: number;
|
|
16
|
+
export declare const mathf64_PI: number;
|
|
17
|
+
export declare const mathf64_PI2: number;
|
|
18
|
+
export declare const mathf64_PI1H: number;
|
|
19
|
+
export declare const mathf64_PI41: number;
|
|
20
|
+
export declare const mathf64_PI42: number;
|
|
21
|
+
export declare class Float64 {
|
|
22
|
+
static gcd(a?: number, b?: number): any;
|
|
23
|
+
static sqrt(n?: number): number;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* The Cross Product Magnitude
|
|
27
|
+
* a × b of two vectors is another vector that is at right angles to both:
|
|
28
|
+
* The magnitude (length) of the cross product equals the area
|
|
29
|
+
* of a parallelogram with vectors a and b for sides:
|
|
30
|
+
*
|
|
31
|
+
* We can calculate the Cross Product this way:
|
|
32
|
+
*
|
|
33
|
+
* a × b = |a| |b| sin(θ) n
|
|
34
|
+
*
|
|
35
|
+
* or as
|
|
36
|
+
*
|
|
37
|
+
* a × b = ax × by - bx × ay
|
|
38
|
+
*
|
|
39
|
+
* Another useful property of the cross product is,
|
|
40
|
+
* that its magnitude is related to the sine of
|
|
41
|
+
* the angle between the two vectors:
|
|
42
|
+
*
|
|
43
|
+
* | a x b | = |a| . |b| . sine(theta)
|
|
44
|
+
*
|
|
45
|
+
* or
|
|
46
|
+
*
|
|
47
|
+
* sine(theta) = | a x b | / (|a| . |b|)
|
|
48
|
+
*
|
|
49
|
+
* So, in implementation 1 above, if a and b are known in advance
|
|
50
|
+
* to be unit vectors then the result of that function is exactly that sine() value.
|
|
51
|
+
* @param {number} ax
|
|
52
|
+
* @param {number} ay
|
|
53
|
+
* @param {number} bx
|
|
54
|
+
* @param {number} by
|
|
55
|
+
*/
|
|
56
|
+
static cross(ax?: number, ay?: number, bx?: number, by?: number): number;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* We can calculate the Dot Product of two vectors this way:
|
|
60
|
+
*
|
|
61
|
+
* a · b = |a| × |b| × cos(θ)
|
|
62
|
+
*
|
|
63
|
+
* or in this implementation as:
|
|
64
|
+
*
|
|
65
|
+
* a · b = ax × bx + ay × by
|
|
66
|
+
*
|
|
67
|
+
* When two vectors are at right angles to each other the dot product is zero.
|
|
68
|
+
*
|
|
69
|
+
* @param {number} ax vector A x velocity
|
|
70
|
+
* @param {number} ay vector A y velocity
|
|
71
|
+
* @param {number} bx vector B x velocity
|
|
72
|
+
* @param {number} by vector B y velocity
|
|
73
|
+
* @returns {number} scalar of the dot product
|
|
74
|
+
*/
|
|
75
|
+
static dot(ax?: number, ay?: number, bx?: number, by?: number): number;
|
|
76
|
+
static mag2(dx?: number, dy?: number): number;
|
|
77
|
+
static mag(dx?: number, dy?: number): number;
|
|
78
|
+
static isqrt(n?: number): number;
|
|
79
|
+
static fib(n?: number): number;
|
|
80
|
+
static fib2(value?: number): number;
|
|
81
|
+
static norm(value?: number, min?: number, max?: number): number;
|
|
82
|
+
static lerp(norm?: number, min?: number, max?: number): number;
|
|
83
|
+
static map(value?: number, smin?: number, smax?: number, dmin?: number, dmax?: number): number;
|
|
84
|
+
/**
|
|
85
|
+
* Clamps a value between a checked boundary.
|
|
86
|
+
* and can therefor handle swapped min/max arguments
|
|
87
|
+
*
|
|
88
|
+
* @param {number} value input value
|
|
89
|
+
* @param {number} min minimum bounds
|
|
90
|
+
* @param {number} max maximum bounds
|
|
91
|
+
* @returns {number} clamped value
|
|
92
|
+
*/
|
|
93
|
+
static clamp(value?: number, min?: number, max?: number): number;
|
|
94
|
+
/**
|
|
95
|
+
* Clamps a value between an unchecked boundary
|
|
96
|
+
* this function needs min < max!!
|
|
97
|
+
* (see Float64.clamp for a checked boundary)
|
|
98
|
+
*
|
|
99
|
+
* @param {number} value input value
|
|
100
|
+
* @param {number} min minimum bounds
|
|
101
|
+
* @param {number} max maximum bounds
|
|
102
|
+
* @returns {number} clamped value
|
|
103
|
+
*/
|
|
104
|
+
static clampu(value?: number, min?: number, max?: number): number;
|
|
105
|
+
static inRange(value?: number, min?: number, max?: number): number;
|
|
106
|
+
static intersectsRange(smin?: number, smax?: number, dmin?: number, dmax?: number): number;
|
|
107
|
+
static intersectsRect(ax?: number, ay?: number, aw?: number, ah?: number, bx?: number, by?: number, bw?: number, bh?: number): number;
|
|
108
|
+
static toRadian(degrees?: number): number;
|
|
109
|
+
static toDegrees(radians?: number): number;
|
|
110
|
+
static wrapRadians(r?: number): number;
|
|
111
|
+
static sinLpEx(r?: number): number;
|
|
112
|
+
static sinLp(r?: number): number;
|
|
113
|
+
static cosLp(r?: number): number;
|
|
114
|
+
static cosHp(r?: number): void;
|
|
115
|
+
static sinMpEx(r?: number): number;
|
|
116
|
+
static sinMp(r?: number): number;
|
|
117
|
+
static cosMp(r?: number): number;
|
|
118
|
+
static theta(x?: number, y?: number): number;
|
|
119
|
+
static angle(x?: number, y?: number): number;
|
|
120
|
+
static phi(y?: number, len?: number): number;
|
|
121
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const mathi32_MULTIPLIER = 10000;
|
|
2
|
+
export declare const mathi32_abs: (x: number) => number;
|
|
3
|
+
export declare const mathi32_round: (x: number) => number;
|
|
4
|
+
export declare const mathi32_ceil: (x: number) => number;
|
|
5
|
+
export declare const mathi32_floor: (x: number) => number;
|
|
6
|
+
export declare const mathi32_min: (...values: number[]) => number;
|
|
7
|
+
export declare const mathi32_max: (...values: number[]) => number;
|
|
8
|
+
export declare const mathi32_sqrt: (x: number) => number;
|
|
9
|
+
export declare const mathi32_asin: (x: number) => number;
|
|
10
|
+
export declare const mathi32_atan2: (y: number, x: number) => number;
|
|
11
|
+
export declare const mathi32_PI: number;
|
|
12
|
+
export declare const mathi32_PI2: number;
|
|
13
|
+
export declare const mathi32_PI1H: number;
|
|
14
|
+
export declare const mathi32_PI41: number;
|
|
15
|
+
export declare const mathi32_PI42: number;
|
|
16
|
+
export declare class Int32 {
|
|
17
|
+
static random(): number;
|
|
18
|
+
static sqrt(n?: number): number;
|
|
19
|
+
static sqrtEx(n?: number): number;
|
|
20
|
+
static fib(n?: number): number;
|
|
21
|
+
static mag2(dx?: number, dy?: number): number;
|
|
22
|
+
static hypot(dx?: number, dy?: number): number;
|
|
23
|
+
static hypotEx(dx?: number, dy?: number): number;
|
|
24
|
+
static dot(ax?: number, ay?: number, bx?: number, by?: number): number;
|
|
25
|
+
static cross(ax?: number, ay?: number, bx?: number, by?: number): number;
|
|
26
|
+
static norm(value?: number, min?: number, max?: number): number;
|
|
27
|
+
static lerp(norm?: number, min?: number, max?: number): number;
|
|
28
|
+
static map(value?: number, smin?: number, smax?: number, dmin?: number, dmax?: number): number;
|
|
29
|
+
static clamp(value?: number, min?: number, max?: number): number;
|
|
30
|
+
static clampu(value?: number, min?: number, max?: number): number;
|
|
31
|
+
static clampu_u8a(value?: number): number;
|
|
32
|
+
static clampu_u8b(value?: number): number;
|
|
33
|
+
static inRange(value?: number, min?: number, max?: number): boolean;
|
|
34
|
+
static intersectsRange(smin?: number, smax?: number, dmin?: number, dmax?: number): boolean;
|
|
35
|
+
static intersectsRect(ax?: number, ay?: number, aw?: number, ah?: number, bx?: number, by?: number, bw?: number, bh?: number): boolean;
|
|
36
|
+
static toRadianEx(degrees?: number): number;
|
|
37
|
+
static toDegreesEx(radians?: number): number;
|
|
38
|
+
static wrapRadians(r?: number): number;
|
|
39
|
+
static sinLpEx(r?: number): number;
|
|
40
|
+
static sinLp(r?: number): number;
|
|
41
|
+
}
|