j-kompact 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.
- package/LICENSE +151 -0
- package/dist/Array.d.ts +110 -0
- package/dist/Array.js +298 -0
- package/dist/Boolean.d.ts +7 -0
- package/dist/Boolean.js +18 -0
- package/dist/Comparison.d.ts +22 -0
- package/dist/Comparison.js +64 -0
- package/dist/Date.d.ts +32 -0
- package/dist/Date.js +106 -0
- package/dist/Dynamic.d.ts +9 -0
- package/dist/Dynamic.js +28 -0
- package/dist/Error.d.ts +4 -0
- package/dist/Error.js +7 -0
- package/dist/Iteration.d.ts +21 -0
- package/dist/Iteration.js +51 -0
- package/dist/Manipulation.d.ts +7 -0
- package/dist/Manipulation.js +19 -0
- package/dist/Object.d.ts +58 -0
- package/dist/Object.js +161 -0
- package/dist/String.d.ts +31 -0
- package/dist/String.js +57 -0
- package/dist/Type.d.ts +3 -0
- package/dist/Type.js +3 -0
- package/dist/google/spreadsheet/Utilites.d.ts +8 -0
- package/dist/google/spreadsheet/Utilites.js +18 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/global.d.ts +10 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Mozilla Public License
|
|
2
|
+
Version 2.0
|
|
3
|
+
1. Definitions
|
|
4
|
+
1.1. “Contributor”
|
|
5
|
+
means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software.
|
|
6
|
+
|
|
7
|
+
1.2. “Contributor Version”
|
|
8
|
+
means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor’s Contribution.
|
|
9
|
+
|
|
10
|
+
1.3. “Contribution”
|
|
11
|
+
means Covered Software of a particular Contributor.
|
|
12
|
+
|
|
13
|
+
1.4. “Covered Software”
|
|
14
|
+
means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof.
|
|
15
|
+
|
|
16
|
+
1.5. “Incompatible With Secondary Licenses”
|
|
17
|
+
means
|
|
18
|
+
|
|
19
|
+
that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or
|
|
20
|
+
|
|
21
|
+
that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License.
|
|
22
|
+
|
|
23
|
+
1.6. “Executable Form”
|
|
24
|
+
means any form of the work other than Source Code Form.
|
|
25
|
+
|
|
26
|
+
1.7. “Larger Work”
|
|
27
|
+
means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software.
|
|
28
|
+
|
|
29
|
+
1.8. “License”
|
|
30
|
+
means this document.
|
|
31
|
+
|
|
32
|
+
1.9. “Licensable”
|
|
33
|
+
means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License.
|
|
34
|
+
|
|
35
|
+
1.10. “Modifications”
|
|
36
|
+
means any of the following:
|
|
37
|
+
|
|
38
|
+
any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or
|
|
39
|
+
|
|
40
|
+
any new file in Source Code Form that contains any Covered Software.
|
|
41
|
+
|
|
42
|
+
1.11. “Patent Claims” of a Contributor
|
|
43
|
+
means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version.
|
|
44
|
+
|
|
45
|
+
1.12. “Secondary License”
|
|
46
|
+
means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses.
|
|
47
|
+
|
|
48
|
+
1.13. “Source Code Form”
|
|
49
|
+
means the form of the work preferred for making modifications.
|
|
50
|
+
|
|
51
|
+
1.14. “You” (or “Your”)
|
|
52
|
+
means an individual or a legal entity exercising rights under this License. For legal entities, “You” includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, “control” means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
|
|
53
|
+
|
|
54
|
+
2. License Grants and Conditions
|
|
55
|
+
2.1. Grants
|
|
56
|
+
Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
|
|
57
|
+
|
|
58
|
+
under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and
|
|
59
|
+
|
|
60
|
+
under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version.
|
|
61
|
+
|
|
62
|
+
2.2. Effective Date
|
|
63
|
+
The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution.
|
|
64
|
+
|
|
65
|
+
2.3. Limitations on Grant Scope
|
|
66
|
+
The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor:
|
|
67
|
+
|
|
68
|
+
for any code that a Contributor has removed from Covered Software; or
|
|
69
|
+
|
|
70
|
+
for infringements caused by: (i) Your and any other third party’s modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or
|
|
71
|
+
|
|
72
|
+
under Patent Claims infringed by Covered Software in the absence of its Contributions.
|
|
73
|
+
|
|
74
|
+
This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4).
|
|
75
|
+
|
|
76
|
+
2.4. Subsequent Licenses
|
|
77
|
+
No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3).
|
|
78
|
+
|
|
79
|
+
2.5. Representation
|
|
80
|
+
Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License.
|
|
81
|
+
|
|
82
|
+
2.6. Fair Use
|
|
83
|
+
This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents.
|
|
84
|
+
|
|
85
|
+
2.7. Conditions
|
|
86
|
+
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1.
|
|
87
|
+
|
|
88
|
+
3. Responsibilities
|
|
89
|
+
3.1. Distribution of Source Form
|
|
90
|
+
All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients’ rights in the Source Code Form.
|
|
91
|
+
|
|
92
|
+
3.2. Distribution of Executable Form
|
|
93
|
+
If You distribute Covered Software in Executable Form then:
|
|
94
|
+
|
|
95
|
+
such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and
|
|
96
|
+
|
|
97
|
+
You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients’ rights in the Source Code Form under this License.
|
|
98
|
+
|
|
99
|
+
3.3. Distribution of a Larger Work
|
|
100
|
+
You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s).
|
|
101
|
+
|
|
102
|
+
3.4. Notices
|
|
103
|
+
You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies.
|
|
104
|
+
|
|
105
|
+
3.5. Application of Additional Terms
|
|
106
|
+
You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction.
|
|
107
|
+
|
|
108
|
+
4. Inability to Comply Due to Statute or Regulation
|
|
109
|
+
If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it.
|
|
110
|
+
|
|
111
|
+
5. Termination
|
|
112
|
+
5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice.
|
|
113
|
+
|
|
114
|
+
5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate.
|
|
115
|
+
|
|
116
|
+
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination.
|
|
117
|
+
|
|
118
|
+
6. Disclaimer of Warranty
|
|
119
|
+
Covered Software is provided under this License on an “as is” basis, without warranty of any kind, either expressed, implied, or statutory, including, without limitation, warranties that the Covered Software is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of the Covered Software is with You. Should any Covered Software prove defective in any respect, You (not any Contributor) assume the cost of any necessary servicing, repair, or correction. This disclaimer of warranty constitutes an essential part of this License. No use of any Covered Software is authorized under this License except under this disclaimer.
|
|
120
|
+
|
|
121
|
+
7. Limitation of Liability
|
|
122
|
+
Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall any Contributor, or anyone who distributes Covered Software as permitted above, be liable to You for any direct, indirect, special, incidental, or consequential damages of any character including, without limitation, damages for lost profits, loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. This limitation of liability shall not apply to liability for death or personal injury resulting from such party’s negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You.
|
|
123
|
+
|
|
124
|
+
8. Litigation
|
|
125
|
+
Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party’s ability to bring cross-claims or counter-claims.
|
|
126
|
+
|
|
127
|
+
9. Miscellaneous
|
|
128
|
+
This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor.
|
|
129
|
+
|
|
130
|
+
10. Versions of the License
|
|
131
|
+
10.1. New Versions
|
|
132
|
+
Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number.
|
|
133
|
+
|
|
134
|
+
10.2. Effect of New Versions
|
|
135
|
+
You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward.
|
|
136
|
+
|
|
137
|
+
10.3. Modified Versions
|
|
138
|
+
If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License).
|
|
139
|
+
|
|
140
|
+
10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
|
|
141
|
+
If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached.
|
|
142
|
+
|
|
143
|
+
Exhibit A - Source Code Form License Notice
|
|
144
|
+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
145
|
+
|
|
146
|
+
If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice.
|
|
147
|
+
|
|
148
|
+
You may add additional accurate notices of copyright ownership.
|
|
149
|
+
|
|
150
|
+
Exhibit B - “Incompatible With Secondary Licenses” Notice
|
|
151
|
+
This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0.
|
package/dist/Array.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { MLObject } from './Object.ts';
|
|
2
|
+
import { And, Ascending, Descending, Or } from './Type.ts';
|
|
3
|
+
export declare const isArray: (arg: any) => arg is any[];
|
|
4
|
+
type MLArrayOptions = {
|
|
5
|
+
flatting?: boolean;
|
|
6
|
+
deleteNull?: boolean;
|
|
7
|
+
unique?: boolean;
|
|
8
|
+
withLog?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type callbackFunction<T, U> = (value: T, no: number, array: MLArray<T>) => U;
|
|
11
|
+
export type OrderBy = typeof Ascending | typeof Descending;
|
|
12
|
+
export type Logic = typeof And | typeof Or;
|
|
13
|
+
export declare class MLArray<T> extends Array<T> {
|
|
14
|
+
batchSize: number;
|
|
15
|
+
withLog: boolean;
|
|
16
|
+
static from<T>(iterable: Iterable<T> | Array<T>): MLArray<T>;
|
|
17
|
+
static from<T>(arrayLike: ArrayLike<T>): MLArray<T>;
|
|
18
|
+
static from<T, U>(arrayLike: ArrayLike<T> | Iterable<T>, mapfn: (v: T, k: number) => U, thisArg?: any): MLArray<U>;
|
|
19
|
+
static repeat<T>(valueOrFunction: T | ((value: T, no: number) => MLArray<T>), count?: number): T[];
|
|
20
|
+
static init<const T>(array?: T | Array<T | {
|
|
21
|
+
[s: string]: T;
|
|
22
|
+
}>, options?: MLArrayOptions): MLArray<T extends readonly any[] ? T[number] : T>;
|
|
23
|
+
findIndexInOrder(valueOrFunc: callbackFunction<T, boolean | T>, order?: number): undefined;
|
|
24
|
+
map<U>(callbackFunc: callbackFunction<T, U>): MLArray<U>;
|
|
25
|
+
map(callbackFunc: (arg0: any, arg1: any, arg2: any) => any, thisArg?: any): any;
|
|
26
|
+
mapToObject(callbackFn: (value: T, no: number, array: MLArray<T>) => unknown): any;
|
|
27
|
+
castToString(): MLArray<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Mengubah array yang ada di dalam MLArray biasa menjadi MLArray
|
|
30
|
+
*/
|
|
31
|
+
mapCast(callbackFunc: callbackFunction<T, any>): MLArray<any>;
|
|
32
|
+
/**
|
|
33
|
+
* Fungsi alternatif dari indexOf() dengan sistem one-based index
|
|
34
|
+
*/
|
|
35
|
+
locationOf(value: T): number;
|
|
36
|
+
slice(start: number, end: number | null): MLArray<T>;
|
|
37
|
+
slice(start?: number, end?: number): T[];
|
|
38
|
+
/**
|
|
39
|
+
* Mengabungkan array dengan pemisah (default: 'dan') di akhir untuk keterbacaan
|
|
40
|
+
*/
|
|
41
|
+
readableJoin(options?: {
|
|
42
|
+
and?: string;
|
|
43
|
+
separator?: string;
|
|
44
|
+
}): string;
|
|
45
|
+
push(...values: T[] | [{
|
|
46
|
+
many: boolean;
|
|
47
|
+
}]): MLArray<T>;
|
|
48
|
+
push(...values: T[]): number;
|
|
49
|
+
filter(predicate: callbackFunction<T, boolean>): MLArray<T>;
|
|
50
|
+
filter(predicate: (arg0: any, arg1: any, arg2: any) => boolean): T[];
|
|
51
|
+
immutableFilter(predicate: callbackFunction<T, boolean>): MLArray<T>;
|
|
52
|
+
batch<U>(length: number, callbackFunction: callbackFunction<T, U>, from?: number): void;
|
|
53
|
+
lazyFlat(): MLArray<T>;
|
|
54
|
+
lazyFlat(): Array<T>;
|
|
55
|
+
get(...at: number[]): T | MLArray<T | undefined> | undefined;
|
|
56
|
+
addAfter(at: number, ...data: T[]): this;
|
|
57
|
+
deleteNull(): MLArray<T>;
|
|
58
|
+
search(search: string | string[] | ((value: string) => boolean), options?: {
|
|
59
|
+
plus?: number;
|
|
60
|
+
}): number[] | number[][];
|
|
61
|
+
getValueWhere(key: string, val: T): T | undefined;
|
|
62
|
+
getValuesExcept(key: string, val: T): MLArray<T>;
|
|
63
|
+
wrap(dimension?: number): MLArray<any>;
|
|
64
|
+
wrapInside(dimension?: number): MLArray<any[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Pembersihan data duplikat di array
|
|
67
|
+
*/
|
|
68
|
+
unique(): MLArray<T>;
|
|
69
|
+
toParam(): MLArray<MLArray<T>>;
|
|
70
|
+
/**
|
|
71
|
+
* Extract 2d array by index
|
|
72
|
+
*/
|
|
73
|
+
extract(...at: number[] | [{
|
|
74
|
+
useWrap?: number;
|
|
75
|
+
isZeroBasedIndex?: boolean;
|
|
76
|
+
}]): any;
|
|
77
|
+
sort(orderBy?: OrderBy | ((a: T, b: T) => number)): this;
|
|
78
|
+
toObject(): MLObject<unknown>;
|
|
79
|
+
iterate(callbackFunc: callbackFunction<T, void>): void;
|
|
80
|
+
sum(): number;
|
|
81
|
+
subtract(options?: {
|
|
82
|
+
positive?: boolean;
|
|
83
|
+
}): number;
|
|
84
|
+
max(): number;
|
|
85
|
+
min(): number;
|
|
86
|
+
minMax(): number[];
|
|
87
|
+
/**
|
|
88
|
+
* Mengecek tipe data menggunakan "typeof" bawaan JavaScript untuk banyak variabel sekaligus
|
|
89
|
+
*/
|
|
90
|
+
isTypeOf(type: ReturnType<typeof typeof_dummy>, options?: {
|
|
91
|
+
logic?: Logic;
|
|
92
|
+
}): boolean;
|
|
93
|
+
}
|
|
94
|
+
declare const typeof_dummy: () => "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined";
|
|
95
|
+
export declare function initArray<const T>(array?: Array<T | Record<string, T>> | T, options?: MLArrayOptions): MLArray<T extends readonly any[] ? T[number] : T>;
|
|
96
|
+
export declare function flat<T>(array: T[]): any[];
|
|
97
|
+
export declare function getOptions(array: any[]): Record<string, any>;
|
|
98
|
+
type SwitchDimension<T, Dimension extends number> = {
|
|
99
|
+
1: T[];
|
|
100
|
+
2: T[][];
|
|
101
|
+
3: T[][][];
|
|
102
|
+
4: T[][][][];
|
|
103
|
+
5: T[][][][][];
|
|
104
|
+
}[Dimension extends keyof 1 | 2 | 3 | 4 | 5 ? Dimension : never];
|
|
105
|
+
type NestedArray<T, Dimension extends number> = Dimension extends 1 | 2 | 3 | 4 | 5 ? SwitchDimension<T, Dimension> : any[];
|
|
106
|
+
export declare function wrap<T, Dimension extends number = 1>(value: T, dimension?: Dimension): NestedArray<T, Dimension>;
|
|
107
|
+
export declare function lazyWrap<T>(value: T | T[]): T[];
|
|
108
|
+
export declare function isAllArray(...arg: any[]): boolean;
|
|
109
|
+
export declare function isIterable(value: any): boolean;
|
|
110
|
+
export {};
|
package/dist/Array.js
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
/** Override fungsi2 bawaan Array */
|
|
2
|
+
import { Break, iterate } from './Iteration.js';
|
|
3
|
+
import { sameWith } from './Comparison.js';
|
|
4
|
+
import { isObject, MLObject } from './Object.js';
|
|
5
|
+
import { And, Ascending, Descending, Or } from './Type.js';
|
|
6
|
+
import { log } from './Dynamic.js';
|
|
7
|
+
import { isString } from './String.js';
|
|
8
|
+
export const isArray = Array.isArray;
|
|
9
|
+
export class MLArray extends Array {
|
|
10
|
+
batchSize = 50000;
|
|
11
|
+
withLog = true;
|
|
12
|
+
// 4. IMPLEMENTASI UTAMA: Gabungkan semua tipe di atas menggunakan union secara presisi
|
|
13
|
+
static from(arrayLikeOrIterable, mapfn, thisArg) {
|
|
14
|
+
// Gunakan 'as any' di internal return agar lolos dari strict check constructor kustom Anda
|
|
15
|
+
return super.from(arrayLikeOrIterable, mapfn, thisArg);
|
|
16
|
+
}
|
|
17
|
+
static repeat(valueOrFunction, count = 1) {
|
|
18
|
+
return super.from({ length: count }, typeof valueOrFunction === 'function' ? valueOrFunction : (_, __) => valueOrFunction);
|
|
19
|
+
}
|
|
20
|
+
static init(array = [], options = {}) {
|
|
21
|
+
const { flatting = false, deleteNull = false, unique = false, withLog = true } = options;
|
|
22
|
+
let result = this.from(lazyWrap(array));
|
|
23
|
+
if (flatting)
|
|
24
|
+
result.lazyFlat();
|
|
25
|
+
if (deleteNull)
|
|
26
|
+
result.deleteNull();
|
|
27
|
+
if (unique)
|
|
28
|
+
result.unique();
|
|
29
|
+
result.withLog = withLog;
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
findIndexInOrder(valueOrFunc, order = 1) {
|
|
33
|
+
const isFunction = typeof valueOrFunc === 'function';
|
|
34
|
+
let currentOrder = 0, result;
|
|
35
|
+
this.iterate((value, no, array) => {
|
|
36
|
+
if (isFunction ? valueOrFunc(value, no, array) : value === valueOrFunc) {
|
|
37
|
+
currentOrder++;
|
|
38
|
+
if (currentOrder === order) {
|
|
39
|
+
result = no;
|
|
40
|
+
return Break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
// Jembatan Tipe untuk IntelliSense (IDE)
|
|
47
|
+
map(callbackFn) {
|
|
48
|
+
return super.map(callbackFn);
|
|
49
|
+
}
|
|
50
|
+
mapToObject(callbackFn) {
|
|
51
|
+
return this.map(callbackFn).toObject();
|
|
52
|
+
}
|
|
53
|
+
castToString() {
|
|
54
|
+
return this.map(data => typeof data !== 'string' ? data.toString() : data);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Mengubah array yang ada di dalam MLArray biasa menjadi MLArray
|
|
58
|
+
*/
|
|
59
|
+
mapCast(callbackFunc) {
|
|
60
|
+
return this.map((data, no, array) => callbackFunc((isArray(data) ? initArray(data) : data), no, array));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Fungsi alternatif dari indexOf() dengan sistem one-based index
|
|
64
|
+
*/
|
|
65
|
+
locationOf(value) {
|
|
66
|
+
return super.indexOf(value) + 1;
|
|
67
|
+
}
|
|
68
|
+
slice(start, end = null) {
|
|
69
|
+
if (sameWith(0, start, end, { logic: Or, withLog: this.withLog }))
|
|
70
|
+
throw Error('Start / end tidak boleh 0');
|
|
71
|
+
if (start >= 1)
|
|
72
|
+
start = start - 1;
|
|
73
|
+
return (end != null ? super.slice(start, end) : super.slice(start));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Mengabungkan array dengan pemisah (default: 'dan') di akhir untuk keterbacaan
|
|
77
|
+
*/
|
|
78
|
+
readableJoin(options = {}) {
|
|
79
|
+
switch (this.length) {
|
|
80
|
+
case 0:
|
|
81
|
+
return '';
|
|
82
|
+
case 1:
|
|
83
|
+
return String(this[0]);
|
|
84
|
+
}
|
|
85
|
+
const { and = 'dan', separator = ', ' } = options;
|
|
86
|
+
return `${this.slice(1, -1).join(separator)} ${and} ${this.at(-1)}`;
|
|
87
|
+
}
|
|
88
|
+
push(...values) {
|
|
89
|
+
const { many = false } = getOptions(values), process = (value) => this.batch(values.length, (_, i) => super.push(...values.slice(i, i + this.batchSize)));
|
|
90
|
+
if (many)
|
|
91
|
+
this.forEach((_, no) => values[no] && process(values[no]));
|
|
92
|
+
else
|
|
93
|
+
process(values.lazyFlat());
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
filter(predicate) {
|
|
97
|
+
let writeIndex = 0;
|
|
98
|
+
this.iterate((data, no) => {
|
|
99
|
+
if (predicate(data, no, this))
|
|
100
|
+
this[writeIndex++] = data;
|
|
101
|
+
});
|
|
102
|
+
this.length = writeIndex;
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
immutableFilter(predicate) {
|
|
106
|
+
return super.filter(predicate);
|
|
107
|
+
}
|
|
108
|
+
batch(length, callbackFunction, from = 0) {
|
|
109
|
+
iterate((i) => callbackFunction(this[i], i, this), { until: length, addition: this.batchSize, from });
|
|
110
|
+
}
|
|
111
|
+
lazyFlat() {
|
|
112
|
+
if (this.some(isArray)) {
|
|
113
|
+
const flattened = this.flat(Infinity).asMLArray();
|
|
114
|
+
this.length = 0;
|
|
115
|
+
flattened.iterate((data, i) => this[i] = data);
|
|
116
|
+
}
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
get(...at) {
|
|
120
|
+
const { defaultIndex = false } = getOptions(at), flattenAt = initArray(at, { flatting: true });
|
|
121
|
+
const process = (index) => index === 0
|
|
122
|
+
? undefined
|
|
123
|
+
: index > 0
|
|
124
|
+
? this[index - +!defaultIndex]
|
|
125
|
+
: this.at(index);
|
|
126
|
+
return flattenAt.length > 2 ? flattenAt.map(process) : process(flattenAt[0]);
|
|
127
|
+
}
|
|
128
|
+
addAfter(at, ...data) {
|
|
129
|
+
data = data.lazyFlat();
|
|
130
|
+
this.batch(data.length, (_, i) => this.splice(at + i, 0, ...data.slice(i, i + this.batchSize)));
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
deleteNull() {
|
|
134
|
+
return this.filter(data => !!data);
|
|
135
|
+
}
|
|
136
|
+
search(search, options = {}) {
|
|
137
|
+
const { plus = 0 } = options;
|
|
138
|
+
let rows = [], firstRow = null, currentRow = 0;
|
|
139
|
+
if (this.withLog) {
|
|
140
|
+
log(`Function Name: getIndexes`);
|
|
141
|
+
log(`Search Value: ${JSON.stringify(search)}`);
|
|
142
|
+
log(`Values: ${this}`);
|
|
143
|
+
log(`Index Plus: ${plus}`);
|
|
144
|
+
}
|
|
145
|
+
if (typeof search !== 'function')
|
|
146
|
+
search = lazyWrap(search);
|
|
147
|
+
this.iterate((data, index, array) => {
|
|
148
|
+
let value = data;
|
|
149
|
+
if (typeof value === 'string')
|
|
150
|
+
value = value.trim();
|
|
151
|
+
const isSame = typeof search === 'function'
|
|
152
|
+
? search(value)
|
|
153
|
+
: search.includes(value);
|
|
154
|
+
if (isSame || firstRow != null)
|
|
155
|
+
currentRow = plus + index;
|
|
156
|
+
if (firstRow != null && !isSame) {
|
|
157
|
+
rows.push([firstRow, currentRow - 1]);
|
|
158
|
+
firstRow = null;
|
|
159
|
+
}
|
|
160
|
+
else if (isSame && firstRow == null)
|
|
161
|
+
firstRow = currentRow;
|
|
162
|
+
});
|
|
163
|
+
if (firstRow)
|
|
164
|
+
rows.push([firstRow, currentRow]);
|
|
165
|
+
return rows;
|
|
166
|
+
}
|
|
167
|
+
getValueWhere(key, val) {
|
|
168
|
+
return this.find(k => k[key] === val);
|
|
169
|
+
}
|
|
170
|
+
getValuesExcept(key, val) {
|
|
171
|
+
return this.filter(k => k[key] !== val);
|
|
172
|
+
}
|
|
173
|
+
wrap(dimension = 1) {
|
|
174
|
+
return MLArray.from(wrap(this, dimension));
|
|
175
|
+
}
|
|
176
|
+
wrapInside(dimension = 1) {
|
|
177
|
+
return this.map(value => wrap(value, dimension));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Pembersihan data duplikat di array
|
|
181
|
+
*/
|
|
182
|
+
unique() {
|
|
183
|
+
this.lazyFlat().deleteNull();
|
|
184
|
+
const uniqueCollection = MLArray.init([...new Set(this)]);
|
|
185
|
+
this.length = 0;
|
|
186
|
+
uniqueCollection.iterate((data, no) => this[no] = data);
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
toParam() {
|
|
190
|
+
let result = initArray([]);
|
|
191
|
+
for (let i = 0; i < this[0].length; i++)
|
|
192
|
+
result[i] = this.map((content) => content[i]);
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Extract 2d array by index
|
|
197
|
+
*/
|
|
198
|
+
extract(...at) {
|
|
199
|
+
const { useWrap = 0, isZeroBasedIndex = false } = getOptions(at),
|
|
200
|
+
/**
|
|
201
|
+
* @param {MLArray} content
|
|
202
|
+
* @param {number} at
|
|
203
|
+
* @return {MLArray|*}
|
|
204
|
+
*/
|
|
205
|
+
process = (content, at) => {
|
|
206
|
+
const result = content.get(at + isZeroBasedIndex);
|
|
207
|
+
return useWrap ? wrap(result, useWrap).asMLArray() : result;
|
|
208
|
+
}, result = initArray(at, { flatting: true }).mapCast(at => this.mapCast(content => process(content, at)));
|
|
209
|
+
return result.length > 1 ? result : result[0];
|
|
210
|
+
}
|
|
211
|
+
sort(orderBy) {
|
|
212
|
+
if (!orderBy)
|
|
213
|
+
orderBy = Ascending;
|
|
214
|
+
return super.sort((a, b) => {
|
|
215
|
+
if (orderBy === Descending)
|
|
216
|
+
[a, b] = [b, a];
|
|
217
|
+
if (typeof orderBy === 'function')
|
|
218
|
+
return orderBy(a, b);
|
|
219
|
+
if (initArray([a, b]).isTypeOf('number'))
|
|
220
|
+
return a - b;
|
|
221
|
+
else
|
|
222
|
+
return a.localeCompare(b);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
toObject() {
|
|
226
|
+
if (this.every(isArray))
|
|
227
|
+
return MLObject.fromEntries(this);
|
|
228
|
+
return MLObject.assign(this);
|
|
229
|
+
}
|
|
230
|
+
iterate(callbackFunc) {
|
|
231
|
+
iterate(i => callbackFunc(this[i], i, this), { from: 0, until: this.length, untilBefore: true });
|
|
232
|
+
}
|
|
233
|
+
sum() {
|
|
234
|
+
let decimalNum = 0, numbers = this;
|
|
235
|
+
if (numbers.isTypeOf('string')) {
|
|
236
|
+
decimalNum = this.map((val) => val.split('.')[1]?.length).unique()[0] ?? 0;
|
|
237
|
+
numbers = numbers.map((val) => val.replace('.', ''));
|
|
238
|
+
}
|
|
239
|
+
const result = numbers.reduce((total, num) => total + (typeof num === 'number' ? num : Number(num)), 0);
|
|
240
|
+
return result / (10 ** decimalNum);
|
|
241
|
+
}
|
|
242
|
+
subtract(options = {}) {
|
|
243
|
+
const { positive = true } = options, flattenedArr = this.lazyFlat();
|
|
244
|
+
if (!flattenedArr.length)
|
|
245
|
+
return 0;
|
|
246
|
+
const result = flattenedArr.reduce((total, num) => total - (typeof num === 'number' ? num : Number(num)), 0) + (flattenedArr[0] * 2);
|
|
247
|
+
return positive ? Math.abs(result) : result;
|
|
248
|
+
}
|
|
249
|
+
max() {
|
|
250
|
+
return Math.max(...this);
|
|
251
|
+
}
|
|
252
|
+
min() {
|
|
253
|
+
return Math.min(...this);
|
|
254
|
+
}
|
|
255
|
+
minMax() {
|
|
256
|
+
return [this.min(), this.max()];
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Mengecek tipe data menggunakan "typeof" bawaan JavaScript untuk banyak variabel sekaligus
|
|
260
|
+
*/
|
|
261
|
+
isTypeOf(type, options = {}) {
|
|
262
|
+
const { logic = And } = options;
|
|
263
|
+
return logic === And
|
|
264
|
+
? this.every(val => type === 'string' ? isString(val) : typeof val === type)
|
|
265
|
+
: this.some(val => type === 'string' ? isString(val) : typeof val === type);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const typeof_dummy = () => typeof '';
|
|
269
|
+
Array.prototype.asMLArray = function () {
|
|
270
|
+
return initArray(this);
|
|
271
|
+
};
|
|
272
|
+
Array.prototype.lazyFlat = function () {
|
|
273
|
+
return flat(this);
|
|
274
|
+
};
|
|
275
|
+
export function initArray(array = [], options = {}) {
|
|
276
|
+
return MLArray.init(array, options);
|
|
277
|
+
}
|
|
278
|
+
export function flat(array) {
|
|
279
|
+
return array.some(isArray) ? array.flat(Infinity) : array;
|
|
280
|
+
}
|
|
281
|
+
export function getOptions(array) {
|
|
282
|
+
return isObject(array.at(-1)) ? array.pop() : {};
|
|
283
|
+
}
|
|
284
|
+
export function wrap(value, dimension = 1) {
|
|
285
|
+
iterate(() => value = [value], { until: dimension });
|
|
286
|
+
return value;
|
|
287
|
+
}
|
|
288
|
+
export function lazyWrap(value) {
|
|
289
|
+
if (typeof value !== 'string' && !(value instanceof String) && isIterable(value))
|
|
290
|
+
return value;
|
|
291
|
+
return wrap(value);
|
|
292
|
+
}
|
|
293
|
+
export function isAllArray(...arg) {
|
|
294
|
+
return arg.length > 1 ? arg.every(isArray) : isArray(arg[0]);
|
|
295
|
+
}
|
|
296
|
+
export function isIterable(value) {
|
|
297
|
+
return typeof value?.[Symbol.iterator] === 'function';
|
|
298
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type StringBoolean = 'TRUE' | 'FALSE';
|
|
2
|
+
/**
|
|
3
|
+
* Melakukan negasi pada primitif boolean atau boolean pada string.
|
|
4
|
+
* Contoh: 'TRUE' -> 'FALSE'
|
|
5
|
+
*/
|
|
6
|
+
export declare function reverseBoolean(value: StringBoolean | boolean): string | boolean | undefined;
|
|
7
|
+
export declare function ifTrue<T>(condition: boolean, value: T): "" | T;
|
package/dist/Boolean.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const stringBoolean = ['TRUE', 'FALSE'], reservedBoolean = ['FALSE', 'TRUE'];
|
|
2
|
+
/**
|
|
3
|
+
* Melakukan negasi pada primitif boolean atau boolean pada string.
|
|
4
|
+
* Contoh: 'TRUE' -> 'FALSE'
|
|
5
|
+
*/
|
|
6
|
+
export function reverseBoolean(value) {
|
|
7
|
+
switch (typeof value) {
|
|
8
|
+
case 'boolean':
|
|
9
|
+
return !value;
|
|
10
|
+
case 'string':
|
|
11
|
+
if (!stringBoolean.includes(value))
|
|
12
|
+
throw Error('Value tidak valid.');
|
|
13
|
+
return reservedBoolean[stringBoolean.indexOf(value)];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function ifTrue(condition, value) {
|
|
17
|
+
return condition ? value : '';
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Logic } from './Array.ts';
|
|
2
|
+
type CompareNumber = '<' | '<=' | '<=<' | '<<=';
|
|
3
|
+
type CompareParam<T> = Array<T | {
|
|
4
|
+
logic: Logic;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function isSame(...arr: any[]): boolean;
|
|
7
|
+
export declare function sameWith<T>(value: T, ...arr: T[] | [{
|
|
8
|
+
withLog?: boolean;
|
|
9
|
+
logic?: Logic;
|
|
10
|
+
}]): boolean;
|
|
11
|
+
export declare function notSameWith(value: any, ...arr: any): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Mengecek apakah 'value' ada di antara 'start' sampai 'until'
|
|
14
|
+
* Mendukung komparasi: '<', '<=', '<=<', '<<='
|
|
15
|
+
*/
|
|
16
|
+
export declare function between(start: number, value: number | number[], until: number, compare?: CompareNumber | CompareNumber[]): boolean;
|
|
17
|
+
export declare function lowerThan(value: number, ...comparations: CompareParam<number>): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Mengecek tipe data menggunakan "typeof" bawaan JavaScript untuk banyak variabel sekaligus
|
|
20
|
+
*/
|
|
21
|
+
export declare function isTypeOf(type: string, ...array: CompareParam<any>): boolean;
|
|
22
|
+
export {};
|