@zairakai/js-utils 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 +21 -0
- package/README.md +270 -0
- package/dist/arrays.cjs +210 -0
- package/dist/arrays.d.cts +119 -0
- package/dist/arrays.d.ts +119 -0
- package/dist/arrays.js +32 -0
- package/dist/chunk-27YHP2CK.js +407 -0
- package/dist/chunk-3WNRYKPG.js +37 -0
- package/dist/chunk-42CHLXT7.js +214 -0
- package/dist/chunk-6F4PWJZI.js +0 -0
- package/dist/chunk-7SXRFZBB.js +173 -0
- package/dist/chunk-F6RSTW65.js +156 -0
- package/dist/chunk-G7ZJ23DW.js +253 -0
- package/dist/chunk-IPP7PA6H.js +136 -0
- package/dist/chunk-LDSWHSRX.js +96 -0
- package/dist/chunk-TY75OOIQ.js +700 -0
- package/dist/chunk-W6JEMFAF.js +54 -0
- package/dist/chunk-XEJLBAXE.js +164 -0
- package/dist/chunk-Z7G3SIQH.js +270 -0
- package/dist/chunk-ZJPKS2MQ.js +101 -0
- package/dist/collections.cjs +797 -0
- package/dist/collections.d.cts +353 -0
- package/dist/collections.d.ts +353 -0
- package/dist/collections.js +17 -0
- package/dist/datetime.cjs +80 -0
- package/dist/datetime.d.cts +75 -0
- package/dist/datetime.d.ts +75 -0
- package/dist/datetime.js +24 -0
- package/dist/equals.cjs +121 -0
- package/dist/equals.d.cts +24 -0
- package/dist/equals.d.ts +24 -0
- package/dist/equals.js +8 -0
- package/dist/formatters.cjs +201 -0
- package/dist/formatters.d.cts +180 -0
- package/dist/formatters.d.ts +180 -0
- package/dist/formatters.js +48 -0
- package/dist/index.cjs +2906 -0
- package/dist/index.d.cts +120 -0
- package/dist/index.d.ts +120 -0
- package/dist/index.js +348 -0
- package/dist/number.cjs +279 -0
- package/dist/number.d.cts +177 -0
- package/dist/number.d.ts +177 -0
- package/dist/number.js +10 -0
- package/dist/obj.cjs +427 -0
- package/dist/obj.d.cts +177 -0
- package/dist/obj.d.ts +177 -0
- package/dist/obj.js +12 -0
- package/dist/php-arrays.cjs +954 -0
- package/dist/php-arrays.d.cts +256 -0
- package/dist/php-arrays.d.ts +256 -0
- package/dist/php-arrays.js +70 -0
- package/dist/runtime.cjs +134 -0
- package/dist/runtime.d.cts +90 -0
- package/dist/runtime.d.ts +90 -0
- package/dist/runtime.js +24 -0
- package/dist/schemas.cjs +86 -0
- package/dist/schemas.d.cts +108 -0
- package/dist/schemas.d.ts +108 -0
- package/dist/schemas.js +22 -0
- package/dist/str.cjs +499 -0
- package/dist/str.d.cts +282 -0
- package/dist/str.d.ts +282 -0
- package/dist/str.js +11 -0
- package/dist/types.cjs +18 -0
- package/dist/types.d.cts +13 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.js +1 -0
- package/dist/validator.cjs +251 -0
- package/dist/validator.d.cts +99 -0
- package/dist/validator.d.ts +99 -0
- package/dist/validator.js +11 -0
- package/dist/validators.cjs +217 -0
- package/dist/validators.d.cts +216 -0
- package/dist/validators.d.ts +216 -0
- package/dist/validators.js +64 -0
- package/package.json +180 -0
- package/src/arrays.ts +316 -0
- package/src/collections.ts +866 -0
- package/src/datetime.ts +103 -0
- package/src/equals.ts +134 -0
- package/src/formatters.ts +342 -0
- package/src/index.ts +36 -0
- package/src/number.ts +281 -0
- package/src/obj.ts +303 -0
- package/src/php-arrays.ts +445 -0
- package/src/pipe.ts +29 -0
- package/src/runtime.ts +194 -0
- package/src/schemas.ts +136 -0
- package/src/str.ts +438 -0
- package/src/types.ts +13 -0
- package/src/validator.ts +157 -0
- package/src/validators.ts +359 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EnhancedArray,
|
|
3
|
+
EnhancedMap,
|
|
4
|
+
collect,
|
|
5
|
+
collectMap,
|
|
6
|
+
mapToObject,
|
|
7
|
+
objectToMap
|
|
8
|
+
} from "./chunk-TY75OOIQ.js";
|
|
9
|
+
import "./chunk-LDSWHSRX.js";
|
|
10
|
+
export {
|
|
11
|
+
EnhancedArray,
|
|
12
|
+
EnhancedMap,
|
|
13
|
+
collect,
|
|
14
|
+
collectMap,
|
|
15
|
+
mapToObject,
|
|
16
|
+
objectToMap
|
|
17
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/datetime.ts
|
|
31
|
+
var datetime_exports = {};
|
|
32
|
+
__export(datetime_exports, {
|
|
33
|
+
dayjs: () => dayjs,
|
|
34
|
+
fromNow: () => fromNow,
|
|
35
|
+
isBetweenDates: () => isBetweenDates,
|
|
36
|
+
isFuture: () => isFuture,
|
|
37
|
+
isPast: () => isPast,
|
|
38
|
+
isToday: () => isToday,
|
|
39
|
+
now: () => now,
|
|
40
|
+
today: () => today,
|
|
41
|
+
tomorrow: () => tomorrow,
|
|
42
|
+
yesterday: () => yesterday
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(datetime_exports);
|
|
45
|
+
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
46
|
+
var import_isBetween = __toESM(require("dayjs/plugin/isBetween"), 1);
|
|
47
|
+
var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"), 1);
|
|
48
|
+
var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"), 1);
|
|
49
|
+
var import_relativeTime = __toESM(require("dayjs/plugin/relativeTime"), 1);
|
|
50
|
+
var import_utc = __toESM(require("dayjs/plugin/utc"), 1);
|
|
51
|
+
import_dayjs.default.extend(import_isBetween.default);
|
|
52
|
+
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
53
|
+
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
54
|
+
import_dayjs.default.extend(import_relativeTime.default);
|
|
55
|
+
import_dayjs.default.extend(import_utc.default);
|
|
56
|
+
var dayjs = import_dayjs.default;
|
|
57
|
+
var now = () => dayjs();
|
|
58
|
+
var today = () => dayjs().startOf("day");
|
|
59
|
+
var tomorrow = () => dayjs().add(1, "day").startOf("day");
|
|
60
|
+
var yesterday = () => dayjs().subtract(1, "day").startOf("day");
|
|
61
|
+
var isBetweenDates = (date, start, end, unit = "day", inclusivity = "[]") => {
|
|
62
|
+
return dayjs(date).isBetween(dayjs(start), dayjs(end), unit, inclusivity);
|
|
63
|
+
};
|
|
64
|
+
var fromNow = (date) => dayjs(date).fromNow();
|
|
65
|
+
var isToday = (date) => dayjs(date).isSame(dayjs(), "day");
|
|
66
|
+
var isPast = (date) => dayjs(date).isBefore(dayjs());
|
|
67
|
+
var isFuture = (date) => dayjs(date).isAfter(dayjs());
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
dayjs,
|
|
71
|
+
fromNow,
|
|
72
|
+
isBetweenDates,
|
|
73
|
+
isFuture,
|
|
74
|
+
isPast,
|
|
75
|
+
isToday,
|
|
76
|
+
now,
|
|
77
|
+
today,
|
|
78
|
+
tomorrow,
|
|
79
|
+
yesterday
|
|
80
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import dayjsModule, { ConfigType, Dayjs } from 'dayjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Date and time utilities using Day.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configured Dayjs instance.
|
|
9
|
+
*/
|
|
10
|
+
declare const dayjs: typeof dayjsModule;
|
|
11
|
+
/**
|
|
12
|
+
* Get the current date and time as a Dayjs instance.
|
|
13
|
+
*
|
|
14
|
+
* @returns {Dayjs} Current date and time
|
|
15
|
+
*/
|
|
16
|
+
declare const now: () => Dayjs;
|
|
17
|
+
/**
|
|
18
|
+
* Get today's date at the start of the day.
|
|
19
|
+
*
|
|
20
|
+
* @returns {Dayjs} Today's date
|
|
21
|
+
*/
|
|
22
|
+
declare const today: () => Dayjs;
|
|
23
|
+
/**
|
|
24
|
+
* Get tomorrow's date at the start of the day.
|
|
25
|
+
*
|
|
26
|
+
* @returns {Dayjs} Tomorrow's date
|
|
27
|
+
*/
|
|
28
|
+
declare const tomorrow: () => Dayjs;
|
|
29
|
+
/**
|
|
30
|
+
* Get yesterday's date at the start of the day.
|
|
31
|
+
*
|
|
32
|
+
* @returns {Dayjs} Yesterday's date
|
|
33
|
+
*/
|
|
34
|
+
declare const yesterday: () => Dayjs;
|
|
35
|
+
/**
|
|
36
|
+
* Check if a date is between two other dates.
|
|
37
|
+
*
|
|
38
|
+
* @param {ConfigType} date Date to check
|
|
39
|
+
* @param {ConfigType} start Start date
|
|
40
|
+
* @param {ConfigType} end End date
|
|
41
|
+
* @param {dayjsModule.OpUnitType} [unit='day'] Unit of comparison (day, month, year, etc.)
|
|
42
|
+
* @param {'()' | '[]' | '[)' | '(]'} [inclusivity='[]'] Inclusivity
|
|
43
|
+
* @returns {boolean} True if the date is between start and end
|
|
44
|
+
*/
|
|
45
|
+
declare const isBetweenDates: (date: ConfigType, start: ConfigType, end: ConfigType, unit?: dayjsModule.OpUnitType, inclusivity?: "()" | "[]" | "[)" | "(]") => boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Format a date to a human-readable relative time.
|
|
48
|
+
*
|
|
49
|
+
* @param {ConfigType} date Date to format
|
|
50
|
+
* @returns {string} Relative time (e.g., "2 hours ago")
|
|
51
|
+
*/
|
|
52
|
+
declare const fromNow: (date: ConfigType) => string;
|
|
53
|
+
/**
|
|
54
|
+
* Check if a date is today.
|
|
55
|
+
*
|
|
56
|
+
* @param {ConfigType} date Date to check
|
|
57
|
+
* @returns {boolean} True if the date is today
|
|
58
|
+
*/
|
|
59
|
+
declare const isToday: (date: ConfigType) => boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Check if a date is in the past.
|
|
62
|
+
*
|
|
63
|
+
* @param {ConfigType} date Date to check
|
|
64
|
+
* @returns {boolean} True if the date is in the past
|
|
65
|
+
*/
|
|
66
|
+
declare const isPast: (date: ConfigType) => boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Check if a date is in the future.
|
|
69
|
+
*
|
|
70
|
+
* @param {ConfigType} date Date to check
|
|
71
|
+
* @returns {boolean} True if the date is in the future
|
|
72
|
+
*/
|
|
73
|
+
declare const isFuture: (date: ConfigType) => boolean;
|
|
74
|
+
|
|
75
|
+
export { dayjs, fromNow, isBetweenDates, isFuture, isPast, isToday, now, today, tomorrow, yesterday };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import dayjsModule, { ConfigType, Dayjs } from 'dayjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Date and time utilities using Day.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configured Dayjs instance.
|
|
9
|
+
*/
|
|
10
|
+
declare const dayjs: typeof dayjsModule;
|
|
11
|
+
/**
|
|
12
|
+
* Get the current date and time as a Dayjs instance.
|
|
13
|
+
*
|
|
14
|
+
* @returns {Dayjs} Current date and time
|
|
15
|
+
*/
|
|
16
|
+
declare const now: () => Dayjs;
|
|
17
|
+
/**
|
|
18
|
+
* Get today's date at the start of the day.
|
|
19
|
+
*
|
|
20
|
+
* @returns {Dayjs} Today's date
|
|
21
|
+
*/
|
|
22
|
+
declare const today: () => Dayjs;
|
|
23
|
+
/**
|
|
24
|
+
* Get tomorrow's date at the start of the day.
|
|
25
|
+
*
|
|
26
|
+
* @returns {Dayjs} Tomorrow's date
|
|
27
|
+
*/
|
|
28
|
+
declare const tomorrow: () => Dayjs;
|
|
29
|
+
/**
|
|
30
|
+
* Get yesterday's date at the start of the day.
|
|
31
|
+
*
|
|
32
|
+
* @returns {Dayjs} Yesterday's date
|
|
33
|
+
*/
|
|
34
|
+
declare const yesterday: () => Dayjs;
|
|
35
|
+
/**
|
|
36
|
+
* Check if a date is between two other dates.
|
|
37
|
+
*
|
|
38
|
+
* @param {ConfigType} date Date to check
|
|
39
|
+
* @param {ConfigType} start Start date
|
|
40
|
+
* @param {ConfigType} end End date
|
|
41
|
+
* @param {dayjsModule.OpUnitType} [unit='day'] Unit of comparison (day, month, year, etc.)
|
|
42
|
+
* @param {'()' | '[]' | '[)' | '(]'} [inclusivity='[]'] Inclusivity
|
|
43
|
+
* @returns {boolean} True if the date is between start and end
|
|
44
|
+
*/
|
|
45
|
+
declare const isBetweenDates: (date: ConfigType, start: ConfigType, end: ConfigType, unit?: dayjsModule.OpUnitType, inclusivity?: "()" | "[]" | "[)" | "(]") => boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Format a date to a human-readable relative time.
|
|
48
|
+
*
|
|
49
|
+
* @param {ConfigType} date Date to format
|
|
50
|
+
* @returns {string} Relative time (e.g., "2 hours ago")
|
|
51
|
+
*/
|
|
52
|
+
declare const fromNow: (date: ConfigType) => string;
|
|
53
|
+
/**
|
|
54
|
+
* Check if a date is today.
|
|
55
|
+
*
|
|
56
|
+
* @param {ConfigType} date Date to check
|
|
57
|
+
* @returns {boolean} True if the date is today
|
|
58
|
+
*/
|
|
59
|
+
declare const isToday: (date: ConfigType) => boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Check if a date is in the past.
|
|
62
|
+
*
|
|
63
|
+
* @param {ConfigType} date Date to check
|
|
64
|
+
* @returns {boolean} True if the date is in the past
|
|
65
|
+
*/
|
|
66
|
+
declare const isPast: (date: ConfigType) => boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Check if a date is in the future.
|
|
69
|
+
*
|
|
70
|
+
* @param {ConfigType} date Date to check
|
|
71
|
+
* @returns {boolean} True if the date is in the future
|
|
72
|
+
*/
|
|
73
|
+
declare const isFuture: (date: ConfigType) => boolean;
|
|
74
|
+
|
|
75
|
+
export { dayjs, fromNow, isBetweenDates, isFuture, isPast, isToday, now, today, tomorrow, yesterday };
|
package/dist/datetime.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dayjs,
|
|
3
|
+
fromNow,
|
|
4
|
+
isBetweenDates,
|
|
5
|
+
isFuture,
|
|
6
|
+
isPast,
|
|
7
|
+
isToday,
|
|
8
|
+
now,
|
|
9
|
+
today,
|
|
10
|
+
tomorrow,
|
|
11
|
+
yesterday
|
|
12
|
+
} from "./chunk-3WNRYKPG.js";
|
|
13
|
+
export {
|
|
14
|
+
dayjs,
|
|
15
|
+
fromNow,
|
|
16
|
+
isBetweenDates,
|
|
17
|
+
isFuture,
|
|
18
|
+
isPast,
|
|
19
|
+
isToday,
|
|
20
|
+
now,
|
|
21
|
+
today,
|
|
22
|
+
tomorrow,
|
|
23
|
+
yesterday
|
|
24
|
+
};
|
package/dist/equals.cjs
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/equals.ts
|
|
21
|
+
var equals_exports = {};
|
|
22
|
+
__export(equals_exports, {
|
|
23
|
+
diff: () => diff,
|
|
24
|
+
isEqual: () => isEqual
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(equals_exports);
|
|
27
|
+
var isEqual = (a, b) => {
|
|
28
|
+
if (a === b) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (a && b && "object" === typeof a && "object" === typeof b) {
|
|
32
|
+
if (a.constructor !== b.constructor) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(a)) {
|
|
36
|
+
if (a.length !== b.length) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
for (let i = 0; i < a.length; i++) {
|
|
40
|
+
if (!isEqual(a[i], b[i])) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (a instanceof Map && b instanceof Map) {
|
|
47
|
+
if (a.size !== b.size) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
for (const [key, val] of a) {
|
|
51
|
+
if (!b.has(key) || !isEqual(val, b.get(key))) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (a instanceof Set && b instanceof Set) {
|
|
58
|
+
if (a.size !== b.size) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
for (const val of a) {
|
|
62
|
+
if (!b.has(val)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (a.constructor === RegExp) {
|
|
69
|
+
return a.source === b.source && a.flags === b.flags;
|
|
70
|
+
}
|
|
71
|
+
if (a.valueOf !== Object.prototype.valueOf) {
|
|
72
|
+
return a.valueOf() === b.valueOf();
|
|
73
|
+
}
|
|
74
|
+
if (a.toString !== Object.prototype.toString) {
|
|
75
|
+
return a.toString() === b.toString();
|
|
76
|
+
}
|
|
77
|
+
const keys = Object.keys(a);
|
|
78
|
+
if (keys.length !== Object.keys(b).length) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const bObj = b;
|
|
82
|
+
const aObj = a;
|
|
83
|
+
for (const key of keys) {
|
|
84
|
+
if (!Object.prototype.hasOwnProperty.call(bObj, key)) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (!isEqual(aObj[key], bObj[key])) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
return a !== a && b !== b;
|
|
94
|
+
};
|
|
95
|
+
var diff = (original, current) => {
|
|
96
|
+
const result = {};
|
|
97
|
+
if (isEqual(original, current)) {
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
if (!original || !current || "object" !== typeof original || "object" !== typeof current) {
|
|
101
|
+
return current || {};
|
|
102
|
+
}
|
|
103
|
+
const originalObj = original;
|
|
104
|
+
const currentObj = current;
|
|
105
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(originalObj), ...Object.keys(currentObj)]);
|
|
106
|
+
for (const key of keys) {
|
|
107
|
+
if (!isEqual(originalObj[key], currentObj[key])) {
|
|
108
|
+
if (originalObj[key] && currentObj[key] && "object" === typeof originalObj[key] && "object" === typeof currentObj[key] && !Array.isArray(originalObj[key])) {
|
|
109
|
+
result[key] = diff(originalObj[key], currentObj[key]);
|
|
110
|
+
} else {
|
|
111
|
+
result[key] = currentObj[key];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
};
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
diff,
|
|
120
|
+
isEqual
|
|
121
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { GenericRecord } from './types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Deep equality and comparison utilities
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Perform a deep comparison between two values to determine if they are equivalent.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} a The first value to compare
|
|
10
|
+
* @param {unknown} b The second value to compare
|
|
11
|
+
* @returns {boolean} True if the values are equivalent, false otherwise
|
|
12
|
+
*/
|
|
13
|
+
declare const isEqual: (a: unknown, b: unknown) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Find the differences between two objects.
|
|
16
|
+
* Returns an object containing only the keys that differ.
|
|
17
|
+
*
|
|
18
|
+
* @param {unknown} original The original object
|
|
19
|
+
* @param {unknown} current The current object
|
|
20
|
+
* @returns {GenericRecord} An object containing the differences
|
|
21
|
+
*/
|
|
22
|
+
declare const diff: (original: unknown, current: unknown) => GenericRecord;
|
|
23
|
+
|
|
24
|
+
export { diff, isEqual };
|
package/dist/equals.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { GenericRecord } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Deep equality and comparison utilities
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Perform a deep comparison between two values to determine if they are equivalent.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} a The first value to compare
|
|
10
|
+
* @param {unknown} b The second value to compare
|
|
11
|
+
* @returns {boolean} True if the values are equivalent, false otherwise
|
|
12
|
+
*/
|
|
13
|
+
declare const isEqual: (a: unknown, b: unknown) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Find the differences between two objects.
|
|
16
|
+
* Returns an object containing only the keys that differ.
|
|
17
|
+
*
|
|
18
|
+
* @param {unknown} original The original object
|
|
19
|
+
* @param {unknown} current The current object
|
|
20
|
+
* @returns {GenericRecord} An object containing the differences
|
|
21
|
+
*/
|
|
22
|
+
declare const diff: (original: unknown, current: unknown) => GenericRecord;
|
|
23
|
+
|
|
24
|
+
export { diff, isEqual };
|
package/dist/equals.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/formatters.ts
|
|
21
|
+
var formatters_exports = {};
|
|
22
|
+
__export(formatters_exports, {
|
|
23
|
+
camelCase: () => camelCase,
|
|
24
|
+
capitalize: () => capitalize,
|
|
25
|
+
kebabCase: () => kebabCase,
|
|
26
|
+
normalizeString: () => normalizeString,
|
|
27
|
+
numberFormat: () => numberFormat,
|
|
28
|
+
slugify: () => slugify,
|
|
29
|
+
snakeCase: () => snakeCase,
|
|
30
|
+
strContainsAll: () => strContainsAll,
|
|
31
|
+
strContainsAny: () => strContainsAny,
|
|
32
|
+
strFinish: () => strFinish,
|
|
33
|
+
strLimit: () => strLimit,
|
|
34
|
+
strMask: () => strMask,
|
|
35
|
+
strPadBoth: () => strPadBoth,
|
|
36
|
+
strPadLeft: () => strPadLeft,
|
|
37
|
+
strPadRight: () => strPadRight,
|
|
38
|
+
strRemove: () => strRemove,
|
|
39
|
+
strReverse: () => strReverse,
|
|
40
|
+
strStart: () => strStart,
|
|
41
|
+
strWordCount: () => strWordCount,
|
|
42
|
+
strWords: () => strWords,
|
|
43
|
+
studlyCase: () => studlyCase,
|
|
44
|
+
titleCase: () => titleCase
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(formatters_exports);
|
|
47
|
+
var capitalize = (value) => {
|
|
48
|
+
if (value == null) {
|
|
49
|
+
return "";
|
|
50
|
+
}
|
|
51
|
+
const stringValue = String(value);
|
|
52
|
+
return stringValue.charAt(0).toUpperCase() + stringValue.slice(1).toLowerCase();
|
|
53
|
+
};
|
|
54
|
+
var slugify = (text) => {
|
|
55
|
+
if (!text) {
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
return text.toString().normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-");
|
|
59
|
+
};
|
|
60
|
+
var strLimit = (value, size) => {
|
|
61
|
+
if (!value) {
|
|
62
|
+
return "";
|
|
63
|
+
}
|
|
64
|
+
const stringValue = String(value);
|
|
65
|
+
return stringValue.length <= size ? stringValue : `${stringValue.slice(0, size)}\u2026`;
|
|
66
|
+
};
|
|
67
|
+
var normalizeString = (value) => {
|
|
68
|
+
if (!value) {
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
return value.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
72
|
+
};
|
|
73
|
+
var strContainsAll = (haystack, needles) => {
|
|
74
|
+
if (!haystack || !Array.isArray(needles)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
return needles.every((needle) => haystack.includes(needle));
|
|
78
|
+
};
|
|
79
|
+
var strContainsAny = (haystack, needles) => {
|
|
80
|
+
if (!haystack || !Array.isArray(needles)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return needles.some((needle) => haystack.includes(needle));
|
|
84
|
+
};
|
|
85
|
+
var strFinish = (value, cap) => {
|
|
86
|
+
if (!value) {
|
|
87
|
+
return cap;
|
|
88
|
+
}
|
|
89
|
+
if (!cap) {
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
return value.endsWith(cap) ? value : value + cap;
|
|
93
|
+
};
|
|
94
|
+
var strStart = (value, prefix) => {
|
|
95
|
+
if (!value) {
|
|
96
|
+
return prefix;
|
|
97
|
+
}
|
|
98
|
+
if (!prefix) {
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
return value.startsWith(prefix) ? value : prefix + value;
|
|
102
|
+
};
|
|
103
|
+
var strPadBoth = (str, length, pad = " ") => {
|
|
104
|
+
if (str.length >= length) {
|
|
105
|
+
return str;
|
|
106
|
+
}
|
|
107
|
+
const totalPad = length - str.length;
|
|
108
|
+
const leftPad = Math.floor(totalPad / 2);
|
|
109
|
+
const rightPad = totalPad - leftPad;
|
|
110
|
+
return pad.repeat(leftPad) + str + pad.repeat(rightPad);
|
|
111
|
+
};
|
|
112
|
+
var strPadLeft = (str, length, pad = " ") => {
|
|
113
|
+
return str.padStart(length, pad);
|
|
114
|
+
};
|
|
115
|
+
var strPadRight = (str, length, pad = " ") => {
|
|
116
|
+
return str.padEnd(length, pad);
|
|
117
|
+
};
|
|
118
|
+
var strReverse = (value) => {
|
|
119
|
+
return value.split("").reverse().join("");
|
|
120
|
+
};
|
|
121
|
+
var strRemove = (search, subject, caseSensitive = true) => {
|
|
122
|
+
if (!search || !subject) {
|
|
123
|
+
return subject;
|
|
124
|
+
}
|
|
125
|
+
const flags = caseSensitive ? "g" : "gi";
|
|
126
|
+
return subject.replace(new RegExp(search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), flags), "");
|
|
127
|
+
};
|
|
128
|
+
var strMask = (str, character, index, length) => {
|
|
129
|
+
if (!str) {
|
|
130
|
+
return str;
|
|
131
|
+
}
|
|
132
|
+
const start = Math.max(0, index);
|
|
133
|
+
const end = length !== void 0 ? start + length : str.length;
|
|
134
|
+
return str.substring(0, start) + character.repeat(end - start) + str.substring(end);
|
|
135
|
+
};
|
|
136
|
+
var strWordCount = (str, characters) => {
|
|
137
|
+
if (!str) {
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
const pattern = characters ? new RegExp(`[${characters}\\s]+`) : /\s+/;
|
|
141
|
+
return str.trim().split(pattern).filter((word) => 0 < word.length).length;
|
|
142
|
+
};
|
|
143
|
+
var strWords = (value, words = 100, end = "...") => {
|
|
144
|
+
if (!value) {
|
|
145
|
+
return "";
|
|
146
|
+
}
|
|
147
|
+
const wordArray = value.trim().split(/\s+/);
|
|
148
|
+
if (wordArray.length <= words) {
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
return wordArray.slice(0, words).join(" ") + end;
|
|
152
|
+
};
|
|
153
|
+
var camelCase = (value) => {
|
|
154
|
+
const studly = studlyCase(value);
|
|
155
|
+
return studly.charAt(0).toLowerCase() + studly.slice(1);
|
|
156
|
+
};
|
|
157
|
+
var snakeCase = (value) => {
|
|
158
|
+
return value.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[\s-]+/g, "_").toLowerCase();
|
|
159
|
+
};
|
|
160
|
+
var kebabCase = (value) => {
|
|
161
|
+
return value.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
162
|
+
};
|
|
163
|
+
var studlyCase = (value) => {
|
|
164
|
+
return value.replace(/[_-]/g, " ").replace(/\s+(.)/g, (_, c) => c.toUpperCase()).replace(/^(.)/, (_, c) => c.toUpperCase()).replace(/\s+/g, "");
|
|
165
|
+
};
|
|
166
|
+
var titleCase = (value) => {
|
|
167
|
+
return value.replace(/\w\S*/g, (txt) => {
|
|
168
|
+
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
var numberFormat = (value, decimals = 2, locale = "en-US") => {
|
|
172
|
+
return new Intl.NumberFormat(locale, {
|
|
173
|
+
minimumFractionDigits: decimals,
|
|
174
|
+
maximumFractionDigits: decimals
|
|
175
|
+
}).format(value);
|
|
176
|
+
};
|
|
177
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
178
|
+
0 && (module.exports = {
|
|
179
|
+
camelCase,
|
|
180
|
+
capitalize,
|
|
181
|
+
kebabCase,
|
|
182
|
+
normalizeString,
|
|
183
|
+
numberFormat,
|
|
184
|
+
slugify,
|
|
185
|
+
snakeCase,
|
|
186
|
+
strContainsAll,
|
|
187
|
+
strContainsAny,
|
|
188
|
+
strFinish,
|
|
189
|
+
strLimit,
|
|
190
|
+
strMask,
|
|
191
|
+
strPadBoth,
|
|
192
|
+
strPadLeft,
|
|
193
|
+
strPadRight,
|
|
194
|
+
strRemove,
|
|
195
|
+
strReverse,
|
|
196
|
+
strStart,
|
|
197
|
+
strWordCount,
|
|
198
|
+
strWords,
|
|
199
|
+
studlyCase,
|
|
200
|
+
titleCase
|
|
201
|
+
});
|