@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.
Files changed (58) hide show
  1. package/ARCHITECTURE.md +800 -0
  2. package/LICENSE +21 -0
  3. package/README.md +68 -0
  4. package/dist/types/array.d.ts +28 -0
  5. package/dist/types/bigint.d.ts +5 -0
  6. package/dist/types/dates.d.ts +79 -0
  7. package/dist/types/float.d.ts +32 -0
  8. package/dist/types/function.d.ts +22 -0
  9. package/dist/types/index.d.ts +119 -0
  10. package/dist/types/integer.d.ts +24 -0
  11. package/dist/types/math/float64.d.ts +121 -0
  12. package/dist/types/math/index.d.ts +5 -0
  13. package/dist/types/math/int32.d.ts +41 -0
  14. package/dist/types/math/vec2f64.d.ts +346 -0
  15. package/dist/types/math/vec2i32.d.ts +43 -0
  16. package/dist/types/math/vec3f64.d.ts +61 -0
  17. package/dist/types/number.d.ts +39 -0
  18. package/dist/types/object.d.ts +44 -0
  19. package/dist/types/scan.d.ts +64 -0
  20. package/dist/types/string.d.ts +65 -0
  21. package/dist/types/text/base64.d.ts +4 -0
  22. package/dist/types/text/basic.d.ts +5 -0
  23. package/dist/types/text/email.d.ts +3 -0
  24. package/dist/types/text/host.d.ts +14 -0
  25. package/dist/types/text/i18n.d.ts +13 -0
  26. package/dist/types/text/identifiers.d.ts +5 -0
  27. package/dist/types/text/index.d.ts +8 -0
  28. package/dist/types/text/iregexp.d.ts +36 -0
  29. package/dist/types/text/misc.d.ts +4 -0
  30. package/dist/types/text/punycode.d.ts +86 -0
  31. package/package.json +101 -0
  32. package/src/array.js +57 -0
  33. package/src/bigint.js +30 -0
  34. package/src/dates.js +371 -0
  35. package/src/float.js +107 -0
  36. package/src/function.js +56 -0
  37. package/src/index.js +223 -0
  38. package/src/integer.js +77 -0
  39. package/src/math/float64.js +316 -0
  40. package/src/math/index.js +5 -0
  41. package/src/math/int32.js +235 -0
  42. package/src/math/vec2f64.js +706 -0
  43. package/src/math/vec2i32.js +250 -0
  44. package/src/math/vec3f64.js +225 -0
  45. package/src/number.js +63 -0
  46. package/src/object.js +240 -0
  47. package/src/scan.js +96 -0
  48. package/src/string.js +194 -0
  49. package/src/text/base64.js +54 -0
  50. package/src/text/basic.js +23 -0
  51. package/src/text/email.js +61 -0
  52. package/src/text/host.js +335 -0
  53. package/src/text/i18n.js +294 -0
  54. package/src/text/identifiers.js +27 -0
  55. package/src/text/index.js +11 -0
  56. package/src/text/iregexp.js +308 -0
  57. package/src/text/misc.js +19 -0
  58. package/src/text/punycode.js +407 -0
@@ -0,0 +1,14 @@
1
+ export declare function isValidMACAddr(str: any): boolean;
2
+ export declare function isValidIPv4(str: any): boolean;
3
+ export declare function isValidIPv6(str: any): boolean;
4
+ export declare function isValidHostname(str: any): boolean;
5
+ export declare function isValidIdnHostname(str: any): boolean;
6
+ export declare function isValidUrl(str: any): boolean;
7
+ export declare function isValidUrlFull(str: any): boolean;
8
+ export declare function isValidUri(str: any): boolean;
9
+ export declare function isValidUriFull(str: any): boolean;
10
+ export declare function isValidUriRef(str: any): boolean;
11
+ export declare function isValidUriRefFull(str: any): boolean;
12
+ export declare function isValidUriTemplate(str: any): boolean;
13
+ export declare function isValidIRI(str: any): boolean;
14
+ export declare function isValidIRIRef(str: any): boolean;
@@ -0,0 +1,13 @@
1
+ export declare function isLatinLowercaseL(code: any): boolean;
2
+ export declare function isGreek(code: any): boolean;
3
+ export declare function isHebrew(code: any): boolean;
4
+ export declare function isHiragana(code: any): boolean;
5
+ export declare function isKatakana(code: any): boolean;
6
+ export declare function isHan(code: any): boolean;
7
+ export declare function isArabicIndicDigit(code: any): boolean;
8
+ export declare function isExtendedArabicIndicDigit(code: any): boolean;
9
+ export declare function isVirama(code: any): boolean;
10
+ export declare function isCombiningMark(code: any): boolean;
11
+ export declare function checkContextualRules(label: any): boolean;
12
+ export declare function checkDigitMixing(codes: any): boolean;
13
+ export declare function isValidIdnChar(code: any): boolean;
@@ -0,0 +1,5 @@
1
+ export declare function isValidUUID(str: any): boolean;
2
+ export declare function isValidGUID(str: any): boolean;
3
+ export declare function isValidIdentifier(str: any): boolean;
4
+ export declare function isValidHtmlIdentifier(str: any): boolean;
5
+ export declare function isValidCssIdentifier(str: any): boolean;
@@ -0,0 +1,8 @@
1
+ export * from './base64.js';
2
+ export * from './basic.js';
3
+ export * from './email.js';
4
+ export * from './host.js';
5
+ export * from './i18n.js';
6
+ export * from './identifiers.js';
7
+ export * from './iregexp.js';
8
+ export * from './misc.js';
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Validate an I-Regexp (RFC 9485) against its complete ABNF grammar and
3
+ * translate it to an equivalent ECMAScript pattern (RFC 9485 section 5.3):
4
+ *
5
+ * - unescaped dots outside character classes become [^\n\r]
6
+ * - '\-' outside a character class becomes '-' (not a valid ECMAScript
7
+ * escape under the 'u' flag)
8
+ * - unescaped '^' and '$' (grammatically NormalChars) pass through
9
+ * unchanged: the RFC's own ECMAScript/PCRE/RE2/Ruby conversions
10
+ * (sections 5.3/5.4) leave them alone, which gives them anchor
11
+ * semantics, and the official JSONPath compliance test suite expects
12
+ * exactly that; write '\^' for a literal caret and '[$]' for a
13
+ * literal dollar ('\$' is not a valid I-Regexp escape)
14
+ *
15
+ * I-Regexp deliberately excludes lookaround, backreferences, lazy
16
+ * quantifiers, multi-character escapes (\d \s \w), and inline flags; per
17
+ * RFC 9535 sections 2.4.6/2.4.7 a nonconforming pattern makes
18
+ * match()/search() yield LogicalFalse, so this returns null for them.
19
+ *
20
+ * @param {string} pattern - The I-Regexp pattern
21
+ * @returns {string|null} The ECMAScript pattern source, or null when invalid
22
+ */
23
+ export declare function translateIRegexp(pattern: string): string | null;
24
+ /**
25
+ * Compile an I-Regexp into an ECMAScript RegExp.
26
+ * @param {string} pattern - The I-Regexp pattern
27
+ * @param {boolean} [fullMatch=false] - Anchor the whole pattern (match() semantics, true) or leave it free (search() semantics, false)
28
+ * @returns {RegExp|null} null when the pattern is not a valid I-Regexp
29
+ */
30
+ export declare function compileIRegexp(pattern: string, fullMatch?: boolean): RegExp | null;
31
+ /**
32
+ * Validates a pattern against the complete I-Regexp (RFC 9485) grammar.
33
+ * @param {string} pattern - The I-Regexp pattern to validate
34
+ * @returns {boolean} True when the pattern is a valid I-Regexp
35
+ */
36
+ export declare function isValidIRegexp(pattern: string): boolean;
@@ -0,0 +1,4 @@
1
+ export declare function isValidISBN10(str: any): boolean;
2
+ export declare function isValidISBN13(str: any): boolean;
3
+ export declare function isValidCountryAlpha2(str: any): boolean;
4
+ export declare function isValidIBAN(str: any): boolean;
@@ -0,0 +1,86 @@
1
+ export declare const punycodeVersion = "2.1.0";
2
+ /**
3
+ * Creates an array containing the numeric code points of each Unicode
4
+ * character in the string. While JavaScript uses UCS-2 internally,
5
+ * this function will convert a pair of surrogate halves (each of which
6
+ * UCS-2 exposes as separate characters) into a single code point,
7
+ * matching UTF-16.
8
+ * @see `punycode.ucs2.encode`
9
+ * @see <https://mathiasbynens.be/notes/javascript-encoding>
10
+ * @memberOf punycode.ucs2
11
+ * @name decode
12
+ * @param {String} string The Unicode input string (UCS-2).
13
+ * @returns {Array} The new array of code points.
14
+ */
15
+ export declare function ucs2decode(string: string): any[];
16
+ /**
17
+ * Creates a string based on an array of numeric code points.
18
+ * @see `punycode.ucs2.decode`
19
+ * @memberOf punycode.ucs2
20
+ * @name encode
21
+ * @param {Array} codePoints The array of numeric code points.
22
+ * @returns {String} The new Unicode string (UCS-2).
23
+ */
24
+ export declare const ucs2encode: (array: any) => string;
25
+ /**
26
+ * Converts a basic code point into a digit/integer.
27
+ * @see `digitToBasic()`
28
+ * @private
29
+ * @param {Number} codePoint The basic numeric code point value.
30
+ * @returns {Number} The numeric value of a basic code point (for use in
31
+ * representing integers) in the range `0` to `base - 1`, or `base` if
32
+ * the code point does not represent a value.
33
+ */
34
+ export declare function basicToDigit(codePoint: number): number;
35
+ /**
36
+ * Converts a digit/integer into a basic code point.
37
+ * @see `basicToDigit()`
38
+ * @private
39
+ * @param {Number} digit The numeric value of a basic code point.
40
+ * @returns {Number} The basic code point whose value (when used for
41
+ * representing integers) is `digit`, which needs to be in the range
42
+ * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
43
+ * used; else, the lowercase form is used. The behavior is undefined
44
+ * if `flag` is non-zero and `digit` has no uppercase form.
45
+ */
46
+ export declare function digitToBasic(digit: number, flag: any): number;
47
+ /**
48
+ * Converts a Punycode string of ASCII-only symbols to a string of Unicode
49
+ * symbols.
50
+ * @memberOf punycode
51
+ * @param {String} input The Punycode string of ASCII-only symbols.
52
+ * @returns {String} The resulting string of Unicode symbols.
53
+ */
54
+ export declare function decode(input: string): string;
55
+ /**
56
+ * Converts a string of Unicode symbols (e.g. a domain name label) to a
57
+ * Punycode string of ASCII-only symbols.
58
+ * @memberOf punycode
59
+ * @param {String} input The string of Unicode symbols.
60
+ * @returns {String} The resulting Punycode string of ASCII-only symbols.
61
+ */
62
+ export declare function encode(str: any): string;
63
+ /**
64
+ * Converts a Punycode string representing a domain name or an email address
65
+ * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
66
+ * it doesn't matter if you call it on a string that has already been
67
+ * converted to Unicode.
68
+ * @memberOf punycode
69
+ * @param {String} input The Punycoded domain name or email address to
70
+ * convert to Unicode.
71
+ * @returns {String} The Unicode representation of the given Punycode
72
+ * string.
73
+ */
74
+ export declare function toUnicode(input: string): string;
75
+ /**
76
+ * Converts a Unicode string representing a domain name or an email address to
77
+ * Punycode. Only the non-ASCII parts of the domain name will be converted,
78
+ * i.e. it doesn't matter if you call it with a domain that's already in
79
+ * ASCII.
80
+ * @memberOf punycode
81
+ * @param {String} input The domain name or email address to convert, as a
82
+ * Unicode string.
83
+ * @returns {String} The Punycode representation of the given domain name or
84
+ * email address.
85
+ */
86
+ export declare function toASCII(input: string): string;
package/package.json ADDED
@@ -0,0 +1,101 @@
1
+ {
2
+ "name": "@jarenjs/core",
3
+ "private": false,
4
+ "version": "0.9.2",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "types": "./dist/types/index.d.ts",
8
+ "sideEffects": false,
9
+ "files": [
10
+ "src/",
11
+ "dist/types/",
12
+ "ARCHITECTURE.md"
13
+ ],
14
+ "description": "Jaren Core Functions",
15
+ "author": "joham",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/jklarenbeek/jarenjs.git",
19
+ "directory": "packages/core"
20
+ },
21
+ "license": "MIT",
22
+ "engines": {
23
+ "node": ">=22"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "registry": "https://registry.npmjs.org/"
28
+ },
29
+ "keywords": [
30
+ "jaren",
31
+ "core"
32
+ ],
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/types/index.d.ts",
36
+ "default": "./src/index.js"
37
+ },
38
+ "./array": {
39
+ "types": "./dist/types/array.d.ts",
40
+ "default": "./src/array.js"
41
+ },
42
+ "./bigint": {
43
+ "types": "./dist/types/bigint.d.ts",
44
+ "default": "./src/bigint.js"
45
+ },
46
+ "./dates": {
47
+ "types": "./dist/types/dates.d.ts",
48
+ "default": "./src/dates.js"
49
+ },
50
+ "./float": {
51
+ "types": "./dist/types/float.d.ts",
52
+ "default": "./src/float.js"
53
+ },
54
+ "./function": {
55
+ "types": "./dist/types/function.d.ts",
56
+ "default": "./src/function.js"
57
+ },
58
+ "./integer": {
59
+ "types": "./dist/types/integer.d.ts",
60
+ "default": "./src/integer.js"
61
+ },
62
+ "./number": {
63
+ "types": "./dist/types/number.d.ts",
64
+ "default": "./src/number.js"
65
+ },
66
+ "./object": {
67
+ "types": "./dist/types/object.d.ts",
68
+ "default": "./src/object.js"
69
+ },
70
+ "./scan": {
71
+ "types": "./dist/types/scan.d.ts",
72
+ "default": "./src/scan.js"
73
+ },
74
+ "./string": {
75
+ "types": "./dist/types/string.d.ts",
76
+ "default": "./src/string.js"
77
+ },
78
+ "./text": {
79
+ "types": "./dist/types/text/index.d.ts",
80
+ "default": "./src/text/index.js"
81
+ },
82
+ "./text/*": {
83
+ "types": "./dist/types/text/*.d.ts",
84
+ "default": "./src/text/*.js"
85
+ },
86
+ "./math": {
87
+ "types": "./dist/types/math/index.d.ts",
88
+ "default": "./src/math/index.js"
89
+ },
90
+ "./math/*": {
91
+ "types": "./dist/types/math/*.d.ts",
92
+ "default": "./src/math/*.js"
93
+ },
94
+ "./package.json": "./package.json"
95
+ },
96
+ "scripts": {
97
+ "build": "npm run build:types",
98
+ "build:types": "tsc -p tsconfig.json",
99
+ "prepack": "npm run build:types"
100
+ }
101
+ }
package/src/array.js ADDED
@@ -0,0 +1,57 @@
1
+ //@ts-check
2
+
3
+ import {
4
+ TypedArray,
5
+ } from './index.js';
6
+
7
+ /**
8
+ * @brief test if object is instanceof Array, Set or TypedArray!
9
+ * @param {*} data the data to test
10
+ * @returns boolean
11
+ */
12
+ export function isArrayish(data) {
13
+ return data != null
14
+ && (data instanceof Array
15
+ || data instanceof Set
16
+ || data instanceof TypedArray);
17
+ }
18
+
19
+ /**
20
+ * Returns a new array containing only the unique elements from the input array.
21
+ * If the input is an array, it filters out duplicate elements.
22
+ * If the input is a Set, it converts it to an array.
23
+ * @param {Array|Set} arr - The input array or Set.
24
+ * @param {Array|undefined} [def=undefined] - The default value to return if the input is neither an array nor a Set.
25
+ * @returns {Array|undefined} A new array with unique elements, or the default value if the input is not an array or Set.
26
+ */
27
+ export function getUniqueArray(arr, def = undefined) {
28
+ if (arr == null)
29
+ return def;
30
+
31
+ return arr.constructor === Array
32
+ ? arr.filter((el, index, a) => index === a.indexOf(el))
33
+ : arr.constructor === Set
34
+ ? Array.from(arr)
35
+ : def;
36
+ }
37
+
38
+ /**
39
+ * Checks if all elements in the input array are unique.
40
+ * @param {Array} arr - The input array to check for uniqueness.
41
+ * @returns {boolean} True if all elements are unique, false otherwise.
42
+ */
43
+ export function isUniqueArray(arr) {
44
+ const unique = getUniqueArray(arr);
45
+ return unique != null
46
+ && unique.length == arr.length;
47
+ }
48
+
49
+ /**
50
+ * Checks if all elements in the 'values' array are included in the 'arr' array.
51
+ * @param {Array} arr - The array to check against.
52
+ * @param {Array} values - The array of values to check for inclusion.
53
+ * @returns {boolean} True if all 'values' are included in 'arr', false otherwise.
54
+ */
55
+ export function includesAll(arr, values) {
56
+ return values.every(v => arr.includes(v));
57
+ }
package/src/bigint.js ADDED
@@ -0,0 +1,30 @@
1
+ //@ts-check
2
+
3
+ import { isBigIntType } from './index.js';
4
+
5
+ export function isBigIntishType(data) {
6
+ return isBigIntType(data)
7
+ ? true
8
+ : false; // TODO: throw new Error('isBigIntishType is not implemented!');
9
+ }
10
+
11
+ export function getBigIntishType(obj, def = undefined) {
12
+ return isBigIntishType(obj)
13
+ ? obj
14
+ : def;
15
+ }
16
+
17
+ export function BigInt_min(...args) {
18
+ return args.reduce((m, e) => (e > m ? e : m));
19
+ }
20
+
21
+ export function BigInt_max(...args) {
22
+ return args.reduce((m, e) => (e < m ? e : m));
23
+ }
24
+
25
+ export function BigInt_MinMax(...args) {
26
+ return args.reduce(([min, max], e) => [
27
+ e < min ? e : min,
28
+ e > max ? e : max,
29
+ ], [args[0], args[0]]);
30
+ }