@arabig/origin 1.0.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arabig-origin-record.mjs","sources":["../../../projects/origin/record/record.ts","../../../projects/origin/record/arabig-origin-record.ts"],"sourcesContent":["/**\r\n * @license\r\n * Copyright Salar Arab All Rights Reserved.\r\n * \r\n * @author Salar Arab <salar_arab@outlook.com>\r\n */\r\n\r\nimport { aoFilterObject } from \"@arabig/origin/functions\";\r\nimport { AoEntryUnion, AoObject } from \"@arabig/origin/types\";\r\n\r\n/**\r\n * Utilizes performing common operations as pipeline on object-like.\r\n *\r\n * @remarks\r\n * {@link AoRecord} provides a fluent and type-safe API for manipulating objects.\r\n * It includes methods for filtering, mapping, and transforming key-value pairs—similar to\r\n * array utilities but designed for object semantics.\r\n *\r\n * This class is ideal for scenarios where object-based data structures need to be processed\r\n * functionally, such as configuration maps, lookup tables, or DTO transformations.\r\n *\r\n * @typeParam T - The type of entries contained in the record.\r\n *\r\n * @example\r\n * ```ts\r\n * const rec = new AoRecord({\r\n * name: \"John\",\r\n * age: 33,\r\n * married: false,\r\n * }).filter(({ key }) => key !== \"age\");\r\n * ```\r\n */\r\nexport class AoRecord<T extends AoObject> {\r\n\r\n private readonly _entries: T;\r\n\r\n /**\r\n * \r\n * @param defaultEntries The default structure to initialize {@link AoRecord} entries\r\n */\r\n constructor(defaultEntries: T) {\r\n this._entries = defaultEntries;\r\n }\r\n\r\n /**\r\n * @readonly Gets keys of the current entries.\r\n * @returns An array containing keys of the current entries\r\n */\r\n public get keys(): (keyof T)[] {\r\n return Object.keys(this._entries);\r\n }\r\n\r\n /**\r\n * @readonly Gets values of the current entries.\r\n * @returns An array containing values of the current entries\r\n */\r\n public get values(): T[keyof T][] {\r\n return Object.values(this._entries) as T[keyof T][];\r\n }\r\n\r\n /**\r\n * @readonly Gets the current entries.\r\n * @returns An array containing the current entries in form of {@link AoEntryUnion}\r\n */\r\n public get entries(): AoEntryUnion<T>[] {\r\n return Object.entries(this._entries)\r\n .map(e => ({ key: e[0], value: e[1] })) as AoEntryUnion<T>[];\r\n }\r\n\r\n /**\r\n * Filters the current entries based on given condition.\r\n * @param predicate The callback that iterates within {@link AoRecord} entries and\r\n * provides the key and value in form of {@link AoEntryUnion} as parameter and must\r\n * return a boolean type determines whether the current key should be remained in the\r\n * resulting entries or not\r\n * @returns A new instance of {@link AoRecord} containing the {@link Partial} filtered entries.\r\n */\r\n public filter(\r\n predicate: (entry: AoEntryUnion<T>) => boolean\r\n ): AoRecord<AoObject> {\r\n return new AoRecord(aoFilterObject(this._entries, predicate));\r\n }\r\n\r\n /**\r\n * Tests the trueness of the given condition for every entry.\r\n * @param predicate The callback that iterates within {@link AoRecord} entries and\r\n * provides the key and value in form of {@link AoEntryUnion} as parameter and must\r\n * return a boolean type determines the condition for current entry\r\n * @returns True, if the given conditions is true for every entry otherwise false\r\n */\r\n public every(\r\n predicate: (entry: AoEntryUnion<T>) => boolean\r\n ): boolean {\r\n for (const key in this._entries) {\r\n if (!Object.hasOwn(this._entries, key)) continue;\r\n\r\n if (!predicate({ key: key, value: this._entries[key] })) return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Tests the trueness of the given condition for atleast one entry.\r\n * @param predicate The callback that iterates within {@link AoRecord} entries and\r\n * provides the key and value in form of {@link AoEntryUnion} as parameter and must\r\n * return a boolean type determines the condition for current entry\r\n * @returns True, if the given conditions is true for atleast one entry otherwise false\r\n */\r\n public some(\r\n predicate: (entry: AoEntryUnion<T>) => boolean\r\n ): boolean {\r\n for (const key in this._entries) {\r\n if (!Object.hasOwn(this._entries, key)) continue;\r\n\r\n if (predicate({ key: key, value: this._entries[key] })) return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;AAAA;;;;;AAKG;AAKH;;;;;;;;;;;;;;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KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,QAAQ,EAAE;YAC/B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC;gBAAE;AAExC,YAAA,IAAI,SAAS,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;AAAE,gBAAA,OAAO,IAAI;QACrE;AAEA,QAAA,OAAO,KAAK;IACd;AAED;;ACzHD;;AAEG;;;;"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright Salar Arab All Rights Reserved.
4
+ *
5
+ * @author Salar Arab <salar_arab@outlook.com>
6
+ */
7
+
8
+ /**
9
+ * @license
10
+ * Copyright Salar Arab All Rights Reserved.
11
+ *
12
+ * @author Salar Arab <salar_arab@outlook.com>
13
+ */
14
+
15
+ /**
16
+ * @license
17
+ * Copyright Agin Company All Rights Reserved
18
+ *
19
+ * @author Salar Arab <salar.arab.70@gmail.com>
20
+ */
21
+
22
+ /**
23
+ * Generated bundle index. Do not edit.
24
+ */
25
+ //# sourceMappingURL=arabig-origin-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arabig-origin-types.mjs","sources":["../../../projects/origin/types/utility.type.ts","../../../projects/origin/types/constant.type.ts","../../../projects/origin/types/checker.type.ts","../../../projects/origin/types/arabig-origin-types.ts"],"sourcesContent":["/**\r\n * @license\r\n * Copyright Salar Arab All Rights Reserved.\r\n * \r\n * @author Salar Arab <salar_arab@outlook.com>\r\n */\r\n\r\n/**\r\n * Represents a union of the given type, `undefined` and `null`.\r\n * @typeParam `T` The type that the union is based on\r\n */\r\nexport type AoNullish<T> = T | null | undefined;\r\n\r\n/**\r\n * Represents a discriminated union of the passed type parameter's possible enteries\r\n * based on its keys.\r\n * @typeParam `T` The type that the union is based on\r\n */\r\nexport type AoEntryUnion<T> = {\r\n [K in keyof T]: { key: K; value: T[K] }\r\n}[keyof T];\r\n\r\n/**\r\n * Represents a key-value pair in form of a two elements tuple that its first element\r\n * is the key and the second one is the value.\r\n */\r\nexport type AoEntry<T> = [keyof T, T[keyof T]];\r\n\r\n/**\r\n * Represents an `object` with loose or typed structure base on given type parameter.\r\n * @typeParam `T` The type that determines the structure of the resulting `object`.\r\n * If omitted, a complete loose structure will be considered\r\n */\r\nexport type AoObject<T extends Record<any, any> = any> = \r\n T extends any[]\r\n ? never\r\n : T extends (...p: any[]) => any\r\n ? never\r\n : unknown extends T\r\n ? Record<any, any>\r\n : { [K in keyof T]: T[K] };\r\n\r\n/**\r\n * Represents an `object` that includes a loose minimal structure base on passed type\r\n * parameter.\r\n * @typeParam `T` The `object` based that forms the minimal structure, if omitted\r\n * a complete loose structure will be considered\r\n */\r\nexport type AoLooseObject<T extends AoObject = AoObject> = AoObject & T;\r\n\r\n/**\r\n * Represents a `string` literal union of the given `enum` values.\r\n * @typeParam `T`The `enum` type\r\n * @typeParam `TDefault` The type that determines the default case of the `enum` values union\r\n */\r\nexport type AoEnumValue<T extends string, TDefault extends string = never> = `${T}` | TDefault;\r\n\r\n/**\r\n * Represents an optional `string` literal union of the given `enum` values.\r\n * @typeParam `T`The `enum` type\r\n */\r\nexport type AoEnumOptionalValue<T extends string> = `${T}` | String;\r\n\r\n/**\r\n * Represents either a typed union of specific keys or a plain primitive key\r\n * base on given type parameter.\r\n * @typeParam `T` The type that determines the keys union or a primitive key if omitted\r\n */\r\nexport type AoKey<T = unknown> = unknown extends T\r\n ? string | number | symbol\r\n : keyof T;\r\n\r\n/**\r\n * Represents either a typed union of specific keys or a `string` key\r\n * base on given type parameter.\r\n * @typeParam `T` The type that determines the keys union or a string key if omitted\r\n */ \r\nexport type AoStringKey<T = unknown> = unknown extends T\r\n ? string\r\n : Exclude<keyof T, number | symbol>;\r\n\r\n/**\r\n * Represents either a typed union of specific keys or a plain primitive key\r\n * base on given type parameter for all nested types.\r\n * @typeParam `T` The type that determines the keys union or a primitive key if omitted\r\n * @remarks Using this type for deeply nested types can prove slow compilation time.\r\n */\r\nexport type AoDeepKey<T = unknown> = unknown extends T\r\n ? string | number | symbol\r\n : {\r\n [K in keyof T]: T[K] extends object\r\n ? K | AoDeepKey<T[K]>\r\n : K\r\n }[keyof T];\r\n\r\n/**\r\n * Represents either a typed union of specific keys or a `string` key\r\n * base on given type parameter for all nested types.\r\n * @typeParam `T` The type that determines the keys union or a `string` key if omitted\r\n * @remarks Using this type for deeply nested types can prove slow compilation time.\r\n */\r\nexport type AoDeepStringKey<T = unknown> = unknown extends T\r\n ? string\r\n : Exclude<\r\n {\r\n [K in keyof T]: T[K] extends object\r\n ? K | AoDeepKey<T[K]>\r\n : K\r\n }[keyof T], number | symbol\r\n >;","/**\r\n * @license\r\n * Copyright Salar Arab All Rights Reserved.\r\n * \r\n * @author Salar Arab <salar_arab@outlook.com>\r\n */\r\n\r\n/**\r\n * Represents a union of JavaScript primitive data types.\r\n * @see {@link https://developer.mozilla.org/en-US/docs/Glossary/Primitive | Primitive}\r\n */\r\nexport type AoPrimitive = string | number | boolean | bigint | undefined | null | symbol;\r\n\r\n/**\r\n * Represents a union of JavaScript falsy values.\r\n * @see {@link https://developer.mozilla.org/en-US/docs/Glossary/Falsy | Falsy}\r\n */\r\nexport type AoFalsy = undefined | null | false | 0 | -0 | 0n | \"\";\r\n\r\n\r\n/**\r\n * Represents an object that is a CSS declaration block, and exposes style information\r\n * and various style-related methods and properties.\r\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration | CSSStyleDeclaration}\r\n */\r\nexport type AoStyle = Partial<CSSStyleDeclaration>;\r\n\r\n/**\r\n * Represents a numeric `string` type\r\n */\r\nexport type AoDigit = `${number}`;\r\n\r\n/**\r\n * Represents a union of the `typeof` keyword result values\r\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof | typeof}\r\n */\r\nexport type AoTypeOf =\r\n | 'string'\r\n | 'number'\r\n | 'boolean'\r\n | 'symbol'\r\n | 'undefined'\r\n | 'object'\r\n | 'function'\r\n | 'bigint';","/**\r\n* @license\r\n* Copyright Agin Company All Rights Reserved\r\n* \r\n* @author Salar Arab <salar.arab.70@gmail.com>\r\n*/\r\n\r\n/**\r\n * Checks whether the passed type is only assignable to a minimal unbound JS `object`.\r\n * @typeParam `T` The type to be checked\r\n */\r\nexport type AoIsObject<T> = T extends \r\n | any[]\r\n | Function\r\n | ((...p: any[]) => any)\r\n ? never\r\n : T extends Record<any, any>\r\n ? T\r\n : never;\r\n\r\n/**\r\n * Checks whether the passed type is only assignable to a minimal unbound JS `array`.\r\n * @typeParam `T` The type to be checked\r\n */\r\nexport type AoIsArray<T> = T extends any[]\r\n ? T\r\n : never;\r\n\r\n/**\r\n * Checks whether the passed type is only assignable to a minimal callable JS `function`.\r\n * @typeParam `T` The type to be checked\r\n */\r\nexport type AoIsFunction<T> = T extends (...p: any[]) => any\r\n ? T\r\n : never;","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA;;;;;AAKG;;ACLH;;;;;AAKG;;ACLH;;;;;AAKE;;ACLF;;AAEG"}
@@ -0,0 +1,176 @@
1
+ /**
2
+ * @license
3
+ * Copyright Salar Arab All Rights Reserved.
4
+ *
5
+ * @author Salar Arab <salar_arab@outlook.com>
6
+ */
7
+ /**
8
+ * Represents a type-safe collection that stores and retrieves values using unique,
9
+ * typed tokens.
10
+ *
11
+ * This class utilizes an abstract data structure similar to `Map`, but replaces generic keys
12
+ * with {@link AoToken} instances to ensure both **uniqueness** and **type safety**. Each token
13
+ * carries a generic type parameter that enforces the expected value type at compile time,
14
+ * preventing mismatches and enhancing developer experience.
15
+ *
16
+ * Ideal for use cases such as dependency registries, metadata stores, or scoped configuration
17
+ * systems where strong typing and collision-free keying are critical.
18
+ *
19
+ * @see {@link https://en.wikipedia.org/wiki/Abstract_data_type | Abstract data type}
20
+ *
21
+ * @typeParam `TValue` Determines the storeable value type range
22
+ *
23
+ * @remarks
24
+ * - Tokens are guaranteed to be unique via their internal `Symbol` identifier.
25
+ * - Values are type-checked against the token’s generic parameter.
26
+ * - This structure improves safety and clarity in large-scale, modular applications.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const data = { meta: "data" };
31
+ *
32
+ * const DATA_TOKEN = new AoToken<{ meta: "data" }>();
33
+ *
34
+ * const collection = new AoVault().store(DATA_TOKEN, data);
35
+ *
36
+ * const value = collection.retrieve(DATA_TOKEN); //inferred as { meta: "data" } | null;
37
+ * ```
38
+ */
39
+ class AoVault {
40
+ _vault;
41
+ /**
42
+ * Creates a new instance with optional initial entries.
43
+ * @param entries The optional initial entries as token-value `tuples`
44
+ */
45
+ constructor(entries) {
46
+ this._vault = new Map(entries);
47
+ }
48
+ /**
49
+ * Checks if an associated entry exists for the given token.
50
+ * @param token An instance of {@link AoToken} as querying token
51
+ * @returns The result of the query as `boolean`
52
+ */
53
+ exists(token) {
54
+ return this._vault.has(token);
55
+ }
56
+ /**
57
+ * Stores the given entry base on {@link AoToken}.
58
+ * @typeParam `T` The type of storing value that must be assignable to {@link AoVault} `TValue` generic type
59
+ * @param token An instance of {@link AoToken} as querying token
60
+ * @param value The storing value
61
+ * @returns The current instance of {@link AoVault}
62
+ */
63
+ store(token, value) {
64
+ this._vault.set(token, value);
65
+ return this;
66
+ }
67
+ /**
68
+ * Retrieves the associated value base on given {@link AoToken}.
69
+ * @typeParam `T` The type of retrieving value that must be assignable to {@link AoVault} `TValue` generic type
70
+ * @param token An instance of {@link AoToken} as querying token
71
+ * @returns The associated value
72
+ */
73
+ retrieve(token) {
74
+ return this._vault.get(token) ?? null;
75
+ }
76
+ /**
77
+ * Deletes the associated entry base on given {@link AoToken}.
78
+ * @typeParam `T` The type of deleting value that must be assignable to {@link AoVault} `TValue` generic type
79
+ * @param token An instance of {@link AoToken} as querying token
80
+ * @returns The associated value before deleting the entry
81
+ */
82
+ delete(token) {
83
+ if (this._vault.has(token)) {
84
+ const _value = this._vault.get(token) ?? null;
85
+ this._vault.delete(token);
86
+ return _value;
87
+ }
88
+ else {
89
+ return null;
90
+ }
91
+ }
92
+ }
93
+
94
+ /**
95
+ * @license
96
+ * Copyright Salar Arab All Rights Reserved.
97
+ *
98
+ * @author Salar Arab <salar_arab@outlook.com>
99
+ */
100
+ /**
101
+ * Represents a uniquely created token-like entity which can be associated with a
102
+ * corresponding value.
103
+ *
104
+ * @remarks
105
+ * Each `AoToken` instance encapsulates a unique `Symbol` identifier, ensuring
106
+ * collision-free keying even across modules. The generic type parameter `T` allows
107
+ * consumers to associate a specific value type with the token, enabling type-safe
108
+ * retrieval from collections.
109
+ *
110
+ * This pattern is especially useful in scenarios like dependency injection,
111
+ * metadata registries, or strongly typed key-value stores.
112
+ *
113
+ * @typeParam `T` The type of value associated with this token.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const BASE_URL_TK = new AoToken<string>("website base URL");
118
+ *
119
+ * const collection = new Map();
120
+ *
121
+ * function getValue<T>(token: AoToken<T>): T | null {
122
+ return collection.get(token) ?? null;
123
+ }
124
+ *
125
+ * const value = getValue(BASE_URL_TK); //inferred as string | null
126
+ * ```
127
+ */
128
+ class AoToken {
129
+ /**
130
+ * @remarks Do not use this property in the inheritance, since it reserved for
131
+ * semantic usage of `T` type parameter.
132
+ */
133
+ $implicitType;
134
+ _identifier;
135
+ _description;
136
+ /**
137
+ * Creates a new instance with optional given description.
138
+ * @param description An optional string description
139
+ */
140
+ constructor(description) {
141
+ this._identifier = Symbol(description ?? "");
142
+ this._description = description ?? "";
143
+ }
144
+ /**
145
+ * @readonly The `symbol` base identifier which is unique for each intance
146
+ * @remarks It is recommended to use this property for identification or comparsion
147
+ * purposes.
148
+ */
149
+ get identifier() {
150
+ return this._identifier;
151
+ }
152
+ /**
153
+ * @readonly The description about this token instance.
154
+ * @remarks It is not recommended to use this property for identification or
155
+ * comparsion purposes, since it's just a simple description about the token instance.
156
+ * Use the `identifier` property for this matter.
157
+ */
158
+ get description() {
159
+ return this._description;
160
+ }
161
+ /**
162
+ * Compares the given `AoToken` with the current instance.
163
+ * @param comparable The comparing `AoToken` instance
164
+ * @returns The comparsion result as `boolean`
165
+ */
166
+ equals(comparable) {
167
+ return comparable.identifier === this.identifier;
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Generated bundle index. Do not edit.
173
+ */
174
+
175
+ export { AoToken, AoVault };
176
+ //# sourceMappingURL=arabig-origin-vault.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arabig-origin-vault.mjs","sources":["../../../projects/origin/vault/vault.ts","../../../projects/origin/vault/token.ts","../../../projects/origin/vault/arabig-origin-vault.ts"],"sourcesContent":["/**\r\n * @license\r\n * Copyright Salar Arab All Rights Reserved.\r\n * \r\n * @author Salar Arab <salar_arab@outlook.com>\r\n */\r\n\r\nimport { AoToken } from \"./token\";\r\n\r\n/**\r\n * Represents a type-safe collection that stores and retrieves values using unique,\r\n * typed tokens.\r\n *\r\n * This class utilizes an abstract data structure similar to `Map`, but replaces generic keys\r\n * with {@link AoToken} instances to ensure both **uniqueness** and **type safety**. Each token\r\n * carries a generic type parameter that enforces the expected value type at compile time,\r\n * preventing mismatches and enhancing developer experience.\r\n *\r\n * Ideal for use cases such as dependency registries, metadata stores, or scoped configuration\r\n * systems where strong typing and collision-free keying are critical.\r\n *\r\n * @see {@link https://en.wikipedia.org/wiki/Abstract_data_type | Abstract data type}\r\n * \r\n * @typeParam `TValue` Determines the storeable value type range\r\n *\r\n * @remarks\r\n * - Tokens are guaranteed to be unique via their internal `Symbol` identifier.\r\n * - Values are type-checked against the token’s generic parameter.\r\n * - This structure improves safety and clarity in large-scale, modular applications.\r\n *\r\n * @example\r\n * ```ts\r\n * const data = { meta: \"data\" };\r\n *\r\n * const DATA_TOKEN = new AoToken<{ meta: \"data\" }>();\r\n *\r\n * const collection = new AoVault().store(DATA_TOKEN, data);\r\n *\r\n * const value = collection.retrieve(DATA_TOKEN); //inferred as { meta: \"data\" } | null;\r\n * ```\r\n */\r\nexport class AoVault<TValue = any> {\r\n\r\n private readonly _vault: Map<AoToken<TValue>, TValue>;\r\n\r\n /**\r\n * Creates a new instance with optional initial entries.\r\n * @param entries The optional initial entries as token-value `tuples`\r\n */\r\n constructor(entries?: [AoToken<TValue>, TValue][]) {\r\n this._vault = new Map(entries);\r\n }\r\n\r\n /**\r\n * Checks if an associated entry exists for the given token.\r\n * @param token An instance of {@link AoToken} as querying token\r\n * @returns The result of the query as `boolean`\r\n */\r\n public exists(token: AoToken<TValue>): boolean {\r\n return this._vault.has(token);\r\n }\r\n\r\n /**\r\n * Stores the given entry base on {@link AoToken}.\r\n * @typeParam `T` The type of storing value that must be assignable to {@link AoVault} `TValue` generic type\r\n * @param token An instance of {@link AoToken} as querying token\r\n * @param value The storing value\r\n * @returns The current instance of {@link AoVault}\r\n */\r\n public store<T extends TValue>(token: AoToken<T>, value: T): AoVault<TValue> {\r\n this._vault.set(token, value);\r\n return this;\r\n }\r\n\r\n /**\r\n * Retrieves the associated value base on given {@link AoToken}.\r\n * @typeParam `T` The type of retrieving value that must be assignable to {@link AoVault} `TValue` generic type\r\n * @param token An instance of {@link AoToken} as querying token\r\n * @returns The associated value\r\n */\r\n public retrieve<T extends TValue>(token: AoToken<T>): T | null {\r\n return this._vault.get(token) as T ?? null;\r\n }\r\n\r\n /**\r\n * Deletes the associated entry base on given {@link AoToken}.\r\n * @typeParam `T` The type of deleting value that must be assignable to {@link AoVault} `TValue` generic type\r\n * @param token An instance of {@link AoToken} as querying token\r\n * @returns The associated value before deleting the entry\r\n */\r\n public delete<T extends TValue>(token: AoToken<T>): T | null {\r\n if (this._vault.has(token)) {\r\n const _value = this._vault.get(token) as T ?? null;\r\n \r\n this._vault.delete(token);\r\n \r\n return _value;\r\n }\r\n else {\r\n return null;\r\n }\r\n }\r\n\r\n}","/**\r\n * @license\r\n * Copyright Salar Arab All Rights Reserved.\r\n * \r\n * @author Salar Arab <salar_arab@outlook.com>\r\n */\r\n\r\n/**\r\n * Represents a uniquely created token-like entity which can be associated with a \r\n * corresponding value.\r\n * \r\n * @remarks\r\n * Each `AoToken` instance encapsulates a unique `Symbol` identifier, ensuring\r\n * collision-free keying even across modules. The generic type parameter `T` allows\r\n * consumers to associate a specific value type with the token, enabling type-safe\r\n * retrieval from collections.\r\n *\r\n * This pattern is especially useful in scenarios like dependency injection,\r\n * metadata registries, or strongly typed key-value stores.\r\n *\r\n * @typeParam `T` The type of value associated with this token.\r\n *\r\n * @example\r\n * ```ts\r\n * const BASE_URL_TK = new AoToken<string>(\"website base URL\");\r\n * \r\n * const collection = new Map();\r\n * \r\n * function getValue<T>(token: AoToken<T>): T | null {\r\n return collection.get(token) ?? null;\r\n }\r\n * \r\n * const value = getValue(BASE_URL_TK); //inferred as string | null\r\n * ```\r\n */\r\nexport class AoToken<T> {\r\n\r\n /**\r\n * @remarks Do not use this property in the inheritance, since it reserved for\r\n * semantic usage of `T` type parameter.\r\n */\r\n protected $implicitType?: T;\r\n\r\n private readonly _identifier: symbol;\r\n\r\n private readonly _description: string;\r\n\r\n /**\r\n * Creates a new instance with optional given description.\r\n * @param description An optional string description\r\n */\r\n constructor(description?: string | null) {\r\n this._identifier = Symbol(description ?? \"\");\r\n this._description = description ?? \"\";\r\n }\r\n\r\n /**\r\n * @readonly The `symbol` base identifier which is unique for each intance\r\n * @remarks It is recommended to use this property for identification or comparsion\r\n * purposes.\r\n */\r\n public get identifier() {\r\n return this._identifier;\r\n }\r\n\r\n /**\r\n * @readonly The description about this token instance.\r\n * @remarks It is not recommended to use this property for identification or\r\n * comparsion purposes, since it's just a simple description about the token instance.\r\n * Use the `identifier` property for this matter.\r\n */\r\n public get description() {\r\n return this._description;\r\n }\r\n\r\n /**\r\n * Compares the given `AoToken` with the current instance.\r\n * @param comparable The comparing `AoToken` instance\r\n * @returns The comparsion result as `boolean`\r\n */\r\n public equals(comparable: AoToken<unknown>): boolean {\r\n return comparable.identifier === this.identifier;\r\n }\r\n\r\n}","/**\n * Generated bundle index. Do not edit.\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AAW,GAAG,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC;AAC5C,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW,IAAI,EAAE;IACvC;AAEA;;;;AAIG;AACH,IAAA,IAAW,UAAU,GAAA;QACnB,OAAO,IAAI,CAAC,WAAW;IACzB;AAEA;;;;;AAKG;AACH,IAAA,IAAW,WAAW,GAAA;QACpB,OAAO,IAAI,CAAC,YAAY;IAC1B;AAEA;;;;AAIG;AACI,IAAA,MAAM,CAAC,UAA4B,EAAA;AACxC,QAAA,OAAO,UAAU,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU;IAClD;AAED;;ACpFD;;AAEG;;;;"}
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Public API Surface of origin
3
+ */
4
+ const _publicOriginNoopPrimaryExport = false;
5
+
6
+ /**
7
+ * Generated bundle index. Do not edit.
8
+ */
9
+
10
+ export { _publicOriginNoopPrimaryExport };
11
+ //# sourceMappingURL=arabig-origin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arabig-origin.mjs","sources":["../../../projects/origin/public-api.ts","../../../projects/origin/arabig-origin.ts"],"sourcesContent":["/*\r\n * Public API Surface of origin\r\n */\r\n\r\nexport const _publicOriginNoopPrimaryExport = false;","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA;;AAEG;AAEI,MAAM,8BAA8B,GAAG;;ACJ9C;;AAEG;;;;"}
@@ -0,0 +1,73 @@
1
+ import { AoObject, AoEntryUnion } from '@arabig/origin/types';
2
+
3
+ /**
4
+ * @license
5
+ * Copyright Salar Arab All Rights Reserved.
6
+ *
7
+ * @author Salar Arab <salar_arab@outlook.com>
8
+ */
9
+ /**
10
+ * Converts the given value to a number based on given options.
11
+ * @param value The convertible input value.
12
+ * @param options The options object that handles different cases of numeric conversion.
13
+ * @returns The resulting number of the conversion
14
+ *
15
+ * @example
16
+ * doToNumber("563.68", {
17
+ * infinityAlt: 0,
18
+ * NaNAlt: 0
19
+ * });
20
+ */
21
+ declare function aoToNumber(value?: unknown, options?: {
22
+ /**
23
+ * Determines the alternative value, if the conversion results in {@link NaN}.
24
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN | NaN}
25
+ *
26
+ * @default 0
27
+ */
28
+ NaNAlt?: number;
29
+ /**
30
+ * Determines the alternative value, if the conversion leads to {@link Infinity}.
31
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity | Infinity}
32
+ *
33
+ * @default 0
34
+ */
35
+ infinityAlt?: number;
36
+ }): number;
37
+ /**
38
+ * Extracts the decimal part of the given value and returns it as raw string.
39
+ * @param value The input value whose decimal part is demanded.
40
+ * @returns The extracted decimal part as numeric string or empty string if no decimal part is found.
41
+ */
42
+ declare function aoExtractDecimal(value: unknown): `${number}` | "";
43
+ /**
44
+ * Extracts the integer part of the given value and returns it as numeric string.
45
+ * @param value The input value whose integer part is demanded.
46
+ * @returns The extracted integer part as numeric string or empty string if no integer part is found.
47
+ */
48
+ declare function aoExtractInteger(value: unknown): `${number}` | "";
49
+
50
+ /**
51
+ * @license
52
+ * Copyright Salar Arab All Rights Reserved.
53
+ *
54
+ * @author Salar Arab <salar_arab@outlook.com>
55
+ */
56
+
57
+ /**
58
+ * Filters the given target object entries based on given condition.
59
+ * @typeParam `T` The type of the target object to be filtered
60
+ * @param target The `object` to be filtered
61
+ * @param predicate The callback that iterates within target entries.
62
+ * Provides the key and value in form of {@link DoEntryUnion} as parameter and must
63
+ * return a boolean type determines whether the current key should be remained in the
64
+ * resulting entries or not
65
+ * @returns The filtered `object`.
66
+ * @remarks
67
+ * Since the structure of the returning `object` is formed during the runtime, the
68
+ * type inference at the compile time is not possible, so an unbound `object` is considered
69
+ * as the return type.
70
+ */
71
+ declare function aoFilterObject<T extends AoObject>(target: T, predicate: (entry: AoEntryUnion<T>) => boolean): AoObject;
72
+
73
+ export { aoExtractDecimal, aoExtractInteger, aoFilterObject, aoToNumber };
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const _publicOriginNoopPrimaryExport = false;
2
+
3
+ export { _publicOriginNoopPrimaryExport };
@@ -0,0 +1,148 @@
1
+ /**
2
+ * @license
3
+ * Copyright Salar Arab All Rights Reserved
4
+ *
5
+ * @author Salar Arab <salar_arab@outlook.com>
6
+ */
7
+ /**
8
+ * Represents a numeric string
9
+ */
10
+ type Digits = `${number}`;
11
+ /**
12
+ * The convertible input type used mostly in calculation methods
13
+ */
14
+ type RawInput = string | number | bigint | null | undefined;
15
+ /**
16
+ * Represents different states of the value
17
+ */
18
+ type ValueState = "current" | "previous" | "initial";
19
+ /**
20
+ * Utilizes performing precise arithmetic operations
21
+ * such as addition, subtraction, multiplication, and division in the form of pipeline.
22
+ *
23
+ * This class is designed to handle extremely large or small numeric values
24
+ * without resulting in {@link Infinity} or {@link NaN}, ensuring safe and predictable
25
+ * calculations across a wide range of inputs.
26
+ *
27
+ * All operations are performed using numeric strings to maintain precision,
28
+ * especially for decimal values, avoiding floating-point inaccuracies common
29
+ * in native JavaScript number handling.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const operand = new AoOperand(0.005).add(1.05).add(0.005);
34
+ *
35
+ * console.log(operand.currentValue) //expecting "1.06";
36
+ * ```
37
+ *
38
+ * @remarks
39
+ * This class is ideal for financial, scientific, or any domain where
40
+ * precision and scale are critical. It does not rely on native number
41
+ * arithmetic and instead uses string-based computation to preserve accuracy.
42
+ */
43
+ declare class AoOperand {
44
+ private readonly _initialValue;
45
+ private _previousValue;
46
+ private _currentValue;
47
+ /**
48
+ * Creates a new instance based on given instance.
49
+ * @param instance An instance of {@link AoOperand}
50
+ */
51
+ constructor(instance: AoOperand);
52
+ /**
53
+ * Creates a new instance of {@link AoOperand} with provided initial value.
54
+ * @param initialValue
55
+ * The initial value of the calculation. If the value is not provided or not numeric
56
+ * convertible, is assigned to "0".
57
+ */
58
+ constructor(initialValue?: RawInput);
59
+ /**
60
+ * Converts and outputs the {@link AoOperand}'s value as number base on given state.
61
+ * @param state The state that determines temporal state of the value. Default is "current"
62
+ * @returns A number
63
+ */
64
+ toNumber(state?: ValueState): number;
65
+ /**
66
+ * Converts and outputs the {@link AoOperand}'s value as bigint base on given state.
67
+ * @param state The state that determines temporal state of the value. Default is "current"
68
+ * @returns A bigint
69
+ */
70
+ toBigInt(state?: ValueState): bigint;
71
+ /**
72
+ * Converts and outputs the {@link AoOperand}'s value as numeric string base on given state.
73
+ * @param state The state that determines temporal state of the value. Default is "current"
74
+ * @returns A numeric string
75
+ */
76
+ toString(state?: ValueState): Digits;
77
+ /**
78
+ * Executes the Executes the {@link https://en.wikipedia.org/wiki/Addition | addition}
79
+ * operation for the given value.
80
+ * @param input The adding operand
81
+ * @returns A new instance of {@link AoOperand} that holds the operation latest result
82
+ */
83
+ add(input: RawInput): AoOperand;
84
+ /**
85
+ * Executes the {@link https://en.wikipedia.org/wiki/Subtraction | subtraction}
86
+ * operation for the given value.
87
+ * @param input The subtracting operand
88
+ * @returns A new instance of {@link AoOperand} that holds the operation latest result
89
+ */
90
+ subtract(input: RawInput): AoOperand;
91
+ /**
92
+ * Executes the {@link https://en.wikipedia.org/wiki/Multiplication | multiplication}
93
+ * operation for the given value.
94
+ * @param input The multiplying operand
95
+ * @returns A new instance of {@link AoOperand} that holds the operation latest result
96
+ */
97
+ multiply(input: RawInput): AoOperand;
98
+ /**
99
+ * Executes the {@link https://en.wikipedia.org/wiki/Division_(mathematics) | division}
100
+ * operation for the given value.
101
+ * @param input The dividing operand
102
+ * @param options The option object that determines calculation behavior.
103
+ * @returns A new instance of {@link AoOperand} that holds the operation latest result
104
+ */
105
+ divide(input: RawInput, options?: {
106
+ /**
107
+ * The number of decimal places to keep. The default value is 10
108
+ */
109
+ precision?: number;
110
+ /**
111
+ * The alternative value in case of divide by zero
112
+ */
113
+ divideByZeroAlt?: RawInput;
114
+ }): AoOperand;
115
+ /**
116
+ * Creates a new instance based on current instance.
117
+ * @returns A new {@link AoOperand} instance
118
+ */
119
+ private clone;
120
+ /**
121
+ * Takes snapshot from the current value then assigns the given value to it.
122
+ * @param value the input value that updates the current value
123
+ */
124
+ private assign;
125
+ /**
126
+ * Restrains the given number operation by switching to its bigint alternative
127
+ * if it leads to {@link Infinity}.
128
+ * @param finiteOperator The callback that returns number
129
+ * @param infiniteOperator The callback that returns bigint
130
+ * @returns A numeric string
131
+ */
132
+ private restrain;
133
+ /**
134
+ * Creates an info object from raw input that provides refined number parts for calculation.
135
+ * @param input The raw input needed for refinement.
136
+ * @returns An object info providing refined data for calculation
137
+ */
138
+ private refine;
139
+ /**
140
+ * Normalizes the decimal part if all of its digits are "0" and removes trailing zeros.
141
+ * @param integer The integer part of the value
142
+ * @param decimal The decimal part of the value
143
+ * @returns The normalized numeric string
144
+ */
145
+ private normalize;
146
+ }
147
+
148
+ export { AoOperand };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@arabig/origin",
3
+ "version": "1.0.0",
4
+ "author": {
5
+ "name": "Salar Arab",
6
+ "email": "salar_arab@outlook.com"
7
+ },
8
+ "description": "@arabig TypeScript Library",
9
+ "homepage": "https://github.com/salar-arab/ng-workspace",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/salar-arab/ng-workspace"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/salar-arab/ng-workspace/issues"
16
+ },
17
+ "keywords": [
18
+ "TypeScript",
19
+ "TS",
20
+ "library"
21
+ ],
22
+ "license": "UNLICENSED",
23
+ "dependencies": {
24
+ "tslib": "^2.3.0"
25
+ },
26
+ "sideEffects": false,
27
+ "module": "fesm2022/arabig-origin.mjs",
28
+ "typings": "index.d.ts",
29
+ "exports": {
30
+ "./package.json": {
31
+ "default": "./package.json"
32
+ },
33
+ ".": {
34
+ "types": "./index.d.ts",
35
+ "default": "./fesm2022/arabig-origin.mjs"
36
+ },
37
+ "./functions": {
38
+ "types": "./functions/index.d.ts",
39
+ "default": "./fesm2022/arabig-origin-functions.mjs"
40
+ },
41
+ "./operand": {
42
+ "types": "./operand/index.d.ts",
43
+ "default": "./fesm2022/arabig-origin-operand.mjs"
44
+ },
45
+ "./record": {
46
+ "types": "./record/index.d.ts",
47
+ "default": "./fesm2022/arabig-origin-record.mjs"
48
+ },
49
+ "./types": {
50
+ "types": "./types/index.d.ts",
51
+ "default": "./fesm2022/arabig-origin-types.mjs"
52
+ },
53
+ "./vault": {
54
+ "types": "./vault/index.d.ts",
55
+ "default": "./fesm2022/arabig-origin-vault.mjs"
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,81 @@
1
+ import { AoObject, AoEntryUnion } from '@arabig/origin/types';
2
+
3
+ /**
4
+ * @license
5
+ * Copyright Salar Arab All Rights Reserved.
6
+ *
7
+ * @author Salar Arab <salar_arab@outlook.com>
8
+ */
9
+
10
+ /**
11
+ * Utilizes performing common operations as pipeline on object-like.
12
+ *
13
+ * @remarks
14
+ * {@link AoRecord} provides a fluent and type-safe API for manipulating objects.
15
+ * It includes methods for filtering, mapping, and transforming key-value pairs—similar to
16
+ * array utilities but designed for object semantics.
17
+ *
18
+ * This class is ideal for scenarios where object-based data structures need to be processed
19
+ * functionally, such as configuration maps, lookup tables, or DTO transformations.
20
+ *
21
+ * @typeParam T - The type of entries contained in the record.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const rec = new AoRecord({
26
+ * name: "John",
27
+ * age: 33,
28
+ * married: false,
29
+ * }).filter(({ key }) => key !== "age");
30
+ * ```
31
+ */
32
+ declare class AoRecord<T extends AoObject> {
33
+ private readonly _entries;
34
+ /**
35
+ *
36
+ * @param defaultEntries The default structure to initialize {@link AoRecord} entries
37
+ */
38
+ constructor(defaultEntries: T);
39
+ /**
40
+ * @readonly Gets keys of the current entries.
41
+ * @returns An array containing keys of the current entries
42
+ */
43
+ get keys(): (keyof T)[];
44
+ /**
45
+ * @readonly Gets values of the current entries.
46
+ * @returns An array containing values of the current entries
47
+ */
48
+ get values(): T[keyof T][];
49
+ /**
50
+ * @readonly Gets the current entries.
51
+ * @returns An array containing the current entries in form of {@link AoEntryUnion}
52
+ */
53
+ get entries(): AoEntryUnion<T>[];
54
+ /**
55
+ * Filters the current entries based on given condition.
56
+ * @param predicate The callback that iterates within {@link AoRecord} entries and
57
+ * provides the key and value in form of {@link AoEntryUnion} as parameter and must
58
+ * return a boolean type determines whether the current key should be remained in the
59
+ * resulting entries or not
60
+ * @returns A new instance of {@link AoRecord} containing the {@link Partial} filtered entries.
61
+ */
62
+ filter(predicate: (entry: AoEntryUnion<T>) => boolean): AoRecord<AoObject>;
63
+ /**
64
+ * Tests the trueness of the given condition for every entry.
65
+ * @param predicate The callback that iterates within {@link AoRecord} entries and
66
+ * provides the key and value in form of {@link AoEntryUnion} as parameter and must
67
+ * return a boolean type determines the condition for current entry
68
+ * @returns True, if the given conditions is true for every entry otherwise false
69
+ */
70
+ every(predicate: (entry: AoEntryUnion<T>) => boolean): boolean;
71
+ /**
72
+ * Tests the trueness of the given condition for atleast one entry.
73
+ * @param predicate The callback that iterates within {@link AoRecord} entries and
74
+ * provides the key and value in form of {@link AoEntryUnion} as parameter and must
75
+ * return a boolean type determines the condition for current entry
76
+ * @returns True, if the given conditions is true for atleast one entry otherwise false
77
+ */
78
+ some(predicate: (entry: AoEntryUnion<T>) => boolean): boolean;
79
+ }
80
+
81
+ export { AoRecord };