@xaendar/common 0.0.4 → 0.1.0

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/package.json CHANGED
@@ -1,8 +1,17 @@
1
- {
2
- "name": "@xaendar/common",
3
- "version": "0.0.4",
4
- "type": "module",
5
- "author": "Kaitenjo",
6
- "license": "MIT",
7
- "description": "A library containing common utils and types"
8
- }
1
+ {
2
+ "name": "@xaendar/common",
3
+ "version": "0.1.0",
4
+ "description": "A library containing common utils and types",
5
+ "type": "module",
6
+ "main": "./xaendar-common.es.js",
7
+ "module": "./xaendar-common.es.js",
8
+ "types": "./xaendar-common.es.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./xaendar-common.es.js",
12
+ "types": "./xaendar-common.es.d.ts"
13
+ }
14
+ },
15
+ "peerDependencies": {},
16
+ "dependencies": {}
17
+ }
@@ -0,0 +1,165 @@
1
+ /**
2
+ * A type representing an abstract constructor function for a given type T.
3
+ * This type can be used to define abstract classes.
4
+ */
5
+ export declare type AbstractConstructor<T extends Object = Object> = abstract new (...args: any[]) => T;
6
+
7
+ /**
8
+ * An abstract constructor function type that can accept any number of arguments
9
+ * and return an instance of the specified type.
10
+ */
11
+ export declare type AbstractConstructorFunction<T extends object = object, Statics extends Record<string, unknown> | undefined = undefined> = (abstract new (...args: any[]) => T) & (Statics extends undefined ? object : Statics);
12
+
13
+ export declare type AccessorDecorator<Class extends Object, Field = unknown, ReturnTypeField = Field> = (value: ClassAccessorDecoratorValue<Field>, context: ClassAccessorDecoratorContext<Class, ReturnTypeField>) => {
14
+ get?: () => ReturnTypeField;
15
+ set?: (value: ReturnTypeField) => void;
16
+ init?: (initialValue: Field) => ReturnTypeField;
17
+ } | void;
18
+
19
+ /**
20
+ * A function type that can accept any number of arguments and return a promise of any type.
21
+ */
22
+ export declare type AsyncFunction<Arguments extends any[] = any[], ReturnType = void> = Arguments extends Array<any> ? (...args: Arguments) => Promise<ReturnType> : () => Promise<ReturnType>;
23
+
24
+ /**
25
+ * An async function type that accepts arguments but always resolves to void.
26
+ * Typically used for async callbacks or side-effect functions.
27
+ * @template Arguments - The types of the function arguments
28
+ * @example
29
+ * type OnUserChangeAsync = AsyncVoidFunction<[user: User]>;
30
+ * const handleUserChangeAsync: OnUserChangeAsync = async (user) => await api.logChange(user);
31
+ */
32
+ export declare type AsyncVoidFunction<Arguments extends any[] = any[]> = (...args: Arguments) => Promise<void>;
33
+
34
+ export declare type Beautify<T extends Object> = {
35
+ [K in keyof T]: T[K];
36
+ } & {};
37
+
38
+ export declare type ClassAccessorDecoratorValue<Field = unknown> = {
39
+ get?: () => Field;
40
+ set: (value: Field) => void;
41
+ };
42
+
43
+ declare type ClassDecorator_2<T extends Object, Statics extends {
44
+ [key: string]: any;
45
+ } = {
46
+ [key: string]: any;
47
+ }> = (klass: Constructor<T, Statics>, context: ClassDecoratorContext) => void;
48
+ export { ClassDecorator_2 as ClassDecorator }
49
+
50
+ /**
51
+ * A type representing a constructor function for a given type T.
52
+ * This type can be used to define classes or factory functions
53
+ */
54
+ export declare type Constructor<T extends Object = Object, Statics extends Record<string, unknown> = {}> = (new (...args: any[]) => T) & Statics;
55
+
56
+ /**
57
+ * A constructor function type that can accept any number of arguments and return an instance of any type.
58
+ */
59
+ export declare type ConstructorFunction<T extends object = object, Statics extends Record<string, unknown> | undefined = undefined> = (new (...args: any[]) => T) & (Statics extends undefined ? object : Statics);
60
+
61
+ export declare type ContainsChar<String extends string, Contains extends string> = String extends `${infer First}${infer Rest}` ? First extends Contains ? true : ContainsChar<Rest, Contains> : false;
62
+
63
+ export declare type Dictionary<Key extends string | number, Value> = {
64
+ [K in Key]?: Value;
65
+ };
66
+
67
+ export declare type FieldDecorator<Class extends Object, Field, ReturnType = Field> = (field: undefined, context: ClassFieldDecoratorContext<Class, Field>) => ((value: Field) => ReturnType);
68
+
69
+ /**
70
+ * A function type that can accept any number of arguments and return any type.
71
+ */
72
+ declare type Function_2<Arguments extends any[] = any[], ReturnType = void> = Arguments extends Array<any> ? (...args: Arguments) => ReturnType : () => ReturnType;
73
+ export { Function_2 as Function }
74
+
75
+ declare type MethodDecorator_2<T extends Object, Method extends Function_2> = (value: Method, context: ClassMethodDecoratorContext<T, Method>) => Method | void;
76
+ export { MethodDecorator_2 as MethodDecorator }
77
+
78
+ export declare type Mutable<T extends Object> = {
79
+ -readonly [P in keyof T]: T[P];
80
+ };
81
+
82
+ /**
83
+ * An async function type that accepts no arguments and returns a promise of the specified type.
84
+ * @template ReturnType - The type that the promise resolves to (defaults to void)
85
+ * @example
86
+ * type FetchUser = AsyncFunctionNoArgs<User>;
87
+ * const fetchUser: FetchUser = async () => await api.getUser();
88
+ */
89
+ export declare type NoArgsAsyncFunction<ReturnType = void> = () => Promise<ReturnType>;
90
+
91
+ /**
92
+ * An async function type that accepts arguments but always resolves to void.
93
+ */
94
+ export declare type NoArgsAsyncVoidFunction = () => Promise<void>;
95
+
96
+ /**
97
+ * A function type that accepts no arguments and returns a value of the specified type.
98
+ * Also known as a 'thunk' in functional programming.
99
+ * @template ReturnType - The return type of the function (defaults to void)
100
+ * @example
101
+ * type GetUser = FunctionNoArgs<User>;
102
+ * const getUser: GetUser = () => ({ id: 1, name: 'John' });
103
+ */
104
+ export declare type NoArgsFunction<ReturnType = void> = () => ReturnType;
105
+
106
+ /**
107
+ * A function type that accepts arguments but always returns void.
108
+ */
109
+ export declare type NoArgsVoidFunction = () => void;
110
+
111
+ export declare type PositiveInteger<Value extends number> = ContainsChar<`${Value}`, '-'> extends true ? never : ContainsChar<`${Value}`, '.'> extends true ? never : Value;
112
+
113
+ export declare type RequireOne<T extends Object, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
114
+ [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
115
+ }[Keys];
116
+
117
+ /**
118
+ * A generic LIFO (Last In, First Out) stack data structure.
119
+ *
120
+ * @template T - The type of elements held in the stack. Defaults to `unknown`.
121
+ */
122
+ export declare class Stack<T = unknown> {
123
+ /**
124
+ * Internal array holding the stack elements, ordered from bottom to top.
125
+ */
126
+ private _elements;
127
+ [index: number]: T;
128
+ constructor();
129
+ /**
130
+ * The number of elements currently in the stack.
131
+ */
132
+ get length(): number;
133
+ /**
134
+ * A shallow copy of the elements in the stack, ordered from bottom to top.
135
+ */
136
+ get values(): T[];
137
+ /**
138
+ * Removes and returns the top element of the stack.
139
+ *
140
+ * @returns The top element, or `undefined` if the stack is empty.
141
+ */
142
+ pop(): T | undefined;
143
+ /**
144
+ * Pushes an element onto the top of the stack.
145
+ *
146
+ * @param element - The element to push.
147
+ * @returns The new length of the stack.
148
+ */
149
+ push(element: T): number;
150
+ }
151
+
152
+ export declare type TupleOfLength<Length extends number, TupleType = number, Acc extends TupleType[] = []> = PositiveInteger<Length> extends never ? never : Acc['length'] extends Length ? Acc : TupleOfLength<Length, TupleType, [...Acc, TupleType]>;
153
+
154
+ /**
155
+ * A function type that accepts arguments but always returns void.
156
+ * Typically used for callbacks, event handlers, or side-effect functions.
157
+ * @template Arguments - The types of the function arguments
158
+ * @example
159
+ * type OnUserChange = VoidFunction<[user: User]>;
160
+ * const handleUserChange: OnUserChange = (user) => console.log(user);
161
+ */
162
+ declare type VoidFunction_2<Arguments extends any[] = any[]> = (...args: Arguments) => void;
163
+ export { VoidFunction_2 as VoidFunction }
164
+
165
+ export { }
@@ -0,0 +1,25 @@
1
+ //#region ../packages/common/src/models/stack/stack.model.ts
2
+ var e = class {
3
+ _elements = [];
4
+ constructor() {
5
+ return new Proxy(this, { get(e, t) {
6
+ if (typeof t == "string") return isNaN(Number(t)) ? e[t] : e._elements[Number(t)];
7
+ } });
8
+ }
9
+ get length() {
10
+ return this._elements.length;
11
+ }
12
+ get values() {
13
+ return [...this._elements];
14
+ }
15
+ pop() {
16
+ return this._elements.pop();
17
+ }
18
+ push(e) {
19
+ return this._elements.push(e);
20
+ }
21
+ };
22
+ //#endregion
23
+ export { e as Stack };
24
+
25
+ //# sourceMappingURL=xaendar-common.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xaendar-common.es.js","names":[],"sources":["../../../packages/common/src/models/stack/stack.model.ts"],"sourcesContent":["/**\r\n * A generic LIFO (Last In, First Out) stack data structure.\r\n *\r\n * @template T - The type of elements held in the stack. Defaults to `unknown`.\r\n */\r\nexport class Stack<T = unknown> {\r\n /**\r\n * Internal array holding the stack elements, ordered from bottom to top.\r\n */\r\n private _elements = new Array<T>;\r\n\r\n [index: number]: T;\r\n\r\n constructor() {\r\n return new Proxy(this, {\r\n get(target, prop) {\r\n if (typeof prop === 'string') {\r\n return isNaN(Number(prop)) ? (target as unknown as { [prop]: unknown })[prop] : target._elements[Number(prop)];\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * The number of elements currently in the stack.\r\n */\r\n public get length(): number {\r\n return this._elements.length;\r\n }\r\n\r\n /**\r\n * A shallow copy of the elements in the stack, ordered from bottom to top.\r\n */\r\n public get values(): T[] {\r\n return [...this._elements];\r\n }\r\n\r\n /**\r\n * Removes and returns the top element of the stack.\r\n *\r\n * @returns The top element, or `undefined` if the stack is empty.\r\n */\r\n public pop(): T | undefined {\r\n return this._elements.pop();\r\n }\r\n\r\n /**\r\n * Pushes an element onto the top of the stack.\r\n *\r\n * @param element - The element to push.\r\n * @returns The new length of the stack.\r\n */\r\n public push(element: T): number {\r\n return this._elements.push(element);\r\n }\r\n}"],"mappings":";AAKA,IAAa,IAAb,MAAgC;CAI9B,YAAoB,EAAY;CAIhC,cAAc;AACZ,SAAO,IAAI,MAAM,MAAM,EACrB,IAAI,GAAQ,GAAM;AAChB,OAAI,OAAO,KAAS,SAClB,QAAO,MAAM,OAAO,EAAK,CAAC,GAAI,EAA0C,KAAQ,EAAO,UAAU,OAAO,EAAK;KAGlH,CAAC;;CAMJ,IAAW,SAAiB;AAC1B,SAAO,KAAK,UAAU;;CAMxB,IAAW,SAAc;AACvB,SAAO,CAAC,GAAG,KAAK,UAAU;;CAQ5B,MAA4B;AAC1B,SAAO,KAAK,UAAU,KAAK;;CAS7B,KAAY,GAAoB;AAC9B,SAAO,KAAK,UAAU,KAAK,EAAQ"}
@@ -1,3 +0,0 @@
1
- export type Beautify<T extends Object> = {
2
- [K in keyof T]: T[K]
3
- } & {}
@@ -1,5 +0,0 @@
1
- /**
2
- * A type representing an abstract constructor function for a given type T.
3
- * This type can be used to define abstract classes.
4
- */
5
- export type AbstractConstructor<T extends Object = Object> = abstract new (...args: any[]) => T;
@@ -1,8 +0,0 @@
1
- /**
2
- * A type representing a constructor function for a given type T.
3
- * This type can be used to define classes or factory functions
4
- */
5
- export type Constructor<
6
- T extends Object = Object,
7
- Statics extends Record<string, unknown> = {}
8
- > = (new (...args: any[]) => T) & Statics;
@@ -1,9 +0,0 @@
1
- export type ContainsChar<
2
- String extends string,
3
- Contains extends string
4
- > =
5
- String extends `${infer First}${infer Rest}`
6
- ? First extends Contains
7
- ? true
8
- : ContainsChar<Rest, Contains>
9
- : false;
@@ -1,17 +0,0 @@
1
- export type AccessorDecorator<
2
- Class extends Object,
3
- Field = unknown,
4
- ReturnTypeField = Field
5
- > = (
6
- value: ClassAccessorDecoratorValue<Field>,
7
- context: ClassAccessorDecoratorContext<Class, ReturnTypeField>
8
- ) => {
9
- get?: () => ReturnTypeField;
10
- set?: (value: ReturnTypeField) => void;
11
- init?: (initialValue: Field) => ReturnTypeField;
12
- } | void;
13
-
14
- export type ClassAccessorDecoratorValue<Field = unknown> = {
15
- get?: () => Field;
16
- set: (value: Field) => void;
17
- };
@@ -1,6 +0,0 @@
1
- import { Constructor } from '../constructors/constructor.type';
2
-
3
- export type ClassDecorator<
4
- T extends Object,
5
- Statics extends { [key: string]: any } = { [key: string]: any }
6
- > = (klass: Constructor<T, Statics>, context: ClassDecoratorContext) => void
@@ -1,5 +0,0 @@
1
- export type FieldDecorator<
2
- Class extends Object,
3
- Field,
4
- ReturnType = Field
5
- > = (field: undefined, context: ClassFieldDecoratorContext<Class, Field>) => ((value: Field) => ReturnType);
@@ -1,6 +0,0 @@
1
- import { Function } from '../function.type';
2
-
3
- export type MethodDecorator<
4
- T extends Object,
5
- Method extends Function
6
- > = (value: Method, context: ClassMethodDecoratorContext<T, Method>) => Method | void;
@@ -1,3 +0,0 @@
1
- export type Dictionary<Key extends string | number, Value> = {
2
- [K in Key]?: Value
3
- }
@@ -1,86 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /**
3
- * A function type that can accept any number of arguments and return any type.
4
- */
5
- export type Function<
6
- Arguments extends any[] = any[],
7
- ReturnType = void
8
- > = Arguments extends Array<any>
9
- ? (...args: Arguments) => ReturnType
10
- : () => ReturnType;
11
-
12
- /**
13
- * A function type that can accept any number of arguments and return a promise of any type.
14
- */
15
- export type AsyncFunction<
16
- Arguments extends any[] = any[],
17
- ReturnType = void
18
- > = Arguments extends Array<any>
19
- ? (...args: Arguments) => Promise<ReturnType>
20
- : () => Promise<ReturnType>;
21
-
22
- /**
23
- * A function type that accepts no arguments and returns a value of the specified type.
24
- * Also known as a 'thunk' in functional programming.
25
- * @template ReturnType - The return type of the function (defaults to void)
26
- * @example
27
- * type GetUser = FunctionNoArgs<User>;
28
- * const getUser: GetUser = () => ({ id: 1, name: 'John' });
29
- */
30
- export type NoArgsFunction <ReturnType = void> = () => ReturnType;
31
-
32
- /**
33
- * An async function type that accepts no arguments and returns a promise of the specified type.
34
- * @template ReturnType - The type that the promise resolves to (defaults to void)
35
- * @example
36
- * type FetchUser = AsyncFunctionNoArgs<User>;
37
- * const fetchUser: FetchUser = async () => await api.getUser();
38
- */
39
- export type NoArgsAsyncFunction <ReturnType = void> = () => Promise<ReturnType>;
40
-
41
- /**
42
- * A function type that accepts arguments but always returns void.
43
- */
44
- export type NoArgsVoidFunction = () => void;
45
-
46
- /**
47
- * An async function type that accepts arguments but always resolves to void.
48
- */
49
- export type NoArgsAsyncVoidFunction = () => Promise<void>;
50
-
51
- /**
52
- * A function type that accepts arguments but always returns void.
53
- * Typically used for callbacks, event handlers, or side-effect functions.
54
- * @template Arguments - The types of the function arguments
55
- * @example
56
- * type OnUserChange = VoidFunction<[user: User]>;
57
- * const handleUserChange: OnUserChange = (user) => console.log(user);
58
- */
59
- export type VoidFunction<Arguments extends any[] = any[]> = (...args: Arguments) => void;
60
-
61
- /**
62
- * An async function type that accepts arguments but always resolves to void.
63
- * Typically used for async callbacks or side-effect functions.
64
- * @template Arguments - The types of the function arguments
65
- * @example
66
- * type OnUserChangeAsync = AsyncVoidFunction<[user: User]>;
67
- * const handleUserChangeAsync: OnUserChangeAsync = async (user) => await api.logChange(user);
68
- */
69
- export type AsyncVoidFunction<Arguments extends any[] = any[]> = (...args: Arguments) => Promise<void>;
70
-
71
- /**
72
- * A constructor function type that can accept any number of arguments and return an instance of any type.
73
- */
74
- export type ConstructorFunction<
75
- T extends object = object,
76
- Statics extends Record<string, unknown> | undefined = undefined
77
- > = (new (...args: any[]) => T) & (Statics extends undefined ? object : Statics);
78
-
79
- /**
80
- * An abstract constructor function type that can accept any number of arguments
81
- * and return an instance of the specified type.
82
- */
83
- export type AbstractConstructorFunction<
84
- T extends object = object,
85
- Statics extends Record<string, unknown> | undefined = undefined
86
- > = (abstract new (...args: any[]) => T) & (Statics extends undefined ? object : Statics);
@@ -1,15 +0,0 @@
1
- export * from './beautify.type';
2
- export * from './constructors/abstact-constructor.type';
3
- export * from './constructors/constructor.type';
4
- export * from './contains-char';
5
- export * from './decorators/accessor-decorator.type';
6
- export * from './decorators/class-decorator.type';
7
- export * from './decorators/field-decorator.type';
8
- export * from './decorators/method-decorator.type';
9
- export * from './dictionary.type';
10
- export * from './function.type';
11
- export * from './mutable.type';
12
- export * from './positive-integer.type';
13
- export * from './require-one.type';
14
- export * from './stack/stack.model';
15
- export * from './tuple-of-length.type';
@@ -1,3 +0,0 @@
1
- export type Mutable<T extends Object> = {
2
- -readonly [P in keyof T]: T[P];
3
- };
@@ -1,8 +0,0 @@
1
- import { ContainsChar } from './contains-char';
2
-
3
- export type PositiveInteger<Value extends number> =
4
- ContainsChar<`${Value}`, '-'> extends true
5
- ? never
6
- : ContainsChar<`${Value}`, '.'> extends true
7
- ? never
8
- : Value;
@@ -1,6 +0,0 @@
1
- export type RequireOne<T extends Object, Keys extends keyof T = keyof T> =
2
- Pick<T, Exclude<keyof T, Keys>> &
3
- {
4
- [K in Keys]-?: Required<Pick<T, K>> &
5
- Partial<Pick<T, Exclude<Keys, K>>>
6
- }[Keys];
@@ -1,56 +0,0 @@
1
- /**
2
- * A generic LIFO (Last In, First Out) stack data structure.
3
- *
4
- * @template T - The type of elements held in the stack. Defaults to `unknown`.
5
- */
6
- export class Stack<T = unknown> {
7
- /**
8
- * Internal array holding the stack elements, ordered from bottom to top.
9
- */
10
- private _elements = new Array<T>;
11
-
12
- [index: number]: T;
13
-
14
- constructor() {
15
- return new Proxy(this, {
16
- get(target, prop) {
17
- if (typeof prop === 'string') {
18
- return isNaN(Number(prop)) ? (target as unknown as { [prop]: unknown })[prop] : target._elements[Number(prop)];
19
- }
20
- }
21
- });
22
- }
23
-
24
- /**
25
- * The number of elements currently in the stack.
26
- */
27
- public get length(): number {
28
- return this._elements.length;
29
- }
30
-
31
- /**
32
- * A shallow copy of the elements in the stack, ordered from bottom to top.
33
- */
34
- public get values(): T[] {
35
- return [...this._elements];
36
- }
37
-
38
- /**
39
- * Removes and returns the top element of the stack.
40
- *
41
- * @returns The top element, or `undefined` if the stack is empty.
42
- */
43
- public pop(): T | undefined {
44
- return this._elements.pop();
45
- }
46
-
47
- /**
48
- * Pushes an element onto the top of the stack.
49
- *
50
- * @param element - The element to push.
51
- * @returns The new length of the stack.
52
- */
53
- public push(element: T): number {
54
- return this._elements.push(element);
55
- }
56
- }
@@ -1,11 +0,0 @@
1
- import { PositiveInteger } from './positive-integer.type';
2
-
3
- export type TupleOfLength<
4
- Length extends number,
5
- TupleType = number,
6
- Acc extends TupleType[] = []
7
- > = PositiveInteger<Length> extends never
8
- ? never
9
- : Acc['length'] extends Length
10
- ? Acc
11
- : TupleOfLength<Length, TupleType, [...Acc, TupleType]>
package/src/public-api.ts DELETED
@@ -1 +0,0 @@
1
- export * from './models';
package/tsconfig.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- }
package/vite.config.ts DELETED
@@ -1,4 +0,0 @@
1
- import { defineConfig } from 'vite';
2
- import getViteConfig from '../../vite-config';
3
-
4
- export default defineConfig(getViteConfig('@xaendar/common', __dirname));