@carlsebastian/jsu 1.0.34

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 (59) hide show
  1. package/LICENSE +201 -0
  2. package/package.json +58 -0
  3. package/src/global.js +7 -0
  4. package/src/types/api/api.d.ts +147 -0
  5. package/src/types/api/element.d.ts +55 -0
  6. package/src/types/custom/custom.d.ts +8 -0
  7. package/src/types/custom/error/builder/error.builder.d.ts +78 -0
  8. package/src/types/custom/error/constructor/error.base.d.ts +4 -0
  9. package/src/types/custom/error/constructor/error.custom.d.ts +34 -0
  10. package/src/types/custom/error/constructor/error.meta.d.ts +18 -0
  11. package/src/types/custom/error/error.d.ts +5 -0
  12. package/src/types/custom/utils/custom.utils.d.ts +42 -0
  13. package/src/types/custom/utils/generator/generator.d.ts +92 -0
  14. package/src/types/dom/attr/attr.class.d.ts +81 -0
  15. package/src/types/dom/attr/attr.id.d.ts +23 -0
  16. package/src/types/dom/attr/attr.style.d.ts +32 -0
  17. package/src/types/dom/dom.d.ts +8 -0
  18. package/src/types/dom/element/create/element.create.d.ts +67 -0
  19. package/src/types/dom/element/getElementBy/dom.getElementBy.d.ts +71 -0
  20. package/src/types/dom/element/tag-verifier/verifier.d.ts +16 -0
  21. package/src/types/global.d.ts +13 -0
  22. package/src/types/guards/data-types/data-types.d.ts +5 -0
  23. package/src/types/guards/formats/formats.d.ts +5 -0
  24. package/src/types/guards/guards.d.ts +8 -0
  25. package/src/types/primitives/obj/obj.accessor.d.ts +5 -0
  26. package/src/types/primitives/obj/obj.iterator.d.ts +5 -0
  27. package/src/types/primitives/primitives.d.ts +8 -0
  28. package/src/types/primitives/str/str.d.ts +26 -0
  29. package/src/types/storage/local/storage.local.d.ts +86 -0
  30. package/src/types/storage/session/storage.session.d.ts +86 -0
  31. package/src/types/storage/storage.d.ts +8 -0
  32. package/src/utils/custom/custom.js +20 -0
  33. package/src/utils/custom/error/builder/error.builder.js +181 -0
  34. package/src/utils/custom/error/constructor/error.base.js +71 -0
  35. package/src/utils/custom/error/constructor/error.custom.js +107 -0
  36. package/src/utils/custom/error/error.js +23 -0
  37. package/src/utils/custom/utils/custom.utils.js +150 -0
  38. package/src/utils/custom/utils/generator/generator.js +222 -0
  39. package/src/utils/dom/attr/attr.class.js +186 -0
  40. package/src/utils/dom/attr/attr.id.js +64 -0
  41. package/src/utils/dom/attr/attr.style.js +128 -0
  42. package/src/utils/dom/dom.js +29 -0
  43. package/src/utils/dom/element/create/element.create.js +312 -0
  44. package/src/utils/dom/element/getElementBy/dom.getElementBy.js +171 -0
  45. package/src/utils/dom/element/query/dom.query.js +75 -0
  46. package/src/utils/dom/element/tag-verifier/verifier.js +60 -0
  47. package/src/utils/dom/lifecycle/mount.js +48 -0
  48. package/src/utils/dom/lifecycle/unmount.js +43 -0
  49. package/src/utils/guards/data-types/data-types.js +201 -0
  50. package/src/utils/guards/formats/formats.js +274 -0
  51. package/src/utils/guards/guards.js +21 -0
  52. package/src/utils/primitives/obj/obj.accessor.js +242 -0
  53. package/src/utils/primitives/obj/obj.iterator.js +148 -0
  54. package/src/utils/primitives/primitives.js +23 -0
  55. package/src/utils/primitives/str/str.js +52 -0
  56. package/src/utils/storage/local/storage.local.js +236 -0
  57. package/src/utils/storage/session/storage.session.js +236 -0
  58. package/src/utils/storage/storage.js +59 -0
  59. package/src/utils/variables.js +78 -0
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Configuration for generator's contents.
3
+ */
4
+ interface GeneratorAPIConfig {
5
+ /**
6
+ * A configuration state for including or excluding numerical values at generator's content.
7
+ */
8
+ numbers?: boolean;
9
+
10
+ /**
11
+ * A configuration state for including or excluding lowercase characters at generator's content.
12
+ */
13
+ lowercase?: boolean;
14
+
15
+ /**
16
+ * A configuration state for including or excluding symbol characters at generator's contents.
17
+ */
18
+ symbols?: boolean;
19
+
20
+ /**
21
+ * A configuration state for including or excluding uppercase characters at generator's contents.
22
+ */
23
+ uppercase?: boolean;
24
+
25
+ /**
26
+ * A configuration state for secure random values generator of generator's contents.
27
+ *
28
+ * ***States***:
29
+ * - `true`: Sets entropy to 'window.crypto' for secure generator's randomized value (32-bits).
30
+ * - `false`: Sets entropy to `Math.random()` for fast but not secure generator's randomized contents.
31
+ */
32
+ secure?: boolean;
33
+ }
34
+
35
+ /**
36
+ * A collection of randomized content generators.
37
+ */
38
+ class GeneratorAPI {
39
+ /**
40
+ * The `size` or `length` of contents of generators to generate.
41
+ */
42
+ Size: number;
43
+
44
+ /**
45
+ * The maximum `size` or `length` of contents of generators to generate.
46
+ */
47
+ readonly Max: number;
48
+
49
+ /**
50
+ * Configuration for generator's contents.
51
+ */
52
+ Conf?: GeneratorAPIConfig;
53
+
54
+ /**
55
+ * A collection of characters that is used in generators as their contents referenced pool.
56
+ */
57
+ readonly Chars?: string[];
58
+
59
+ /**
60
+ * Constructs the size and configuration for generator's contents.
61
+ *
62
+ * ***Notes***:
63
+ * - If `size` is less than the generator's minimum `size` or higher than its maximum `size`, it will be
64
+ * clamped to it minimum and/or maximum `size`.
65
+ * - If both of configuration `lowercase` and `uppercase` are set to `false` state, the generator's would
66
+ * automatically use uppercase as preferred characters.
67
+ * - By default, the secure randomized of generators are disabled for performance efficiency, you can just enabled
68
+ * it for security related use for a little trade of performance.
69
+ *
70
+ * @param size - The `size` or `length` of generator's contents to generate.
71
+ * @param conf - A configuration for generator's contents.
72
+ */
73
+ constructor(size: number, conf?: GeneratorAPIConfig);
74
+
75
+ /**
76
+ * Generates a random integer value and returns it.
77
+ *
78
+ * @param min - The minimum or lowest integer value it can generate. (Default: 0)
79
+ * @param max - The maximum or highest integer value it can generate. (Default: 1)
80
+ */
81
+ readonly RandomInteger(min?: number, max?: number): number;
82
+
83
+ /**
84
+ * Generates a set of randomized characters in lowercase and/or uppercase.
85
+ */
86
+ readonly RandomCharacters(): string;
87
+
88
+ /**
89
+ * Generates a new set of randomized tokens that can be used for ids, session id, etc.
90
+ */
91
+ readonly NewToken(): string;
92
+ }
@@ -0,0 +1,81 @@
1
+ interface DOMClassOfAPI {
2
+ /**
3
+ * Search the given `class` token at the element's `DOMTokenList`.
4
+ *
5
+ * ***Notes***:
6
+ * - If the token is not in string format, it would automatically return a `false` state result.
7
+ *
8
+ * @param token - The `class` token to search.
9
+ */
10
+ Has(token: string): boolean;
11
+
12
+ /**
13
+ * Search every of the given collection of `class` tokens at the element's `DOMTokenList`.
14
+ *
15
+ * ***Notes***:
16
+ * - If one or more of token at collection of token are not in string format, It would automatically
17
+ * return a `false` state result.
18
+ *
19
+ * @param tokens - The collection of `class` token to search.
20
+ */
21
+ Has(...tokens: string[]): boolean;
22
+
23
+ /**
24
+ * Retrieves the current collection of element's `DOMTokenList`.
25
+ */
26
+ List(): DOMTokenList;
27
+
28
+ /**
29
+ * Removes the given `class` token at the element's `DOMTokenList`.
30
+ *
31
+ * @param token - The `class` token to remove.
32
+ */
33
+ Remove(token: string): boolean;
34
+
35
+ /**
36
+ * Removes the given `class` collection of tokens at the element's `DOMTokenList`.
37
+ *
38
+ * @param token - The collection of `class` token to remove.
39
+ */
40
+ Remove(...tokens: string[]): boolean;
41
+
42
+ /**
43
+ * Sets a new given `class` token at the element's `DOMTokenList`.
44
+ *
45
+ * @param token - The `class` token to set.
46
+ */
47
+ Set(token: string): void;
48
+
49
+ /**
50
+ * Sets a collection of new given `class` tokens at the element's `DOMTokenList`.
51
+ *
52
+ * @param token - The collection of `class` token to set.
53
+ */
54
+ Set(...tokens: string[]): void;
55
+
56
+ /**
57
+ * Toggles the state of the given `class` token at the element's `DOMTokenList`.
58
+ *
59
+ * ***States***:
60
+ * - TRUE: The given `class` token will be added at the element's `class` attribute and `DOMTokenList`.
61
+ * - FALSE: The given `class` token will be remove at the element's `class` attribute and `DOMTokenList`.
62
+ *
63
+ * @param token - The `class` token to toggle.
64
+ * @param forceState - Forcefully set the state of the given `class` token, despite its current state.
65
+ * @returns The new state of toggled `class` token.
66
+ */
67
+ Toggle(token: string, forceState?: boolean): boolean;
68
+
69
+ /**
70
+ * Toggles the state of the given `class` collection tokens at the element's `DOMTokenList`.
71
+ *
72
+ * ***States***:
73
+ * - TRUE: A certain collection of `class` token will be added at the element's `class` attribute and `DOMTokenList`.
74
+ * - FALSE: A certain collection of `class` token will be remove at the element's `class` attribute and `DOMTokenList`.
75
+ *
76
+ * @param token - The `class` token to toggle.
77
+ * @param forceState - Forcefully set the state of the given `class` collection token, despite their current state.
78
+ * @returns The collection of new states of toggled `class` tokens.
79
+ */
80
+ Toggle(tokens: string[], forceState?: boolean): boolean[];
81
+ }
@@ -0,0 +1,23 @@
1
+ interface DOMIdOfAPI {
2
+ /**
3
+ * The current unique `id` value of the element.
4
+ *
5
+ * ***Note***:
6
+ * - If the element has no `id`, the value of this property would be '\<NO_ID\>'.
7
+ */
8
+ Value: string;
9
+
10
+ /**
11
+ * Removes the `id` attribute of the element.
12
+ * @returns The state result of `id` removal process.
13
+ */
14
+ Remove(): boolean;
15
+
16
+ /**
17
+ * Set (or change) a unique `id` attribute of element.
18
+ *
19
+ * @param id - The new unique `id` of element.
20
+ * @returns The new or current unique `id` of the element.
21
+ */
22
+ Set(id: string): string;
23
+ }
@@ -0,0 +1,32 @@
1
+ interface DOMStyleOfAPI {
2
+ /**
3
+ * Set the given `CSSStyle` object properties from the element.
4
+ *
5
+ * @param CSSObj - The `CSSStyle` object properties to set.
6
+ */
7
+ Set(CSSObj: CSSDeclaration): void;
8
+
9
+ /**
10
+ * Removes the given `CSSStyle` property from the element.
11
+ *
12
+ * @param CSSProperty - The `CSSStyle` property to remove.
13
+ * @returns The state of `CSSStyle` property removal process result.
14
+ */
15
+ Remove(CSSProperty: keyof CSSDeclaration): boolean;
16
+
17
+ /**
18
+ * Removes the given `CSSStyle` properties collection from the element.
19
+ *
20
+ * @param CSSProperty - The collection of `CSSStyle` properties to remove.
21
+ * @returns The state of `CSSStyle` properties removal process result.
22
+ */
23
+ Remove(...CSSProperties: (keyof CSSDeclaration)[]): boolean;
24
+
25
+ /**
26
+ * Retrieves the current data value of the given `CSSStyle` property of the element.
27
+ *
28
+ * @param CSSProperty - The `CSSStyle` property to retrieve.
29
+ * @returns The retrieved data of given `CSSStyle` property.
30
+ */
31
+ Get(CSSProperty: keyof CSSDeclaration): string | null;
32
+ }
@@ -0,0 +1,8 @@
1
+ declare global {
2
+ /**
3
+ * A collection of customized and/or enhanced `DocumentObjectModel` methods.
4
+ */
5
+ readonly var DOM: DomAPI;
6
+ }
7
+
8
+ export { }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * A collection of `DOM` element creation API methods.
3
+ */
4
+ interface DOMCreateAPI {
5
+ /**
6
+ * Generates an instance of `HTMLElement` with the given qualified tag.
7
+ *
8
+ * @param tag - The tag of `HTMLElement` to generate.
9
+ *
10
+ * @throws {ArgumentError} - When parameter tag is not in string format.
11
+ * @throws {NoSuchElementTagError} - When the given tag of `HTMLElement` is not qualified.
12
+ */
13
+ HTMLElement<T extends keyof HTMLElementTags>(tag: T): ResolveTag<T>;
14
+
15
+ /**
16
+ * Generates an instance of `HTMLElement` with the given qualified tag.
17
+ *
18
+ * @param tag - The tag of `HTMLElement` to generate.
19
+ * @param conf - A configuration properties for `HTMLElement` instance.
20
+ *
21
+ * @throws {ArgumentError} - When parameter tag is not in string format.
22
+ * @throws {NoSuchElementTagError} - When the given tag of `HTMLElement` is not qualified.
23
+ */
24
+ HTMLElement<T extends keyof HTMLElementTags>(tag: T, conf?: HTMLElementConfig): ResolveTag<T>;
25
+
26
+ /**
27
+ * Generates an instance of `MathMLElement` with the given qualified tag.
28
+ *
29
+ * @param tag - The tag of `MathMLElement` to generate.
30
+ *
31
+ * @throws {ArgumentError} - When parameter tag is not in string format.
32
+ * @throws {NoSuchElementTagError} - When the given tag of `MathMLElement` is not qualified.
33
+ */
34
+ MathElement<T extends keyof MathElementTags>(tag: T): ResolveTag<T>;
35
+
36
+ /**
37
+ * Generates an instance of `MathMLElement` with the given qualified tag.
38
+ *
39
+ * @param tag - The tag of `MathMLElement` to generate.
40
+ * @param conf - A configuration properties for `MathMLElement` instance.
41
+ *
42
+ * @throws {ArgumentError} - When parameter tag is not in string format.
43
+ * @throws {NoSuchElementTagError} - When the given tag of `MathMLElement` is not qualified.
44
+ */
45
+ MathElement<T extends keyof MathElementTags>(tag: T, conf?: MathElementConfig): ResolveTag<T>;
46
+
47
+ /**
48
+ * Generates an instance of `SVGElement` with the given qualified tag.
49
+ *
50
+ * @param tag - The tag of `SVGElement` to generate.
51
+ *
52
+ * @throws {ArgumentError} - When parameter tag is not in string format.
53
+ * @throws {NoSuchElementTagError} - When the given tag of `SVGElement` is not qualified.
54
+ */
55
+ SVGElement<T extends keyof SVGElementTags>(tag: T): ResolveTag<T>;
56
+
57
+ /**
58
+ * Generates an instance of `SVGElement` with the given qualified tag.
59
+ *
60
+ * @param tag - The tag of `SVGElement` to generate.
61
+ * @param conf - A configuration properties for `SVGElement` instance.
62
+ *
63
+ * @throws {ArgumentError} - When parameter tag is not in string format.
64
+ * @throws {NoSuchElementTagError} - When the given tag of `SVGElement` is not qualified.
65
+ */
66
+ SVGElement<T extends keyof SVGElementTags>(tag: T, conf?: SVGElementConfig): ResolveTag<T>;
67
+ }
@@ -0,0 +1,71 @@
1
+ interface DOMGetElementByAPI {
2
+ /**
3
+ * Search and retrieves the elements with the given class name.
4
+ *
5
+ * @param cls - The class name of element to search.
6
+ * @returns The collection of elements with the given class name.
7
+ */
8
+ ClassName(cls: string): HTMLCollectionOf<Element>;
9
+
10
+ /**
11
+ * Search and retrieves the elements with the given class name.
12
+ *
13
+ * @param cls - The class name of element to search.
14
+ * @param root - The parent element of where to search the elements with the given class name. (Default: Document)
15
+ * @returns The collection of elements with the given class name.
16
+ */
17
+ ClassName(cls: string, root?: ParentNode): HTMLCollectionOf<Element>;
18
+
19
+ /**
20
+ * Search and retrieves the element with the given unique `id`.
21
+ *
22
+ * @param id - The unique `id` of element to search.
23
+ * @returns The element with the given unique `id`.
24
+ */
25
+ ID(id: string): HTMLElement | null;
26
+
27
+ /**
28
+ * Search and retrieves the element with the given unique `id`.
29
+ *
30
+ * @param id - The unique `id` of element to search.
31
+ * @param root - The root element of where to search the element with the given `unique` id. (Default: Document)
32
+ * @returns The element with the given unique `id`.
33
+ */
34
+ ID(id: string, root?: ParentNode): HTMLElement | null;
35
+
36
+ /**
37
+ * Search and retrieves the elements with the given tag.
38
+ *
39
+ * @param id - The tag of element to search.
40
+ * @returns The collection of elements with the given tag.
41
+ */
42
+ TagName<T extends keyof ElementTags>(tag: T): ResolveTag<T>;
43
+
44
+ /**
45
+ * Search and retrieves the elements with the given tag.
46
+ *
47
+ * @param id - The tag of element to search.
48
+ * @param root - The parent element of where to search the elements with the given tag. (Default: Document)
49
+ * @returns The collection of elements with the given tag.
50
+ */
51
+ TagName<T extends keyof ElementTags>(tag: T, root?: ParentNode): ResolveTag<T>;
52
+
53
+ /**
54
+ * Search and retrieves the elements with the given XML namespace and tag.
55
+ *
56
+ * @param namespace - The XML namespace of element.
57
+ * @param tag - The tag of element with the given XML namespace to search.
58
+ * @returns The collection of elements with the given XML namespace and tag.
59
+ */
60
+ TagNameNS<NS extends XMLNameSpace, T extends keyof ElementTags>(namespace: NS, tag: T): ResolveTagNS<NS, T>;
61
+
62
+ /**
63
+ * Search and retrieves the elements with the given XML namespace and tag.
64
+ *
65
+ * @param namespace - The XML namespace of element.
66
+ * @param tag - The tag of element with the given XML namespace to search.
67
+ * @param root - The parent element of where to search the elements with the given XML namespace and tag. (Default: Document)
68
+ * @returns The collection of elements with the given XML namespace and tag.
69
+ */
70
+ TagNameNS<NS extends XMLNameSpace, T extends keyof ElementTags>(namespace: NS, tag: T, root?: ParentNode): ResolveTagNS<NS, T>;
71
+ }
@@ -0,0 +1,16 @@
1
+ interface VerifierTagAPI<K extends keyof ElementTags> {
2
+ /**
3
+ * Verifies the given tag of element whether if its qualified as instance of `HTMLElement`.
4
+ */
5
+ HTMLElement(): ResolveTag<K>;
6
+
7
+ /**
8
+ * Verifies the given tag of element whether if its qualified as instance of `MathMLElement`.
9
+ */
10
+ MathElement(): ResolveTag<K>;
11
+
12
+ /**
13
+ * Verifies the given tag of element whether if its qualified as instance of `SVGElement`.
14
+ */
15
+ SVGElement(): ResolveTag<K>;
16
+ }
@@ -0,0 +1,13 @@
1
+ declare global {
2
+ /**
3
+ * A collection of enhanced and custom utilities modules.
4
+ */
5
+ readonly var Utils: EnhancedGlobalUtilsAPI;
6
+
7
+ /**
8
+ * A enhanced version collection of element retrieval methods.
9
+ */
10
+ readonly var GetElementBy: DOMGetElementByAPI;
11
+ }
12
+
13
+ export { }
@@ -0,0 +1,5 @@
1
+ type DataTypesModule = typeof import("../../../utils/guards/data-types/data-types.js");
2
+
3
+ type GuardsDataTypesAPI = {
4
+ [K in keyof DataTypesModule]: DataTypesModule[K];
5
+ }
@@ -0,0 +1,5 @@
1
+ type FormatsModule = typeof import("../../../utils/guards/formats/formats.js");
2
+
3
+ type GuardsFormatAPI = {
4
+ [K in keyof FormatsModule]: FormatsModule[K];
5
+ }
@@ -0,0 +1,8 @@
1
+ declare global {
2
+ /**
3
+ * A collection of data types and formats guards validation.
4
+ */
5
+ readonly var Guards: GuardsAPI;
6
+ }
7
+
8
+ export { }
@@ -0,0 +1,5 @@
1
+ type ObjAccessorModule = typeof import("../../../utils/primitives/obj/obj.accessor.js");
2
+
3
+ type PrimitivesObjAccessorAPI = {
4
+ [K in keyof ObjAccessorModule]: ObjAccessorModule[K];
5
+ }
@@ -0,0 +1,5 @@
1
+ type ObjIteratorModule = typeof import("../../../utils/primitives/obj/obj.iterator.js");
2
+
3
+ type PrimitivesIteratorAPI = {
4
+ [K in keyof ObjIteratorModule]: ObjIteratorModule[K];
5
+ }
@@ -0,0 +1,8 @@
1
+ declare global {
2
+ /**
3
+ * A enhanced version of primitive methods API.
4
+ */
5
+ readonly var Primitives: PrimitivesAPI;
6
+ }
7
+
8
+ export { }
@@ -0,0 +1,26 @@
1
+ interface PrimitivesStrAPI {
2
+ /**
3
+ * A collection of characters.
4
+ */
5
+ readonly Chars: {
6
+ /**
7
+ * A collection of numeric characters. (`0-9`)
8
+ */
9
+ Numeric(): string;
10
+
11
+ /**
12
+ * A collection of lowercase characters. (`a-z`)
13
+ */
14
+ Lowercase(): string;
15
+
16
+ /**
17
+ * A collection of special or symbol characters. (`~!@#$...`)
18
+ */
19
+ Symbols(): string;
20
+
21
+ /**
22
+ * A collection of uppercase characters. (`A-Z`)
23
+ */
24
+ Uppercase(): string;
25
+ }
26
+ }
@@ -0,0 +1,86 @@
1
+ type LocalStorageResponse<OtherMeta extends {} = {}> = {
2
+ State: boolean;
3
+ Reason?: "DUPLICATE_KEY_FOUND" | "INVALID_KEY" | "NO_SUCH_KEY" | "NOT_SUPPORTED"
4
+ } & OtherMeta;
5
+
6
+ interface LocalStorageAPI {
7
+ /**
8
+ * The current total count of items at `localStorage`.
9
+ */
10
+ ITEMS_COUNT: number;
11
+
12
+ /**
13
+ * The current total accumulated bytes size of items at `localStorage`.
14
+ *
15
+ * ***Notes***
16
+ * - This does not tells or let you know on how much of a bytes size is remaining at your
17
+ * browser `localStorage` API.
18
+ *
19
+ * @returns The total accumulated bytes size.
20
+ */
21
+ SIZE(): number;
22
+
23
+ /**
24
+ * Indicates whether if the `localStorage` API is supported on your or user's current browser environment version.
25
+ */
26
+ readonly IS_SUPPORTED: boolean;
27
+
28
+ /**
29
+ * Retrieves the stored data of the specified `localStorage` key.
30
+ *
31
+ * ***Notes***
32
+ * - Automatically parsed the `JSON` object of the retrieved data. If you want it to
33
+ * be in raw format, provide a `false` state as its second parameter.
34
+ *
35
+ * @param localKey - The access key of `localStorage` item.
36
+ * @returns The retrieved data at `localStorage`.
37
+ */
38
+ GET(localKey: string): LocalStorageResponse<{ Data: unknown | undefined }>;
39
+
40
+ /**
41
+ * Retrieves the stored data of the specified `localStorage` key.
42
+ *
43
+ * ***Notes***
44
+ * - Automatically parsed the `JSON` object of the retrieved data. If you want it to
45
+ * be in raw format, provide a `false` state as its second parameter.
46
+ *
47
+ * @param localKey - The access key of storage item to retrieve.
48
+ * @param autoParse - A state for controlling whether if it should automatically parse the retrieved data at `localStorage` item or not.
49
+ * @returns The retrieved data at `localStorage`.
50
+ */
51
+ GET<B extends boolean = true>(localKey: string, autoParse?: B): LocalStorageResponse<{
52
+ Data: (B extends true ? unknown : string) | undefined;
53
+ }>;
54
+
55
+ /**
56
+ * Store a new item with its data at the `localStorage` API.
57
+ *
58
+ * ***Notes***:
59
+ * - If there's a already storage item with the same `key` at `localStorage` API, it will automatically
60
+ * terminate the process and returns a default response object with reason in it.
61
+ * - Automatically converts the specified data to store along with the new storage item into its stringified
62
+ * format using `JSON.stringify` built-in method.
63
+ *
64
+ * @param localKey - The access key of new storage item.
65
+ * @param data - The data of the new storage item.
66
+ * @returns The response object of this process.
67
+ */
68
+ NEW(localKey: string, data?: any): LocalStorageResponse;
69
+
70
+ /**
71
+ * Removes the specified `key` of a storage item at `localStorage` API.
72
+ *
73
+ * @param localKey - The access key of storage item to remove.
74
+ * @returns The response object of this process.
75
+ */
76
+ REMOVE(localKey: string): LocalStorageResponse;
77
+
78
+ /**
79
+ * Updates the data of the specified `key` of storage item with the given new data for it at `localStorage` API.
80
+ *
81
+ * @param localKey - The access key of storage item to update.
82
+ * @param newData - The new data to set at storage item.
83
+ * @returns The response object of this process.
84
+ */
85
+ UPDATE(localKey: string, newData?: any): LocalStorageResponse;
86
+ }
@@ -0,0 +1,86 @@
1
+ type SessionStorageResponse<OtherMeta extends {} = {}> = {
2
+ State: boolean;
3
+ Reason?: "DUPLICATE_KEY_FOUND" | "INVALID_KEY" | "NO_SUCH_KEY" | "NOT_SUPPORTED"
4
+ } & OtherMeta;
5
+
6
+ interface SessionStorageAPI {
7
+ /**
8
+ * The current total count of items at `sessionStorage`.
9
+ */
10
+ ITEMS_COUNT: number;
11
+
12
+ /**
13
+ * The current total accumulated bytes size of items at `sessionStorage`.
14
+ *
15
+ * ***Notes***
16
+ * - This does not tells or let you know on how much of a bytes size is remaining at your
17
+ * browser `sessionStorage` API.
18
+ *
19
+ * @returns The total accumulated bytes size.
20
+ */
21
+ SIZE(): number;
22
+
23
+ /**
24
+ * Indicates whether if the `sessionStorage` API is supported on your or user's current browser environment version.
25
+ */
26
+ readonly IS_SUPPORTED: boolean;
27
+
28
+ /**
29
+ * Retrieves the stored data of the specified `sessionStorage` key.
30
+ *
31
+ * ***Notes***
32
+ * - Automatically parsed the `JSON` object of the retrieved data. If you want it to
33
+ * be in raw format, provide a `false` state as its second parameter.
34
+ *
35
+ * @param sessionKey - The access key of `sessionStorage` item.
36
+ * @returns The retrieved data at `sessionStorage`.
37
+ */
38
+ GET(sessionKey: string): SessionStorageResponse<{ Data: unknown | undefined }>;
39
+
40
+ /**
41
+ * Retrieves the stored data of the specified `sessionStorage` key.
42
+ *
43
+ * ***Notes***
44
+ * - Automatically parsed the `JSON` object of the retrieved data. If you want it to
45
+ * be in raw format, provide a `false` state as its second parameter.
46
+ *
47
+ * @param sessionKey - The access key of storage item to retrieve.
48
+ * @param autoParse - A state for controlling whether if it should automatically parse the retrieved data at `sessionStorage` item or not.
49
+ * @returns The retrieved data at `sessionStorage`.
50
+ */
51
+ GET<B extends boolean = true>(sessionKey: string, autoParse?: B): SessionStorageResponse<{
52
+ Data: (B extends true ? unknown : string) | undefined;
53
+ }>;
54
+
55
+ /**
56
+ * Store a new item with its data at the `sessionStorage` API.
57
+ *
58
+ * ***Notes***:
59
+ * - If there's a already storage item with the same `key` at `sessionStorage` API, it will automatically
60
+ * terminate the process and returns a default response object with reason in it.
61
+ * - Automatically converts the specified data to store along with the new storage item into its stringified
62
+ * format using `JSON.stringify` built-in method.
63
+ *
64
+ * @param sessionKey - The access key of new storage item.
65
+ * @param data - The data of the new storage item.
66
+ * @returns The response object of this process.
67
+ */
68
+ NEW(sessionKey: string, data?: any): SessionStorageResponse;
69
+
70
+ /**
71
+ * Removes the specified `key` of a storage item at `sessionStorage` API.
72
+ *
73
+ * @param sessionKey - The access key of storage item to remove.
74
+ * @returns The response object of this process.
75
+ */
76
+ REMOVE(sessionKey: string): SessionStorageResponse;
77
+
78
+ /**
79
+ * Updates the data of the specified `key` of storage item with the given new data for it at `sessionStorage` API.
80
+ *
81
+ * @param sessionKey - The access key of storage item to update.
82
+ * @param newData - The new data to set at storage item.
83
+ * @returns The response object of this process.
84
+ */
85
+ UPDATE(sessionKey: string, newData?: any): SessionStorageResponse;
86
+ }
@@ -0,0 +1,8 @@
1
+ declare global {
2
+ /**
3
+ * A enhanced version of `StorageAPI` methods.
4
+ */
5
+ readonly var STORAGE: StorageAPI;
6
+ }
7
+
8
+ export { }