inibase 1.0.0-rc.9 → 1.0.0-rc.90
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 +1 -1
- package/README.md +410 -100
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +272 -0
- package/dist/file.d.ts +148 -0
- package/dist/file.js +597 -0
- package/dist/index.d.ts +192 -0
- package/dist/index.js +1350 -0
- package/dist/utils.d.ts +205 -0
- package/dist/utils.js +509 -0
- package/dist/utils.server.d.ts +83 -0
- package/dist/utils.server.js +248 -0
- package/package.json +66 -19
- package/file.ts +0 -501
- package/index.test.ts +0 -210
- package/index.ts +0 -1488
- package/tsconfig.json +0 -7
- package/utils.server.ts +0 -79
- package/utils.ts +0 -212
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type { ComparisonOperator, Field, FieldType, Schema } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard function to check if the input is an array of objects.
|
|
4
|
+
*
|
|
5
|
+
* @param input - The value to be checked.
|
|
6
|
+
* @returns boolean - True if the input is an array of objects, false otherwise.
|
|
7
|
+
*
|
|
8
|
+
* Note: Considers empty arrays and arrays where every element is an object.
|
|
9
|
+
*/
|
|
10
|
+
export declare const isArrayOfObjects: (input: any) => input is Record<any, any>[];
|
|
11
|
+
/**
|
|
12
|
+
* Type guard function to check if the input is an array of arrays.
|
|
13
|
+
*
|
|
14
|
+
* @param input - The value to be checked.
|
|
15
|
+
* @returns boolean - True if the input is an array of arrays, false otherwise.
|
|
16
|
+
*
|
|
17
|
+
* Note: Considers empty arrays and arrays where every element is also an array.
|
|
18
|
+
*/
|
|
19
|
+
export declare const isArrayOfArrays: (input: any) => input is any[][];
|
|
20
|
+
/**
|
|
21
|
+
* Type guard function to check if the input is an array of nulls or an array of arrays of nulls.
|
|
22
|
+
*
|
|
23
|
+
* @param input - The value to be checked.
|
|
24
|
+
* @returns boolean - True if the input is an array consisting entirely of nulls or arrays of nulls, false otherwise.
|
|
25
|
+
*
|
|
26
|
+
* Note: Recursively checks each element, allowing for nested arrays of nulls.
|
|
27
|
+
*/
|
|
28
|
+
export declare const isArrayOfNulls: (input: any) => input is null[] | null[][];
|
|
29
|
+
/**
|
|
30
|
+
* Type guard function to check if the input is an object.
|
|
31
|
+
*
|
|
32
|
+
* @param obj - The value to be checked.
|
|
33
|
+
* @returns boolean - True if the input is an object (excluding arrays), false otherwise.
|
|
34
|
+
*
|
|
35
|
+
* Note: Checks if the input is non-null and either has 'Object' as its constructor name or is of type 'object' without being an array.
|
|
36
|
+
*/
|
|
37
|
+
export declare const isObject: (obj: any) => obj is Record<any, any>;
|
|
38
|
+
/**
|
|
39
|
+
* Recursively merges properties from a source object into a target object. If a property exists in both, the source's value overwrites the target's.
|
|
40
|
+
*
|
|
41
|
+
* @param target - The target object to merge properties into.
|
|
42
|
+
* @param source - The source object from which properties are merged.
|
|
43
|
+
* @returns any - The modified target object with merged properties.
|
|
44
|
+
*
|
|
45
|
+
* Note: Performs a deep merge for nested objects. Non-object properties are directly overwritten.
|
|
46
|
+
*/
|
|
47
|
+
export declare const deepMerge: (target: any, source: any) => any;
|
|
48
|
+
/**
|
|
49
|
+
* Type guard function to check if the input is a number.
|
|
50
|
+
*
|
|
51
|
+
* @param input - The value to be checked.
|
|
52
|
+
* @returns boolean - True if the input is a number, false otherwise.
|
|
53
|
+
*
|
|
54
|
+
* Note: Validates that the input can be parsed as a float and that subtracting zero results in a number, ensuring it's a numeric value.
|
|
55
|
+
*/
|
|
56
|
+
export declare const isNumber: (input: any) => input is number;
|
|
57
|
+
/**
|
|
58
|
+
* Checks if the input is a valid email format.
|
|
59
|
+
*
|
|
60
|
+
* @param input - The value to be checked.
|
|
61
|
+
* @returns boolean - True if the input matches the email format, false otherwise.
|
|
62
|
+
*
|
|
63
|
+
* Note: Uses a regular expression to validate the email format, ensuring it has parts separated by '@' and contains a domain with a period.
|
|
64
|
+
*/
|
|
65
|
+
export declare const isEmail: (input: any) => boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Checks if the input is a valid URL format.
|
|
68
|
+
*
|
|
69
|
+
* @param input - The value to be checked.
|
|
70
|
+
* @returns boolean - True if the input matches the URL format, false otherwise.
|
|
71
|
+
*
|
|
72
|
+
* Note: Validates URLs including protocols (http/https), domain names, IP addresses, ports, paths, query strings, and fragments.
|
|
73
|
+
* Also recognizes 'tel:' and 'mailto:' as valid URL formats, as well as strings starting with '#' without spaces.
|
|
74
|
+
*/
|
|
75
|
+
export declare const isURL: (input: any) => boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Checks if the input contains HTML tags or entities.
|
|
78
|
+
*
|
|
79
|
+
* @param input - The value to be checked.
|
|
80
|
+
* @returns boolean - True if the input contains HTML tags or entities, false otherwise.
|
|
81
|
+
*
|
|
82
|
+
* Note: Uses a regular expression to detect HTML tags (like <tag>) and entities (like &entity;).
|
|
83
|
+
* Recognizes both opening and closing tags, as well as self-closing tags.
|
|
84
|
+
*/
|
|
85
|
+
export declare const isHTML: (input: any) => boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Type guard function to check if the input is a string, excluding strings that match specific formats (number, boolean, email, URL, IP).
|
|
88
|
+
*
|
|
89
|
+
* @param input - The value to be checked.
|
|
90
|
+
* @returns boolean - True if the input is a string that doesn't match the specific formats, false otherwise.
|
|
91
|
+
*
|
|
92
|
+
* Note: Validates the input against being a number, boolean, email, URL, or IP address to ensure it's a general string.
|
|
93
|
+
*/
|
|
94
|
+
export declare const isString: (input: any) => input is string;
|
|
95
|
+
/**
|
|
96
|
+
* Checks if the input is a valid IP address format.
|
|
97
|
+
*
|
|
98
|
+
* @param input - The value to be checked.
|
|
99
|
+
* @returns boolean - True if the input matches the IP address format, false otherwise.
|
|
100
|
+
*
|
|
101
|
+
* Note: Uses a regular expression to validate IP addresses, ensuring they consist of four octets, each ranging from 0 to 255.
|
|
102
|
+
*/
|
|
103
|
+
export declare const isIP: (input: any) => boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Type guard function to check if the input is a boolean or a string representation of a boolean.
|
|
106
|
+
*
|
|
107
|
+
* @param input - The value to be checked.
|
|
108
|
+
* @returns boolean - True if the input is a boolean value or 'true'/'false' strings, false otherwise.
|
|
109
|
+
*
|
|
110
|
+
* Note: Recognizes both boolean literals (true, false) and their string representations ("true", "false").
|
|
111
|
+
*/
|
|
112
|
+
export declare const isBoolean: (input: any) => input is boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Type guard function to check if the input is a password based on a specific length criterion.
|
|
115
|
+
*
|
|
116
|
+
* @param input - The value to be checked.
|
|
117
|
+
* @returns boolean - True if the input is a string with a length of 161 characters, false otherwise.
|
|
118
|
+
*
|
|
119
|
+
* Note: Specifically checks for string length to determine if it matches the defined password length criterion.
|
|
120
|
+
*/
|
|
121
|
+
export declare const isPassword: (input: any) => input is string;
|
|
122
|
+
/**
|
|
123
|
+
* Checks if the input can be converted to a valid date.
|
|
124
|
+
*
|
|
125
|
+
* @param input - The input to be checked, can be of any type.
|
|
126
|
+
* @returns A boolean indicating whether the input is a valid date.
|
|
127
|
+
*/
|
|
128
|
+
export declare const isDate: (input: any) => boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Checks if the input is a valid ID.
|
|
131
|
+
*
|
|
132
|
+
* @param input - The input to be checked, can be of any type.
|
|
133
|
+
* @returns A boolean indicating whether the input is a string representing a valid ID of length 32.
|
|
134
|
+
*/
|
|
135
|
+
export declare const isValidID: (input: any) => input is string;
|
|
136
|
+
/**
|
|
137
|
+
* Checks if a given string is a valid JSON.
|
|
138
|
+
*
|
|
139
|
+
* @param {string} str - The string to be checked.
|
|
140
|
+
* @returns {boolean} Returns true if the string is valid JSON, otherwise false.
|
|
141
|
+
*/
|
|
142
|
+
export declare const isJSON: (str: string) => boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Identifies and returns properties that have changed between two objects.
|
|
145
|
+
*
|
|
146
|
+
* @param obj1 - The first object for comparison, with string keys and values.
|
|
147
|
+
* @param obj2 - The second object for comparison, with string keys and values.
|
|
148
|
+
* @returns A record of changed properties with original values from obj1 and new values from obj2, or null if no changes are found.
|
|
149
|
+
*/
|
|
150
|
+
export declare const findChangedProperties: (obj1: Record<string, string>, obj2: Record<string, string>) => Record<string, string> | null;
|
|
151
|
+
/**
|
|
152
|
+
* Detects the field type of an input based on available types.
|
|
153
|
+
*
|
|
154
|
+
* @param input - The input whose field type is to be detected.
|
|
155
|
+
* @param availableTypes - An array of potential field types to consider.
|
|
156
|
+
* @returns The detected field type as a string, or undefined if no matching type is found.
|
|
157
|
+
*/
|
|
158
|
+
export declare const detectFieldType: (input: any, availableTypes: FieldType[]) => FieldType | undefined;
|
|
159
|
+
export declare const isFieldType: (compareAtType: string | string[], fieldType?: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[] | Schema) => boolean;
|
|
160
|
+
export declare const flattenSchema: (schema: Schema, keepParents?: boolean) => Schema;
|
|
161
|
+
export declare const filterSchema: (schema: Schema, callback: (arg0: Field) => boolean) => Field[];
|
|
162
|
+
/**
|
|
163
|
+
* Validates if the given value matches the specified field type(s).
|
|
164
|
+
*
|
|
165
|
+
* @param value - The value to be validated.
|
|
166
|
+
* @param fieldType - The expected field type or an array of possible field types.
|
|
167
|
+
* @param fieldChildrenType - Optional; the expected type(s) of children elements, used if the field type is an array.
|
|
168
|
+
* @returns A boolean indicating whether the value matches the specified field type(s).
|
|
169
|
+
*/
|
|
170
|
+
export declare const validateFieldType: (value: any, fieldType: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[]) => boolean;
|
|
171
|
+
export declare function FormatObjectCriteriaValue(value: string): [
|
|
172
|
+
ComparisonOperator,
|
|
173
|
+
string | number | boolean | null | (string | number | null)[]
|
|
174
|
+
];
|
|
175
|
+
/**
|
|
176
|
+
* Get field from schema
|
|
177
|
+
*
|
|
178
|
+
* @export
|
|
179
|
+
* @param {string} keyPath Support dot notation path
|
|
180
|
+
* @param {Schema} schema
|
|
181
|
+
*/
|
|
182
|
+
export declare function getField(keyPath: string, schema: Schema): Field;
|
|
183
|
+
/**
|
|
184
|
+
* Override a schema field, key, type or other properties
|
|
185
|
+
*
|
|
186
|
+
* @export
|
|
187
|
+
* @param {string} keyPath Support dot notation path
|
|
188
|
+
* @param {Schema} schema
|
|
189
|
+
* @param {(Omit<Field, "key" | "type"> & {
|
|
190
|
+
* key?: string;
|
|
191
|
+
* type?: FieldType | FieldType[];
|
|
192
|
+
* })} field
|
|
193
|
+
*/
|
|
194
|
+
export declare function setField(keyPath: string, schema: Schema, field: Omit<Field, "key" | "type"> & {
|
|
195
|
+
key?: string;
|
|
196
|
+
type?: FieldType | FieldType[];
|
|
197
|
+
}): Field;
|
|
198
|
+
/**
|
|
199
|
+
* Remove field from schema
|
|
200
|
+
*
|
|
201
|
+
* @export
|
|
202
|
+
* @param {string} keyPath Support dot notation path
|
|
203
|
+
* @param {Schema} schema
|
|
204
|
+
*/
|
|
205
|
+
export declare function unsetField(keyPath: string, schema: Schema): Field;
|