@rebasepro/utils 0.9.1-canary.fd3754b → 0.10.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/dist/index.d.ts +2 -0
- package/dist/index.es.js +155 -2
- package/dist/index.es.js.map +1 -1
- package/dist/policy-names.d.ts +27 -0
- package/dist/sha1.d.ts +20 -0
- package/dist/strings.d.ts +10 -0
- package/package.json +8 -8
- package/src/index.ts +2 -0
- package/src/policy-names.ts +65 -0
- package/src/sha1.ts +98 -0
- package/src/strings.ts +16 -1
- package/dist/index.umd.js +0 -633
- package/dist/index.umd.js.map +0 -1
package/dist/index.umd.js
DELETED
|
@@ -1,633 +0,0 @@
|
|
|
1
|
-
(function(global, factory) {
|
|
2
|
-
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("object-hash"), require("@rebasepro/types")) : typeof define === "function" && define.amd ? define([
|
|
3
|
-
"exports",
|
|
4
|
-
"object-hash",
|
|
5
|
-
"@rebasepro/types"
|
|
6
|
-
], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["Rebase Util"] = {}, global.object_hash, global._rebasepro_types));
|
|
7
|
-
})(this, function(exports, object_hash, _rebasepro_types) {
|
|
8
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
-
//#region \0rolldown/runtime.js
|
|
10
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __copyProps = (to, from, except, desc) => {
|
|
17
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
18
|
-
key = keys[i];
|
|
19
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
20
|
-
get: ((k) => from[k]).bind(null, key),
|
|
21
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
return to;
|
|
25
|
-
};
|
|
26
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
27
|
-
value: mod,
|
|
28
|
-
enumerable: true
|
|
29
|
-
}) : target, mod));
|
|
30
|
-
//#endregion
|
|
31
|
-
object_hash = __toESM(object_hash, 1);
|
|
32
|
-
//#region src/strings.ts
|
|
33
|
-
var tokenizeRegex = /[A-Z]{2,}(?=[A-Z][a-z]|\b)|[A-Z]?[a-z]+|[0-9]+(?:[a-z](?![a-z]))?|[A-Z]/g;
|
|
34
|
-
var toKebabCase = (str) => {
|
|
35
|
-
if (!str || typeof str !== "string") return "";
|
|
36
|
-
const regExpMatchArray = str.match(tokenizeRegex);
|
|
37
|
-
if (!regExpMatchArray) return "";
|
|
38
|
-
return regExpMatchArray.map((x) => x.toLowerCase()).join("-");
|
|
39
|
-
};
|
|
40
|
-
var snakeCaseRegex = tokenizeRegex;
|
|
41
|
-
var toSnakeCase = (str) => {
|
|
42
|
-
if (!str || typeof str !== "string") return "";
|
|
43
|
-
const regExpMatchArray = str.match(snakeCaseRegex);
|
|
44
|
-
if (!regExpMatchArray) return "";
|
|
45
|
-
return regExpMatchArray.map((x) => x.toLowerCase()).join("_");
|
|
46
|
-
};
|
|
47
|
-
function camelCase(str) {
|
|
48
|
-
if (!str) return "";
|
|
49
|
-
if (str.length === 1) return str.toLowerCase();
|
|
50
|
-
const parts = str.split(/[-_ ]+/).filter(Boolean);
|
|
51
|
-
if (parts.length === 0) return "";
|
|
52
|
-
return parts[0].toLowerCase() + parts.slice(1).map((part) => part.charAt(0).toUpperCase() + part.substring(1).toLowerCase()).join("");
|
|
53
|
-
}
|
|
54
|
-
function randomString(strLength = 5) {
|
|
55
|
-
return Math.random().toString(36).slice(2, 2 + strLength);
|
|
56
|
-
}
|
|
57
|
-
function randomColor() {
|
|
58
|
-
return Math.floor(Math.random() * 16777215).toString(16);
|
|
59
|
-
}
|
|
60
|
-
function slugify(text, separator = "_", lowercase = true) {
|
|
61
|
-
if (!text) return "";
|
|
62
|
-
const from = "ãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;-";
|
|
63
|
-
const to = `aaaaaeeeeeiiiiooooouuuunc${separator}${separator}${separator}${separator}${separator}${separator}${separator}`;
|
|
64
|
-
for (let i = 0, l = 32; i < l; i++) text = text.replace(new RegExp(from.charAt(i), "g"), to.charAt(i));
|
|
65
|
-
text = text.toString().trim().replace(/^\s+|\s+$/g, "").replace(/\s+/g, separator).replace(/&/g, separator).replace(/[^\w\\-]+/g, "").replace(new RegExp("\\" + separator + "\\" + separator + "+", "g"), separator);
|
|
66
|
-
return lowercase ? text.toLowerCase() : text;
|
|
67
|
-
}
|
|
68
|
-
function unslugify(slug) {
|
|
69
|
-
if (!slug) return "";
|
|
70
|
-
if (slug.includes("-") || slug.includes("_") || !slug.includes(" ")) return slug.replace(/[-_]/g, " ").replace(/\w\S*/g, function(txt) {
|
|
71
|
-
return txt.charAt(0).toUpperCase() + txt.substring(1);
|
|
72
|
-
}).trim();
|
|
73
|
-
else return slug.trim();
|
|
74
|
-
}
|
|
75
|
-
function prettifyIdentifier(input) {
|
|
76
|
-
if (!input) return "";
|
|
77
|
-
let text = input;
|
|
78
|
-
text = text.replace(/([a-z])([A-Z])|([A-Z])([A-Z][a-z])/g, "$1$3 $2$4");
|
|
79
|
-
text = text.replace(/[_-]+/g, " ");
|
|
80
|
-
return text.trim().replace(/\b\w/g, (char) => char.toUpperCase());
|
|
81
|
-
}
|
|
82
|
-
//#endregion
|
|
83
|
-
//#region src/objects.ts
|
|
84
|
-
/** @private is the value an empty array? */
|
|
85
|
-
var isEmptyArray = (value) => Array.isArray(value) && value.length === 0;
|
|
86
|
-
/** @private is the given object a Function? */
|
|
87
|
-
var isFunction = (obj) => typeof obj === "function";
|
|
88
|
-
/** @private is the given object an integer? */
|
|
89
|
-
var isInteger = (obj) => String(Math.floor(Number(obj))) === String(obj);
|
|
90
|
-
/** @private is the given object a NaN? */
|
|
91
|
-
var isNaN = (obj) => obj !== obj;
|
|
92
|
-
/**
|
|
93
|
-
* Deeply get a value from an object via its path.
|
|
94
|
-
*/
|
|
95
|
-
function getIn(obj, key, def, p = 0) {
|
|
96
|
-
const path = toPath(key);
|
|
97
|
-
while (obj && p < path.length) obj = obj[path[p++]];
|
|
98
|
-
if (p !== path.length && !obj) return def;
|
|
99
|
-
return obj === void 0 ? def : obj;
|
|
100
|
-
}
|
|
101
|
-
function setIn(obj, path, value) {
|
|
102
|
-
const res = clone(obj);
|
|
103
|
-
let resVal = res;
|
|
104
|
-
let i = 0;
|
|
105
|
-
const pathArray = toPath(path);
|
|
106
|
-
for (; i < pathArray.length - 1; i++) {
|
|
107
|
-
const currentPath = pathArray[i];
|
|
108
|
-
const currentObj = getIn(obj, pathArray.slice(0, i + 1));
|
|
109
|
-
if (currentObj && (isObject(currentObj) || Array.isArray(currentObj))) resVal = resVal[currentPath] = clone(currentObj);
|
|
110
|
-
else {
|
|
111
|
-
const nextPath = pathArray[i + 1];
|
|
112
|
-
resVal = resVal[currentPath] = isInteger(nextPath) && Number(nextPath) >= 0 ? [] : {};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if ((i === 0 ? obj : resVal)[pathArray[i]] === value) return obj;
|
|
116
|
-
if (value === void 0) delete resVal[pathArray[i]];
|
|
117
|
-
else resVal[pathArray[i]] = value;
|
|
118
|
-
if (i === 0 && value === void 0) delete res[pathArray[i]];
|
|
119
|
-
return res;
|
|
120
|
-
}
|
|
121
|
-
function clone(value) {
|
|
122
|
-
if (Array.isArray(value)) return [...value];
|
|
123
|
-
else if (typeof value === "object" && value !== null) return { ...value };
|
|
124
|
-
else return value;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Deep clone a value, preserving function references and class instances.
|
|
128
|
-
* Unlike structuredClone, this handles objects that contain functions
|
|
129
|
-
* (e.g. CollectionConfig with target(), childCollections(), callbacks).
|
|
130
|
-
*/
|
|
131
|
-
function deepClone(value) {
|
|
132
|
-
if (value === null || value === void 0) return value;
|
|
133
|
-
if (typeof value === "function") return value;
|
|
134
|
-
if (typeof value !== "object") return value;
|
|
135
|
-
if (Array.isArray(value)) return value.map((item) => deepClone(item));
|
|
136
|
-
if (Object.getPrototypeOf(value) !== Object.prototype) return value;
|
|
137
|
-
const result = {};
|
|
138
|
-
for (const key of Object.keys(value)) result[key] = deepClone(value[key]);
|
|
139
|
-
return result;
|
|
140
|
-
}
|
|
141
|
-
function toPath(value) {
|
|
142
|
-
if (Array.isArray(value)) return value;
|
|
143
|
-
return value.replace(/\[(\d+)]/g, ".$1").replace(/^\./, "").replace(/\.$/, "").split(".");
|
|
144
|
-
}
|
|
145
|
-
var pick = (obj, ...args) => ({ ...args.reduce((res, key) => ({
|
|
146
|
-
...res,
|
|
147
|
-
[key]: obj[key]
|
|
148
|
-
}), {}) });
|
|
149
|
-
function isObject(item) {
|
|
150
|
-
return !!item && typeof item === "object" && !Array.isArray(item);
|
|
151
|
-
}
|
|
152
|
-
function isPlainObject(obj) {
|
|
153
|
-
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) return false;
|
|
154
|
-
return Object.getPrototypeOf(obj) === Object.prototype;
|
|
155
|
-
}
|
|
156
|
-
function mergeDeep(target, source, ignoreUndefined = false) {
|
|
157
|
-
if (!isObject(target)) return target;
|
|
158
|
-
const output = { ...target };
|
|
159
|
-
if (!isObject(source)) return output;
|
|
160
|
-
for (const key in source) {
|
|
161
|
-
if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
|
|
162
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
163
|
-
const sourceValue = source[key];
|
|
164
|
-
const outputValue = output[key];
|
|
165
|
-
if (ignoreUndefined && sourceValue === void 0) continue;
|
|
166
|
-
if (sourceValue instanceof Date) output[key] = new Date(sourceValue.getTime());
|
|
167
|
-
else if (Array.isArray(sourceValue)) if (Array.isArray(outputValue)) if (!(sourceValue.some(isPlainObject) || outputValue.some(isPlainObject))) output[key] = [...sourceValue];
|
|
168
|
-
else {
|
|
169
|
-
const newArray = [];
|
|
170
|
-
const maxLength = Math.max(outputValue.length, sourceValue.length);
|
|
171
|
-
for (let i = 0; i < maxLength; i++) {
|
|
172
|
-
const sourceItem = sourceValue[i];
|
|
173
|
-
const targetItem = outputValue[i];
|
|
174
|
-
if (i >= sourceValue.length) newArray[i] = targetItem;
|
|
175
|
-
else if (i >= outputValue.length) newArray[i] = sourceItem;
|
|
176
|
-
else if (sourceItem === null) newArray[i] = targetItem;
|
|
177
|
-
else if (isPlainObject(sourceItem) && isPlainObject(targetItem)) newArray[i] = mergeDeep(targetItem, sourceItem, ignoreUndefined);
|
|
178
|
-
else newArray[i] = sourceItem;
|
|
179
|
-
}
|
|
180
|
-
output[key] = newArray;
|
|
181
|
-
}
|
|
182
|
-
else output[key] = [...sourceValue];
|
|
183
|
-
else if (isPlainObject(sourceValue)) if (isPlainObject(outputValue)) output[key] = mergeDeep(outputValue, sourceValue, ignoreUndefined);
|
|
184
|
-
else output[key] = sourceValue;
|
|
185
|
-
else if (isObject(sourceValue)) output[key] = sourceValue;
|
|
186
|
-
else output[key] = sourceValue;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return output;
|
|
190
|
-
}
|
|
191
|
-
function getValueInPath(o, path) {
|
|
192
|
-
if (!o) return void 0;
|
|
193
|
-
if (typeof o === "object") {
|
|
194
|
-
if (path in o) return o[path];
|
|
195
|
-
if (path.includes(".") || path.includes("[")) {
|
|
196
|
-
let pathSegments = path.split(/[.[]/);
|
|
197
|
-
if (path.includes("[")) pathSegments = pathSegments.map((segment) => segment.replace("]", ""));
|
|
198
|
-
const firstSegment = pathSegments[0];
|
|
199
|
-
const isArrayAndIndexExists = Array.isArray(o[firstSegment]) && !isNaN(parseInt(pathSegments[1]));
|
|
200
|
-
const nextObject = isArrayAndIndexExists ? o[firstSegment][parseInt(pathSegments[1])] : o[firstSegment];
|
|
201
|
-
const nextPath = pathSegments.slice(isArrayAndIndexExists ? 2 : 1).join(".");
|
|
202
|
-
if (nextPath === "") return nextObject;
|
|
203
|
-
return getValueInPath(nextObject, nextPath);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
function removeInPath(o, path) {
|
|
208
|
-
const res = clone(o);
|
|
209
|
-
let current = res;
|
|
210
|
-
const parts = path.split(".");
|
|
211
|
-
const last = parts.pop();
|
|
212
|
-
for (const part of parts) if (part in current && current[part] !== null && typeof current[part] === "object") {
|
|
213
|
-
current[part] = clone(current[part]);
|
|
214
|
-
current = current[part];
|
|
215
|
-
} else return res;
|
|
216
|
-
if (last && current && typeof current === "object") delete current[last];
|
|
217
|
-
return res;
|
|
218
|
-
}
|
|
219
|
-
function removeFunctions(o) {
|
|
220
|
-
if (o === void 0) return void 0;
|
|
221
|
-
if (o === null) return null;
|
|
222
|
-
if (typeof o === "object") {
|
|
223
|
-
if (Array.isArray(o)) return o.map((v) => removeFunctions(v));
|
|
224
|
-
if (!isPlainObject(o)) return o;
|
|
225
|
-
return Object.entries(o).filter(([_, value]) => typeof value !== "function").map(([key, value]) => {
|
|
226
|
-
if (Array.isArray(value)) return { [key]: value.map((v) => removeFunctions(v)) };
|
|
227
|
-
else if (typeof value === "object") return { [key]: removeFunctions(value) };
|
|
228
|
-
else return { [key]: value };
|
|
229
|
-
}).reduce((a, b) => ({
|
|
230
|
-
...a,
|
|
231
|
-
...b
|
|
232
|
-
}), {});
|
|
233
|
-
}
|
|
234
|
-
return o;
|
|
235
|
-
}
|
|
236
|
-
function getHashValue(v) {
|
|
237
|
-
if (!v) return null;
|
|
238
|
-
if (typeof v === "object" && v !== null) {
|
|
239
|
-
if ("id" in v) return String(v.id);
|
|
240
|
-
else if (v instanceof Date) return v.toLocaleString();
|
|
241
|
-
else if (v instanceof _rebasepro_types.GeoPoint) return (0, object_hash.default)(v);
|
|
242
|
-
}
|
|
243
|
-
return (0, object_hash.default)(v, { ignoreUnknown: true });
|
|
244
|
-
}
|
|
245
|
-
function removeUndefined(value, removeEmptyStrings) {
|
|
246
|
-
if (typeof value === "function") return value;
|
|
247
|
-
if (Array.isArray(value)) return value.map((v) => removeUndefined(v, removeEmptyStrings));
|
|
248
|
-
if (typeof value === "object") {
|
|
249
|
-
if (value === null) return value;
|
|
250
|
-
if (!isPlainObject(value)) return value;
|
|
251
|
-
const res = {};
|
|
252
|
-
Object.keys(value).forEach((key) => {
|
|
253
|
-
if (!isEmptyObject(value)) {
|
|
254
|
-
const childRes = removeUndefined(value[key], removeEmptyStrings);
|
|
255
|
-
const isString = typeof childRes === "string";
|
|
256
|
-
const shouldKeepIfString = !removeEmptyStrings || removeEmptyStrings && !isString || removeEmptyStrings && isString && childRes !== "";
|
|
257
|
-
if (childRes !== void 0 && !isEmptyObject(childRes) && shouldKeepIfString) res[key] = childRes;
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
return res;
|
|
261
|
-
}
|
|
262
|
-
return value;
|
|
263
|
-
}
|
|
264
|
-
function removeNulls(value) {
|
|
265
|
-
if (typeof value === "function") return value;
|
|
266
|
-
if (Array.isArray(value)) return value.map((v) => removeNulls(v));
|
|
267
|
-
if (typeof value === "object") {
|
|
268
|
-
if (value === null) return value;
|
|
269
|
-
if (!isPlainObject(value)) return value;
|
|
270
|
-
const res = {};
|
|
271
|
-
const obj = value;
|
|
272
|
-
Object.keys(obj).forEach((key) => {
|
|
273
|
-
if (obj[key] !== null) res[key] = removeNulls(obj[key]);
|
|
274
|
-
});
|
|
275
|
-
return res;
|
|
276
|
-
}
|
|
277
|
-
return value;
|
|
278
|
-
}
|
|
279
|
-
function isEmptyObject(obj) {
|
|
280
|
-
return obj && Object.getPrototypeOf(obj) === Object.prototype && Object.keys(obj).length === 0;
|
|
281
|
-
}
|
|
282
|
-
function removePropsIfExisting(source, comparison) {
|
|
283
|
-
const isObject = (val) => typeof val === "object" && val !== null;
|
|
284
|
-
const isArray = (val) => Array.isArray(val);
|
|
285
|
-
if (!isObject(source) || !isObject(comparison)) return source;
|
|
286
|
-
const res = isArray(source) ? [...source] : { ...source };
|
|
287
|
-
if (isArray(res)) {
|
|
288
|
-
for (let i = res.length - 1; i >= 0; i--) if (res[i] === comparison[i]) res.splice(i, 1);
|
|
289
|
-
else if (isObject(res[i]) && isObject(comparison[i])) res[i] = removePropsIfExisting(res[i], comparison[i]);
|
|
290
|
-
} else Object.keys(comparison).forEach((key) => {
|
|
291
|
-
if (key in res) {
|
|
292
|
-
if (isObject(res[key]) && isObject(comparison[key])) res[key] = removePropsIfExisting(res[key], comparison[key]);
|
|
293
|
-
else if (res[key] === comparison[key]) delete res[key];
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
return res;
|
|
297
|
-
}
|
|
298
|
-
//#endregion
|
|
299
|
-
//#region src/arrays.ts
|
|
300
|
-
function toArray(input) {
|
|
301
|
-
return Array.isArray(input) ? input : input ? [input] : [];
|
|
302
|
-
}
|
|
303
|
-
//#endregion
|
|
304
|
-
//#region src/dates.ts
|
|
305
|
-
var defaultDateFormat = "MMMM dd, yyyy, HH:mm:ss";
|
|
306
|
-
//#endregion
|
|
307
|
-
//#region src/hash.ts
|
|
308
|
-
function hashString(str) {
|
|
309
|
-
if (!str) return 0;
|
|
310
|
-
let hash = 0;
|
|
311
|
-
let i;
|
|
312
|
-
let chr;
|
|
313
|
-
for (i = 0; i < str.length; i++) {
|
|
314
|
-
chr = str.charCodeAt(i);
|
|
315
|
-
hash = (hash << 5) - hash + chr;
|
|
316
|
-
hash |= 0;
|
|
317
|
-
}
|
|
318
|
-
return Math.abs(hash);
|
|
319
|
-
}
|
|
320
|
-
//#endregion
|
|
321
|
-
//#region src/regexp.ts
|
|
322
|
-
function serializeRegExp(input) {
|
|
323
|
-
if (!input) return "";
|
|
324
|
-
return input.toString();
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Get a RegExp out of a serialized string
|
|
328
|
-
* @param input
|
|
329
|
-
*/
|
|
330
|
-
function hydrateRegExp(input) {
|
|
331
|
-
if (!input) return void 0;
|
|
332
|
-
const fragments = input.match(/\/(.*?)\/([a-z]*)?$/i);
|
|
333
|
-
if (fragments) return new RegExp(fragments[1], fragments[2] || "");
|
|
334
|
-
else return new RegExp(input, "");
|
|
335
|
-
}
|
|
336
|
-
function isValidRegExp(input) {
|
|
337
|
-
if (input.match(/\/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)\/((?:g(?:im?|mi?)?|i(?:gm?|mg?)?|m(?:gi?|ig?)?)?)/)) return true;
|
|
338
|
-
return !!input.match(/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)/);
|
|
339
|
-
}
|
|
340
|
-
//#endregion
|
|
341
|
-
//#region src/flatten_object.ts
|
|
342
|
-
function flattenObject(obj, parentKey = "") {
|
|
343
|
-
if (!obj) return obj;
|
|
344
|
-
return Object.keys(obj).reduce((flatObj, key) => {
|
|
345
|
-
const newKey = parentKey ? `${parentKey}.${key}` : key;
|
|
346
|
-
if (typeof obj[key] === "object" && obj[key] !== null) if (Array.isArray(obj[key])) obj[key].forEach((item, index) => {
|
|
347
|
-
if (typeof item === "object" && item !== null) Object.assign(flatObj, flattenObject(item, `${newKey}[${index}]`));
|
|
348
|
-
else flatObj[`${newKey}[${index}]`] = item;
|
|
349
|
-
});
|
|
350
|
-
else Object.assign(flatObj, flattenObject(obj[key], newKey));
|
|
351
|
-
else flatObj[newKey] = obj[key];
|
|
352
|
-
return flatObj;
|
|
353
|
-
}, {});
|
|
354
|
-
}
|
|
355
|
-
function getArrayValuesCount(array) {
|
|
356
|
-
return array.reduce((acc, obj) => {
|
|
357
|
-
Object.entries(obj).forEach(([key, value]) => {
|
|
358
|
-
if (Array.isArray(value)) acc[key] = Math.max(acc[key] || 0, value.length);
|
|
359
|
-
if (typeof value === "object" && value !== null) {
|
|
360
|
-
const nested = getArrayValuesCount([value]);
|
|
361
|
-
Object.entries(nested).forEach(([nestedKey, nestedCount]) => {
|
|
362
|
-
const compoundKey = `${key}.${nestedKey}`;
|
|
363
|
-
acc[compoundKey] = Math.max(acc[compoundKey] || 0, nestedCount);
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
return acc;
|
|
368
|
-
}, {});
|
|
369
|
-
}
|
|
370
|
-
//#endregion
|
|
371
|
-
//#region src/plurals.ts
|
|
372
|
-
/**
|
|
373
|
-
* Returns the plural of an English word.
|
|
374
|
-
*
|
|
375
|
-
* @param {string} word
|
|
376
|
-
* @param {number} [amount]
|
|
377
|
-
* @returns {string}
|
|
378
|
-
*/
|
|
379
|
-
function plural(word, amount) {
|
|
380
|
-
if (amount !== void 0 && amount === 1) return word;
|
|
381
|
-
const plurals = {
|
|
382
|
-
"(quiz)$": "$1zes",
|
|
383
|
-
"^(ox)$": "$1en",
|
|
384
|
-
"([m|l])ouse$": "$1ice",
|
|
385
|
-
"(matr|vert|ind)ix|ex$": "$1ices",
|
|
386
|
-
"(x|ch|ss|sh)$": "$1es",
|
|
387
|
-
"([^aeiouy]|qu)y$": "$1ies",
|
|
388
|
-
"(hive)$": "$1s",
|
|
389
|
-
"(?:([^f])fe|([lr])f)$": "$1$2ves",
|
|
390
|
-
"(shea|lea|loa|thie)f$": "$1ves",
|
|
391
|
-
sis$: "ses",
|
|
392
|
-
"([ti])um$": "$1a",
|
|
393
|
-
"(tomat|potat|ech|her|vet)o$": "$1oes",
|
|
394
|
-
"(bu)s$": "$1ses",
|
|
395
|
-
"(alias)$": "$1es",
|
|
396
|
-
"(octop)us$": "$1i",
|
|
397
|
-
"(ax|test)is$": "$1es",
|
|
398
|
-
"(us)$": "$1es",
|
|
399
|
-
"([^s]+)$": "$1s"
|
|
400
|
-
};
|
|
401
|
-
const irregular = {
|
|
402
|
-
move: "moves",
|
|
403
|
-
foot: "feet",
|
|
404
|
-
goose: "geese",
|
|
405
|
-
sex: "sexes",
|
|
406
|
-
child: "children",
|
|
407
|
-
man: "men",
|
|
408
|
-
tooth: "teeth",
|
|
409
|
-
person: "people"
|
|
410
|
-
};
|
|
411
|
-
if ([
|
|
412
|
-
"sheep",
|
|
413
|
-
"fish",
|
|
414
|
-
"deer",
|
|
415
|
-
"moose",
|
|
416
|
-
"series",
|
|
417
|
-
"species",
|
|
418
|
-
"money",
|
|
419
|
-
"rice",
|
|
420
|
-
"information",
|
|
421
|
-
"equipment",
|
|
422
|
-
"bison",
|
|
423
|
-
"cod",
|
|
424
|
-
"offspring",
|
|
425
|
-
"pike",
|
|
426
|
-
"salmon",
|
|
427
|
-
"shrimp",
|
|
428
|
-
"swine",
|
|
429
|
-
"trout",
|
|
430
|
-
"aircraft",
|
|
431
|
-
"hovercraft",
|
|
432
|
-
"spacecraft",
|
|
433
|
-
"sugar",
|
|
434
|
-
"tuna",
|
|
435
|
-
"you",
|
|
436
|
-
"wood"
|
|
437
|
-
].indexOf(word.toLowerCase()) >= 0) return word;
|
|
438
|
-
for (const w in irregular) {
|
|
439
|
-
const pattern = new RegExp(`${w}$`, "i");
|
|
440
|
-
const replace = irregular[w];
|
|
441
|
-
if (pattern.test(word)) return word.replace(pattern, replace);
|
|
442
|
-
}
|
|
443
|
-
for (const reg in plurals) {
|
|
444
|
-
const pattern = new RegExp(reg, "i");
|
|
445
|
-
if (pattern.test(word)) return word.replace(pattern, plurals[reg]);
|
|
446
|
-
}
|
|
447
|
-
return word;
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Returns the singular of an English word.
|
|
451
|
-
*
|
|
452
|
-
* @param {string} word
|
|
453
|
-
* @param {number} [amount]
|
|
454
|
-
* @returns {string}
|
|
455
|
-
*/
|
|
456
|
-
function singular(word, amount) {
|
|
457
|
-
if (amount !== void 0 && amount !== 1) return word;
|
|
458
|
-
const singulars = {
|
|
459
|
-
"(quiz)zes$": "$1",
|
|
460
|
-
"(matr)ices$": "$1ix",
|
|
461
|
-
"(vert|ind)ices$": "$1ex",
|
|
462
|
-
"^(ox)en$": "$1",
|
|
463
|
-
"(alias)es$": "$1",
|
|
464
|
-
"(octop|vir)i$": "$1us",
|
|
465
|
-
"(cris|ax|test)es$": "$1is",
|
|
466
|
-
"(shoe)s$": "$1",
|
|
467
|
-
"(o)es$": "$1",
|
|
468
|
-
"(bus)es$": "$1",
|
|
469
|
-
"([m|l])ice$": "$1ouse",
|
|
470
|
-
"(x|ch|ss|sh)es$": "$1",
|
|
471
|
-
"(m)ovies$": "$1ovie",
|
|
472
|
-
"(s)eries$": "$1eries",
|
|
473
|
-
"([^aeiouy]|qu)ies$": "$1y",
|
|
474
|
-
"([lr])ves$": "$1f",
|
|
475
|
-
"(tive)s$": "$1",
|
|
476
|
-
"(hive)s$": "$1",
|
|
477
|
-
"(li|wi|kni)ves$": "$1fe",
|
|
478
|
-
"(shea|loa|lea|thie)ves$": "$1f",
|
|
479
|
-
"(^analy)ses$": "$1sis",
|
|
480
|
-
"((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$": "$1$2sis",
|
|
481
|
-
"([ti])a$": "$1um",
|
|
482
|
-
"(n)ews$": "$1ews",
|
|
483
|
-
"(h|bl)ouses$": "$1ouse",
|
|
484
|
-
"(corpse)s$": "$1",
|
|
485
|
-
"(us)es$": "$1",
|
|
486
|
-
s$: ""
|
|
487
|
-
};
|
|
488
|
-
const irregular = {
|
|
489
|
-
move: "moves",
|
|
490
|
-
foot: "feet",
|
|
491
|
-
goose: "geese",
|
|
492
|
-
sex: "sexes",
|
|
493
|
-
child: "children",
|
|
494
|
-
man: "men",
|
|
495
|
-
tooth: "teeth",
|
|
496
|
-
person: "people"
|
|
497
|
-
};
|
|
498
|
-
if ([
|
|
499
|
-
"sheep",
|
|
500
|
-
"fish",
|
|
501
|
-
"deer",
|
|
502
|
-
"moose",
|
|
503
|
-
"series",
|
|
504
|
-
"species",
|
|
505
|
-
"money",
|
|
506
|
-
"rice",
|
|
507
|
-
"information",
|
|
508
|
-
"equipment",
|
|
509
|
-
"bison",
|
|
510
|
-
"cod",
|
|
511
|
-
"offspring",
|
|
512
|
-
"pike",
|
|
513
|
-
"salmon",
|
|
514
|
-
"shrimp",
|
|
515
|
-
"swine",
|
|
516
|
-
"trout",
|
|
517
|
-
"aircraft",
|
|
518
|
-
"hovercraft",
|
|
519
|
-
"spacecraft",
|
|
520
|
-
"sugar",
|
|
521
|
-
"tuna",
|
|
522
|
-
"you",
|
|
523
|
-
"wood"
|
|
524
|
-
].indexOf(word.toLowerCase()) >= 0) return word;
|
|
525
|
-
for (const w in irregular) {
|
|
526
|
-
const pattern = new RegExp(`${irregular[w]}$`, "i");
|
|
527
|
-
if (pattern.test(word)) return word.replace(pattern, w);
|
|
528
|
-
}
|
|
529
|
-
for (const reg in singulars) {
|
|
530
|
-
const pattern = new RegExp(reg, "i");
|
|
531
|
-
if (pattern.test(word)) return word.replace(pattern, singulars[reg]);
|
|
532
|
-
}
|
|
533
|
-
return word;
|
|
534
|
-
}
|
|
535
|
-
//#endregion
|
|
536
|
-
//#region src/names.ts
|
|
537
|
-
/**
|
|
538
|
-
* Generates a foreign key column name from a given string, typically a collection slug or name.
|
|
539
|
-
* It converts the name to snake_case, attempts to singularize it by removing a trailing 's'
|
|
540
|
-
* (a common convention for collection names), and appends '_id'.
|
|
541
|
-
*
|
|
542
|
-
* @param name The base name to convert to a foreign key.
|
|
543
|
-
* @returns A foreign key name in the format 'singular_name_id'.
|
|
544
|
-
*
|
|
545
|
-
* @example
|
|
546
|
-
* // returns "user_id"
|
|
547
|
-
* generateForeignKeyName("users")
|
|
548
|
-
*
|
|
549
|
-
* @example
|
|
550
|
-
* // returns "post_id"
|
|
551
|
-
* generateForeignKeyName("posts")
|
|
552
|
-
*
|
|
553
|
-
* @example
|
|
554
|
-
* // returns "product_id"
|
|
555
|
-
* generateForeignKeyName("Product")
|
|
556
|
-
*
|
|
557
|
-
*/
|
|
558
|
-
function generateForeignKeyName(name) {
|
|
559
|
-
const snakeCaseName = toSnakeCase(name);
|
|
560
|
-
return `${snakeCaseName.endsWith("s") ? snakeCaseName.slice(0, -1) : snakeCaseName}_id`;
|
|
561
|
-
}
|
|
562
|
-
//#endregion
|
|
563
|
-
//#region src/fields.ts
|
|
564
|
-
function isDefaultFieldConfigId(id) {
|
|
565
|
-
return [
|
|
566
|
-
"text_field",
|
|
567
|
-
"multiline",
|
|
568
|
-
"markdown",
|
|
569
|
-
"url",
|
|
570
|
-
"email",
|
|
571
|
-
"switch",
|
|
572
|
-
"select",
|
|
573
|
-
"multi_select",
|
|
574
|
-
"number_input",
|
|
575
|
-
"number_select",
|
|
576
|
-
"multi_number_select",
|
|
577
|
-
"file_upload",
|
|
578
|
-
"multi_file_upload",
|
|
579
|
-
"reference",
|
|
580
|
-
"multi_references",
|
|
581
|
-
"relation",
|
|
582
|
-
"date_time",
|
|
583
|
-
"group",
|
|
584
|
-
"key_value",
|
|
585
|
-
"repeat",
|
|
586
|
-
"custom_array",
|
|
587
|
-
"block"
|
|
588
|
-
].includes(id);
|
|
589
|
-
}
|
|
590
|
-
//#endregion
|
|
591
|
-
exports.camelCase = camelCase;
|
|
592
|
-
exports.clone = clone;
|
|
593
|
-
exports.deepClone = deepClone;
|
|
594
|
-
exports.defaultDateFormat = defaultDateFormat;
|
|
595
|
-
exports.flattenObject = flattenObject;
|
|
596
|
-
exports.generateForeignKeyName = generateForeignKeyName;
|
|
597
|
-
exports.getArrayValuesCount = getArrayValuesCount;
|
|
598
|
-
exports.getHashValue = getHashValue;
|
|
599
|
-
exports.getIn = getIn;
|
|
600
|
-
exports.getValueInPath = getValueInPath;
|
|
601
|
-
exports.hashString = hashString;
|
|
602
|
-
exports.hydrateRegExp = hydrateRegExp;
|
|
603
|
-
exports.isDefaultFieldConfigId = isDefaultFieldConfigId;
|
|
604
|
-
exports.isEmptyArray = isEmptyArray;
|
|
605
|
-
exports.isEmptyObject = isEmptyObject;
|
|
606
|
-
exports.isFunction = isFunction;
|
|
607
|
-
exports.isInteger = isInteger;
|
|
608
|
-
exports.isNaN = isNaN;
|
|
609
|
-
exports.isObject = isObject;
|
|
610
|
-
exports.isPlainObject = isPlainObject;
|
|
611
|
-
exports.isValidRegExp = isValidRegExp;
|
|
612
|
-
exports.mergeDeep = mergeDeep;
|
|
613
|
-
exports.pick = pick;
|
|
614
|
-
exports.plural = plural;
|
|
615
|
-
exports.prettifyIdentifier = prettifyIdentifier;
|
|
616
|
-
exports.randomColor = randomColor;
|
|
617
|
-
exports.randomString = randomString;
|
|
618
|
-
exports.removeFunctions = removeFunctions;
|
|
619
|
-
exports.removeInPath = removeInPath;
|
|
620
|
-
exports.removeNulls = removeNulls;
|
|
621
|
-
exports.removePropsIfExisting = removePropsIfExisting;
|
|
622
|
-
exports.removeUndefined = removeUndefined;
|
|
623
|
-
exports.serializeRegExp = serializeRegExp;
|
|
624
|
-
exports.setIn = setIn;
|
|
625
|
-
exports.singular = singular;
|
|
626
|
-
exports.slugify = slugify;
|
|
627
|
-
exports.toArray = toArray;
|
|
628
|
-
exports.toKebabCase = toKebabCase;
|
|
629
|
-
exports.toSnakeCase = toSnakeCase;
|
|
630
|
-
exports.unslugify = unslugify;
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
//# sourceMappingURL=index.umd.js.map
|