@limitlesspc/std 0.20.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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/array.d.ts +209 -0
  4. package/dist/array.js +41 -0
  5. package/dist/async/index.d.ts +48 -0
  6. package/dist/async/index.js +155 -0
  7. package/dist/bytes.d.ts +38 -0
  8. package/dist/bytes.js +35 -0
  9. package/dist/chunk-6F4PWJZI.js +0 -0
  10. package/dist/chunk-C2DS6YRJ.js +1664 -0
  11. package/dist/chunk-DO4NH5XG.js +523 -0
  12. package/dist/chunk-EWSJTMH2.js +68 -0
  13. package/dist/chunk-ILLWUQPY.js +139 -0
  14. package/dist/chunk-LJSF3QBT.js +122 -0
  15. package/dist/chunk-MG5VQSTV.js +89 -0
  16. package/dist/chunk-TMLWLR46.js +12 -0
  17. package/dist/chunk-WBSY6KRH.js +358 -0
  18. package/dist/cmath/index.d.ts +57 -0
  19. package/dist/cmath/index.js +187 -0
  20. package/dist/cmp.d.ts +11 -0
  21. package/dist/cmp.js +12 -0
  22. package/dist/csv.d.ts +3 -0
  23. package/dist/csv.js +16 -0
  24. package/dist/easing.d.ts +37 -0
  25. package/dist/easing.js +157 -0
  26. package/dist/events.d.ts +20 -0
  27. package/dist/events.js +67 -0
  28. package/dist/fn/index.d.ts +66 -0
  29. package/dist/fn/index.js +25 -0
  30. package/dist/gfx/index.d.ts +13 -0
  31. package/dist/gfx/index.js +68 -0
  32. package/dist/iter/index.d.ts +226 -0
  33. package/dist/iter/index.js +65 -0
  34. package/dist/math/index.d.ts +463 -0
  35. package/dist/math/index.js +129 -0
  36. package/dist/object.d.ts +72 -0
  37. package/dist/object.js +24 -0
  38. package/dist/random.d.ts +68 -0
  39. package/dist/random.js +22 -0
  40. package/dist/string/index.d.ts +62 -0
  41. package/dist/string/index.js +98 -0
  42. package/dist/structs/index.d.ts +184 -0
  43. package/dist/structs/index.js +24 -0
  44. package/dist/time/index.d.ts +35 -0
  45. package/dist/time/index.js +84 -0
  46. package/dist/types.d.ts +21 -0
  47. package/dist/types.js +1 -0
  48. package/dist/vec3-D7Wuy2AZ.d.ts +70 -0
  49. package/package.json +111 -0
@@ -0,0 +1,68 @@
1
+ import { int, uint } from './types.js';
2
+
3
+ /**
4
+ * @module
5
+ * Random number and array utilities
6
+ */
7
+
8
+ /**
9
+ * Returns a random number from 0 to a maximum non-inclusive
10
+ * @param max default 1
11
+ */
12
+ declare function random(max?: number): number;
13
+ /**
14
+ * Returns a random number from a minimum inclusive to a maximum non-inclusive
15
+ * @param min
16
+ * @param max
17
+ */
18
+ declare function random(min?: number, max?: number): number;
19
+ /**
20
+ * Returns a random number from 0 to a maximum inclusive
21
+ * @param max default 1
22
+ */
23
+ declare function randomInt(max?: int): int;
24
+ /**
25
+ * Returns a random number from a minimum inclusive to a maximum inclusive
26
+ * @param min
27
+ * @param max
28
+ */
29
+ declare function randomInt(min: int, max: int): int;
30
+ /**
31
+ * Randomizes the order of items in an array in-place
32
+ * @param array
33
+ * @returns the original array
34
+ */
35
+ declare function shuffle<T extends ArrayLike<unknown>>(array: T): T;
36
+ /**
37
+ * Chooses a random character from a string
38
+ * @param string
39
+ */
40
+ declare function choice(string: string): string;
41
+ /**
42
+ * Chooses a random item from an array
43
+ * @param array
44
+ */
45
+ declare function choice<T>(array: ArrayLike<T>): T | undefined;
46
+ /**
47
+ * Get random characters from a string
48
+ * @param string
49
+ * @param n number of characters to pick
50
+ * @returns a string of the random chars
51
+ */
52
+ declare function choices(string: string, n: uint): string;
53
+ /**
54
+ * Get random items from an array
55
+ * @param array
56
+ * @param n number of items to pick
57
+ * @returns an array containing the random items
58
+ */
59
+ declare function choices<T>(array: ArrayLike<T>, n: uint): T[];
60
+ /**
61
+ * Chooses unique random items from an array
62
+ * @param array
63
+ * @param n number of items to pick
64
+ * @returns an array containing the random items
65
+ */
66
+ declare function sample<T>(array: ArrayLike<T> & Iterable<T>, n: uint): T[];
67
+
68
+ export { choice, choices, random, randomInt, sample, shuffle };
package/dist/random.js ADDED
@@ -0,0 +1,22 @@
1
+ import {
2
+ choice,
3
+ choices,
4
+ random,
5
+ randomInt,
6
+ sample,
7
+ shuffle
8
+ } from "./chunk-EWSJTMH2.js";
9
+ import "./chunk-ILLWUQPY.js";
10
+ import "./chunk-WBSY6KRH.js";
11
+ import "./chunk-MG5VQSTV.js";
12
+ import "./chunk-6F4PWJZI.js";
13
+ import "./chunk-TMLWLR46.js";
14
+ import "./chunk-LJSF3QBT.js";
15
+ export {
16
+ choice,
17
+ choices,
18
+ random,
19
+ randomInt,
20
+ sample,
21
+ shuffle
22
+ };
@@ -0,0 +1,62 @@
1
+ declare const lowercase = "abcdefghijklmnopqrstuvwxyz";
2
+ declare const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
3
+ declare const letters: string;
4
+ declare const digits = "0123456789";
5
+ declare const hexdigits: `0123456789abcdefABCDEF`;
6
+ declare const octdigits = "01234567";
7
+
8
+ /**
9
+ * Joins a list of strings into a single string, using a conjunction before the last item.
10
+ * @param items an array of strings
11
+ * @param conjunction the word to use before the last item
12
+ * @example
13
+ * ```ts
14
+ * listItems(["apples", "oranges", "bananas"]); // "apples, oranges, and bananas"
15
+ * listItems(["apples", "oranges", "bananas"], "or"); // "apples, oranges, or bananas"
16
+ * ```
17
+ */
18
+ declare function listItems(items: string[], conjunction?: string): string;
19
+
20
+ /**
21
+ * Capitalizes the first character in the word
22
+ * @param word a string
23
+ */
24
+ declare function capitalize<T extends string>(word: T): Capitalize<T>;
25
+ declare function pluralize<S extends string>(word: S, n: number): S | `${S}s`;
26
+ declare function pluralize<S extends string, P extends string>(word: S, n: number, plural: P): S | P;
27
+ declare function quantify<S extends string>(word: S, n: number): string;
28
+ declare function quantify<S extends string, P extends string>(word: S, quantity: number, plural: P): string;
29
+ /**
30
+ * Capitalizes the first character in each word
31
+ * @exmaple
32
+ * ```ts
33
+ * titalize("hello world"); // "Hello World"
34
+ * ```
35
+ */
36
+ declare function titalize(str: string): string;
37
+
38
+ /**
39
+ * @module
40
+ * String utility functions
41
+ */
42
+
43
+ /**
44
+ * Splits a string only one time
45
+ * @param str the string to split
46
+ * @param separator a string to search for
47
+ * @return a tuple containing a substring before the separator and a substring after the separator
48
+ * the return tuple will always have at least 1 item, which will just be the str if no separator was found
49
+ * @example
50
+ * ```ts
51
+ * const str = "abc_def_ghi";
52
+ * console.log(splitOnce(str, '_')); // ["abc", "def_ghi"]
53
+ * console.log(splitOnce(str, '+')); // ["abc_def_ghi"]
54
+ * ```
55
+ */
56
+ declare function splitOnce(str: string, separator: string): [before: string, after?: string];
57
+ declare function reverse(str: string): string;
58
+ declare function replace(str: string, replacements: Record<string, string>): string;
59
+ declare const escapeInRegexRegex: RegExp;
60
+ declare function escapeRegex(regexStr: string): string;
61
+
62
+ export { capitalize, digits, escapeInRegexRegex, escapeRegex, hexdigits, letters, listItems, lowercase, octdigits, pluralize, quantify, replace, reverse, splitOnce, titalize, uppercase };
@@ -0,0 +1,98 @@
1
+ // src/string/constants.ts
2
+ var lowercase = "abcdefghijklmnopqrstuvwxyz";
3
+ var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
4
+ var letters = lowercase + uppercase;
5
+ var digits = "0123456789";
6
+ var hexdigits = `${digits}abcdefABCDEF`;
7
+ var octdigits = "01234567";
8
+
9
+ // src/string/list.ts
10
+ function listItems(items, conjunction = "and") {
11
+ switch (items.length) {
12
+ case 0: {
13
+ return "";
14
+ }
15
+ case 1: {
16
+ return items[0] || "";
17
+ }
18
+ case 2: {
19
+ return items.join(` ${conjunction} `);
20
+ }
21
+ default: {
22
+ return `${items.slice(0, -1).join(", ")}, ${conjunction} ${items.at(-1)}`;
23
+ }
24
+ }
25
+ }
26
+
27
+ // src/string/word.ts
28
+ function capitalize(word) {
29
+ const first = word[0] || "";
30
+ return first.toUpperCase() + word.slice(1);
31
+ }
32
+ function pluralize(word, n, plural) {
33
+ if (n === 1) {
34
+ return word;
35
+ }
36
+ if (plural) {
37
+ return plural;
38
+ }
39
+ return `${word}s`;
40
+ }
41
+ function quantify(word, quantity, plural) {
42
+ return `${quantity} ${plural ? pluralize(word, quantity, plural) : pluralize(word, quantity)}`;
43
+ }
44
+ function titalize(str) {
45
+ return str.split(" ").map((word) => capitalize(word)).join(" ");
46
+ }
47
+
48
+ // src/string/index.ts
49
+ function splitOnce(str, separator) {
50
+ if (!str) {
51
+ return [""];
52
+ }
53
+ if (!separator) {
54
+ if (str.length < 2) {
55
+ return [str];
56
+ }
57
+ return [str[0], str.slice(1)];
58
+ }
59
+ const index = str.indexOf(separator);
60
+ if (index === -1) {
61
+ return [str];
62
+ }
63
+ const before = str.slice(0, index);
64
+ const after = str.slice(index + separator.length);
65
+ return [before, after];
66
+ }
67
+ function reverse(str) {
68
+ return [...str].reverse().join("");
69
+ }
70
+ function replace(str, replacements) {
71
+ const regex = new RegExp(
72
+ Object.keys(replacements).map(escapeRegex).join("|"),
73
+ "g"
74
+ );
75
+ return str.replace(regex, (matched) => replacements[matched] || "");
76
+ }
77
+ var escapeInRegexRegex = /[$()*+./?[\\\]^{|}-]/g;
78
+ function escapeRegex(regexStr) {
79
+ return regexStr.replaceAll(escapeInRegexRegex, "\\$&");
80
+ }
81
+ export {
82
+ capitalize,
83
+ digits,
84
+ escapeInRegexRegex,
85
+ escapeRegex,
86
+ hexdigits,
87
+ letters,
88
+ listItems,
89
+ lowercase,
90
+ octdigits,
91
+ pluralize,
92
+ quantify,
93
+ replace,
94
+ reverse,
95
+ splitOnce,
96
+ titalize,
97
+ uppercase
98
+ };
@@ -0,0 +1,184 @@
1
+ import { uint, int } from '../types.js';
2
+ import { Compare } from '../cmp.js';
3
+
4
+ interface Node$1<T> {
5
+ value: T;
6
+ next?: Node$1<T>;
7
+ prev?: Node$1<T>;
8
+ }
9
+ declare class DoublyLinkedList<T> implements Iterable<T> {
10
+ private head?;
11
+ private tail?;
12
+ private size;
13
+ static from<T>(values: Iterable<T>): DoublyLinkedList<T>;
14
+ get length(): uint;
15
+ [Symbol.iterator](): Iterator<T>;
16
+ getNode(index: uint): Node$1<T> | undefined;
17
+ get(index: uint): T | undefined;
18
+ set(index: uint, value: T): T | undefined;
19
+ push(value: T): uint;
20
+ pop(): T | undefined;
21
+ unshift(value: T): uint;
22
+ shift(): T | undefined;
23
+ reverse(): this;
24
+ remove(index: uint): T | undefined;
25
+ splice(index: uint, count: uint, ...values: T[]): T[];
26
+ }
27
+
28
+ /**
29
+ * ## Binary Heap
30
+ * A tree in which any given node is the max or min of its children
31
+ *
32
+ * | Method | Average Case | Worst Case |
33
+ * | ----------- | ------------ | ---------- |
34
+ * | peek() | O(1) | O(1) |
35
+ * | pop() | O(log n) | O(log n) |
36
+ * | push(value) | O(1) | O(log n) |
37
+ *
38
+ * @see https://en.wikipedia.org/wiki/Heap_(data_structure)
39
+ */
40
+ declare class Heap<T> implements Iterable<T> {
41
+ readonly compare: Compare<T>;
42
+ data: T[];
43
+ constructor(compare: Compare<T>, data?: T[], heapify?: boolean);
44
+ get length(): uint;
45
+ get height(): uint;
46
+ valueOf(): T | undefined;
47
+ copy(): Heap<T>;
48
+ /**
49
+ * Returns the first value in the heap
50
+ */
51
+ peek(): T | undefined;
52
+ /**
53
+ * Removes the first value from the heap and returns it
54
+ */
55
+ pop(): T | undefined;
56
+ /**
57
+ * Inserts values into the heap and makes sure the first value is the min/max
58
+ * @param values
59
+ * @returns The new length of the heap
60
+ */
61
+ push(...values: T[]): uint;
62
+ drain(): Generator<T>;
63
+ [Symbol.iterator](): Iterator<T>;
64
+ protected heapify(i?: number): void;
65
+ }
66
+
67
+ declare class MaxHeap<T> extends Heap<T> {
68
+ constructor(data?: T[], heapify?: boolean);
69
+ copy(): MaxHeap<T>;
70
+ }
71
+
72
+ declare class MinHeap<T> extends Heap<T> {
73
+ constructor(data?: T[], heapify?: boolean);
74
+ copy(): MinHeap<T>;
75
+ }
76
+
77
+ interface Node<T> {
78
+ value: T;
79
+ next?: Node<T>;
80
+ }
81
+ declare class LinkedList<T> implements Iterable<T> {
82
+ node?: Node<T>;
83
+ static from<T>(values: Iterable<T>): LinkedList<T>;
84
+ get length(): uint;
85
+ [Symbol.iterator](): Iterator<T>;
86
+ get tail(): Node<T> | undefined;
87
+ getNode(index: uint): Node<T> | undefined;
88
+ get(index: uint): T | undefined;
89
+ set(index: uint, value: T): T | undefined;
90
+ push(value: T): void;
91
+ pop(): Node<T> | undefined;
92
+ unshift(value: T): void;
93
+ shift(): Node<T> | undefined;
94
+ }
95
+
96
+ /**
97
+ * ## Queue
98
+ * A data structure that follows a first-in-first-out (FIFO) order
99
+ *
100
+ * | Method | Average Case | Worst Case |
101
+ * | ----------- | ------------ | ---------- |
102
+ * | enqueue() | O(1) | O(1) |
103
+ * | dequeue() | O(1) | O(1) |
104
+ *
105
+ * @see https://en.wikipedia.org/wiki/Queue_(abstract_data_type)
106
+ */
107
+ declare class Queue<T> implements Iterable<T> {
108
+ protected items: T[];
109
+ constructor(items?: T[]);
110
+ get size(): uint;
111
+ enqueue(item: T): uint;
112
+ dequeue(): T | undefined;
113
+ [Symbol.iterator](): Iterator<T>;
114
+ }
115
+
116
+ /**
117
+ * ## Sorted Array
118
+ * An array that maintains sorted order
119
+ *
120
+ * | Method | Average Case | Worst Case |
121
+ * | -------------- | ------------ | ---------- |
122
+ * | indexOf(value) | O(log n) | O(log n) |
123
+ * | has(value) | O(log n) | O(log n) |
124
+ * | push(value) | O(n) | O(n) |
125
+ *
126
+ * @see https://en.wikipedia.org/wiki/Sorted_array
127
+ */
128
+ declare class SortedArray<T> implements Iterable<T> {
129
+ private readonly data;
130
+ readonly compare: Compare<T>;
131
+ constructor(data?: T[], compare?: Compare<T>, sort?: boolean);
132
+ valueOf(): T | undefined;
133
+ keys(): IterableIterator<uint>;
134
+ values(): IterableIterator<T>;
135
+ entries(): IterableIterator<[uint, T]>;
136
+ [Symbol.iterator](): IterableIterator<T>;
137
+ length(): uint;
138
+ at(index: uint): T | undefined;
139
+ copy(): SortedArray<T>;
140
+ /**
141
+ * Returns the index of the value if it exists, otherwise -1
142
+ * @param value
143
+ */
144
+ indexOf(value: T): int;
145
+ /**
146
+ * Returns if the array has the value
147
+ * @param value
148
+ */
149
+ has(value: T): boolean;
150
+ /**
151
+ * Binary inserts a value into the array while maintaining sorted order
152
+ * @param value
153
+ * @returns the index of where the value was inserted
154
+ */
155
+ push(value: T): uint;
156
+ }
157
+
158
+ /**
159
+ * ## Unordered Array
160
+ * An array that maintains no order
161
+ */
162
+ declare class UnorderedArray<T> extends Array<T> {
163
+ copy(): UnorderedArray<T>;
164
+ /**
165
+ * Inserts new elements at the end of an unordered array, and returns the new length of the unordered array.
166
+ * @param items Elements to insert at the end of the array.
167
+ */
168
+ unshift(...items: T[]): uint;
169
+ /**
170
+ * Removes the last element from an array and returns it.
171
+ * If the array is empty, undefined is returned and the array is not modified.
172
+ */
173
+ shift(): T | undefined;
174
+ /**
175
+ * Removes an item by index
176
+ * @param index the index of the item to remove
177
+ * @returns the removed item, if it exists
178
+ */
179
+ removeIndex(index: uint): T | undefined;
180
+ splice(start: uint, deleteCount?: number, ...items: T[]): T[];
181
+ toSpliced(start: uint, deleteCount?: number, ...items: T[]): T[];
182
+ }
183
+
184
+ export { DoublyLinkedList, LinkedList, MaxHeap, MinHeap, Queue, SortedArray, UnorderedArray };
@@ -0,0 +1,24 @@
1
+ import {
2
+ DoublyLinkedList,
3
+ LinkedList,
4
+ MaxHeap,
5
+ MinHeap,
6
+ Queue,
7
+ SortedArray,
8
+ UnorderedArray
9
+ } from "../chunk-DO4NH5XG.js";
10
+ import "../chunk-ILLWUQPY.js";
11
+ import "../chunk-WBSY6KRH.js";
12
+ import "../chunk-MG5VQSTV.js";
13
+ import "../chunk-6F4PWJZI.js";
14
+ import "../chunk-TMLWLR46.js";
15
+ import "../chunk-LJSF3QBT.js";
16
+ export {
17
+ DoublyLinkedList,
18
+ LinkedList,
19
+ MaxHeap,
20
+ MinHeap,
21
+ Queue,
22
+ SortedArray,
23
+ UnorderedArray
24
+ };
@@ -0,0 +1,35 @@
1
+ declare const SECOND = 1000;
2
+ declare const MINUTE: number;
3
+ declare const HOUR: number;
4
+ declare const DAY: number;
5
+ declare const WEEK: number;
6
+
7
+ interface DurationLike {
8
+ readonly years?: number;
9
+ readonly months?: number;
10
+ readonly weeks?: number;
11
+ readonly days?: number;
12
+ readonly hours?: number;
13
+ readonly minutes?: number;
14
+ readonly seconds?: number;
15
+ readonly milliseconds?: number;
16
+ }
17
+ declare function addDuration(date: Date, { years, days, months, hours, minutes, seconds, milliseconds }: DurationLike): Date;
18
+ declare function subtractDuration(date: Date, { years, days, months, hours, minutes, seconds, milliseconds }: DurationLike): Date;
19
+ declare const stripTime: (date: Date) => Date;
20
+ declare const getToday: () => Date;
21
+ declare const getTomorrow: () => Date;
22
+ declare const getYesterday: () => Date;
23
+ /**
24
+ * Determines if two dates are the same day, ignoring time
25
+ * @param a
26
+ * @param b
27
+ */
28
+ declare function sameDay(a: Date, b: Date): boolean;
29
+ /**
30
+ * Checks if a date is valid
31
+ * @param date
32
+ */
33
+ declare function validDate(date: Date): boolean;
34
+
35
+ export { DAY, type DurationLike, HOUR, MINUTE, SECOND, WEEK, addDuration, getToday, getTomorrow, getYesterday, sameDay, stripTime, subtractDuration, validDate };
@@ -0,0 +1,84 @@
1
+ // src/time/consts.ts
2
+ var SECOND = 1e3;
3
+ var MINUTE = 60 * SECOND;
4
+ var HOUR = 60 * MINUTE;
5
+ var DAY = 24 * HOUR;
6
+ var WEEK = 7 * DAY;
7
+
8
+ // src/time/date.ts
9
+ function addDuration(date, { years, days, months, hours, minutes, seconds, milliseconds }) {
10
+ const newDate = new Date(date);
11
+ if (years) {
12
+ newDate.setFullYear(newDate.getFullYear() + years);
13
+ }
14
+ if (months) {
15
+ newDate.setMonth(newDate.getMonth() + months);
16
+ }
17
+ if (days) {
18
+ newDate.setDate(newDate.getDate() + days);
19
+ }
20
+ if (hours) {
21
+ newDate.setHours(newDate.getHours() + hours);
22
+ }
23
+ if (minutes) {
24
+ newDate.setMinutes(newDate.getMinutes() + minutes);
25
+ }
26
+ if (seconds) {
27
+ newDate.setSeconds(newDate.getSeconds() + seconds);
28
+ }
29
+ if (milliseconds) {
30
+ newDate.setMilliseconds(newDate.getMilliseconds() + milliseconds);
31
+ }
32
+ return newDate;
33
+ }
34
+ function subtractDuration(date, { years, days, months, hours, minutes, seconds, milliseconds }) {
35
+ const newDate = new Date(date);
36
+ if (years) {
37
+ newDate.setFullYear(newDate.getFullYear() - years);
38
+ }
39
+ if (days) {
40
+ newDate.setDate(newDate.getDate() - days);
41
+ }
42
+ if (months) {
43
+ newDate.setMonth(newDate.getMonth() - months);
44
+ }
45
+ if (hours) {
46
+ newDate.setHours(newDate.getHours() - hours);
47
+ }
48
+ if (minutes) {
49
+ newDate.setMinutes(newDate.getMinutes() - minutes);
50
+ }
51
+ if (seconds) {
52
+ newDate.setSeconds(newDate.getSeconds() - seconds);
53
+ }
54
+ if (milliseconds) {
55
+ newDate.setMilliseconds(newDate.getMilliseconds() - milliseconds);
56
+ }
57
+ return newDate;
58
+ }
59
+ var stripTime = (date) => new Date(date.getFullYear(), date.getMonth(), date.getDate());
60
+ var getToday = () => stripTime(/* @__PURE__ */ new Date());
61
+ var getTomorrow = () => addDuration(getToday(), { days: 1 });
62
+ var getYesterday = () => subtractDuration(getToday(), { days: 1 });
63
+ function sameDay(a, b) {
64
+ return a.getDate() === b.getDate() && a.getMonth() === b.getMonth() && a.getFullYear() === b.getFullYear();
65
+ }
66
+ function validDate(date) {
67
+ const millis = date.getTime();
68
+ return !Number.isNaN(millis);
69
+ }
70
+ export {
71
+ DAY,
72
+ HOUR,
73
+ MINUTE,
74
+ SECOND,
75
+ WEEK,
76
+ addDuration,
77
+ getToday,
78
+ getTomorrow,
79
+ getYesterday,
80
+ sameDay,
81
+ stripTime,
82
+ subtractDuration,
83
+ validDate
84
+ };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @module
3
+ * Useful utility types for Typescript
4
+ */
5
+ type Primitive = string | number | boolean | bigint | symbol | undefined | null;
6
+ type int = number;
7
+ type uint = number;
8
+ type Maybe<T> = T | undefined;
9
+ type Nullish<T> = Maybe<T> | null;
10
+ type AnyRecord = Record<PropertyKey, any>;
11
+ type AnyFunction = (...args: any[]) => any;
12
+ type MaybeArray<T> = T | T[];
13
+ type MaybeReadonlyArray<T> = T | readonly T[];
14
+ type Dict<T> = Record<string, T>;
15
+ type Indexable<T> = Record<number, T>;
16
+ type Result<T, E = Error> = [T, undefined] | [undefined, E];
17
+ type Awaitable<T> = T | Promise<T>;
18
+ type NonFalsy<T> = T extends false | 0 | "" | null | undefined | 0n ? never : T;
19
+ type Repeat<T, N extends number> = N extends 0 ? [] : N extends 1 ? [T] : N extends 2 ? [T, T] : N extends 3 ? [T, T, T] : N extends 4 ? [T, T, T, T] : N extends 5 ? [T, T, T, T, T] : N extends 6 ? [T, T, T, T, T, T] : N extends 7 ? [T, T, T, T, T, T, T] : N extends 8 ? [T, T, T, T, T, T, T, T] : N extends 9 ? [T, T, T, T, T, T, T, T, T] : N extends 10 ? [T, T, T, T, T, T, T, T, T, T] : T[];
20
+
21
+ export type { AnyFunction, AnyRecord, Awaitable, Dict, Indexable, Maybe, MaybeArray, MaybeReadonlyArray, NonFalsy, Nullish, Primitive, Repeat, Result, int, uint };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ import "./chunk-6F4PWJZI.js";
@@ -0,0 +1,70 @@
1
+ interface Vec extends Float32Array {
2
+ toString: () => string;
3
+ copy: () => Vec;
4
+ mag: () => number;
5
+ setMag: (n: number) => this;
6
+ magSq: () => number;
7
+ limit: (max: number) => this;
8
+ normalize: () => this;
9
+ }
10
+
11
+ type Vec3Like = [x: number, y: number, z: number] | Float32Array;
12
+ type ReadonlyVec3Like = Readonly<Vec3Like>;
13
+ type First = ReadonlyVec3Like | number;
14
+ declare class Vec3 extends Float32Array implements Vec {
15
+ static readonly BYTE_LENGTH: number;
16
+ constructor(x?: First, y?: number, z?: number);
17
+ get x(): number;
18
+ set x(value: number);
19
+ get y(): number;
20
+ set y(value: number);
21
+ get z(): number;
22
+ set z(value: number);
23
+ get r(): number;
24
+ set r(value: number);
25
+ get g(): number;
26
+ set g(value: number);
27
+ get b(): number;
28
+ set b(value: number);
29
+ toString(): string;
30
+ copy(): Vec3;
31
+ static random(mag?: number): Vec3;
32
+ eq(x: First, y?: number, z?: number): boolean;
33
+ neg(): Vec3;
34
+ add(x: First, y?: number, z?: number): this;
35
+ static add(v1: Vec3, x: First, y?: number, z?: number): Vec3;
36
+ sub(x: First, y?: number, z?: number): this;
37
+ static sub(v1: Vec3, x: First, y?: number, z?: number): Vec3;
38
+ mul(x: First, y?: number, z?: number): this;
39
+ static mul(v1: Vec3, x: First, y?: number, z?: number): Vec3;
40
+ div(x: First, y?: number, z?: number): this;
41
+ static div(v1: Vec3, x: First, y?: number, z?: number): Vec3;
42
+ static fma(a: ReadonlyVec3Like, b: ReadonlyVec3Like, c: ReadonlyVec3Like): Vec3;
43
+ lt(x: ReadonlyVec3Like): Vec3;
44
+ lte(x: ReadonlyVec3Like): Vec3;
45
+ gt(x: ReadonlyVec3Like): Vec3;
46
+ gte(x: ReadonlyVec3Like): Vec3;
47
+ limit(max: number): this;
48
+ normalize(): this;
49
+ static normalize(v: Vec3): Vec3;
50
+ mag(): number;
51
+ setMag(n: number): this;
52
+ magSq(): number;
53
+ dist(v: Vec3): number;
54
+ distSq(v: Vec3): number;
55
+ dot(v: ReadonlyVec3Like): number;
56
+ cross(v: ReadonlyVec3Like): Vec3;
57
+ lerp(v: ReadonlyVec3Like, norm: number): this;
58
+ static lerp(v1: Vec3, v2: ReadonlyVec3Like, norm: number): Vec3;
59
+ clamp(min: ReadonlyVec3Like, max: ReadonlyVec3Like): this;
60
+ static clamp(v: Vec3, min: ReadonlyVec3Like, max: ReadonlyVec3Like): Vec3;
61
+ rotateX(angle: number): this;
62
+ rotateY(angle: number): this;
63
+ rotateZ(angle: number): this;
64
+ reflect(normal: Vec3): this;
65
+ static reflect(v: Vec3, normal: Vec3): Vec3;
66
+ refract(normal: Vec3, eta: number): this;
67
+ }
68
+ declare function vec3(x?: First, y?: number, z?: number): Vec3;
69
+
70
+ export { type ReadonlyVec3Like as R, Vec3 as V, type Vec as a, type Vec3Like as b, vec3 as v };