@xaendar/common 0.1.7 → 0.2.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/common",
3
- "version": "0.1.7",
3
+ "version": "0.2.0",
4
4
  "description": "A library containing common utils and types",
5
5
  "type": "module",
6
6
  "main": "./xaendar-common.es.js",
@@ -1,119 +1,3 @@
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
1
  /**
118
2
  * A generic LIFO (Last In, First Out) stack data structure.
119
3
  *
@@ -125,6 +9,7 @@ export declare class Stack<T = unknown> {
125
9
  */
126
10
  private _elements;
127
11
  [index: number]: T;
12
+ [prop: string | symbol]: unknown;
128
13
  constructor();
129
14
  /**
130
15
  * The number of elements currently in the stack.
@@ -149,17 +34,4 @@ export declare class Stack<T = unknown> {
149
34
  push(element: T): number;
150
35
  }
151
36
 
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
37
  export { }
@@ -3,7 +3,7 @@ var e = class {
3
3
  _elements = [];
4
4
  constructor() {
5
5
  return new Proxy(this, { get(e, t) {
6
- if (typeof t == "string") return isNaN(Number(t)) ? e[t] : e._elements[Number(t)];
6
+ return isNaN(Number(t)) ? e[t] : e._elements[Number(t)];
7
7
  } });
8
8
  }
9
9
  get length() {
@@ -1 +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
+ {"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 [prop: string | symbol]: unknown;\r\n\r\n constructor() {\r\n return new Proxy(this, {\r\n get(target, prop) {\r\n return isNaN(Number(prop)) ? target[prop] : target._elements[Number(prop)];\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;CAMhC,cAAc;EACZ,OAAO,IAAI,MAAM,MAAM,EACrB,IAAI,GAAQ,GAAM;GAChB,OAAO,MAAM,OAAO,EAAK,CAAC,GAAG,EAAO,KAAQ,EAAO,UAAU,OAAO,EAAK;KAE5E,CAAC;;CAMJ,IAAW,SAAiB;EAC1B,OAAO,KAAK,UAAU;;CAMxB,IAAW,SAAc;EACvB,OAAO,CAAC,GAAG,KAAK,UAAU;;CAQ5B,MAA4B;EAC1B,OAAO,KAAK,UAAU,KAAK;;CAS7B,KAAY,GAAoB;EAC9B,OAAO,KAAK,UAAU,KAAK,EAAQ"}