@akanjs/common 0.0.97 → 0.0.99
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/{Logger.mjs → Logger.cjs} +35 -6
- package/Logger.js +6 -35
- package/applyMixins.cjs +42 -0
- package/applyMixins.js +3 -22
- package/capitalize.cjs +25 -0
- package/capitalize.js +3 -22
- package/deepObjectify.cjs +49 -0
- package/deepObjectify.js +7 -26
- package/index.cjs +55 -0
- package/index.js +35 -54
- package/isDayjs.cjs +23 -0
- package/isDayjs.js +3 -22
- package/isQueryEqual.cjs +59 -0
- package/isQueryEqual.js +7 -36
- package/isValidDate.cjs +45 -0
- package/isValidDate.js +9 -38
- package/lowerlize.cjs +25 -0
- package/lowerlize.js +3 -22
- package/mergeVersion.cjs +23 -0
- package/mergeVersion.js +3 -22
- package/objectify.cjs +30 -0
- package/objectify.js +3 -22
- package/package.json +4 -4
- package/pathGet.cjs +26 -0
- package/pathGet.js +3 -22
- package/pathSet.cjs +33 -0
- package/pathSet.js +3 -22
- package/pluralize.cjs +33 -0
- package/pluralize.js +3 -32
- package/randomPick.cjs +23 -0
- package/randomPick.js +3 -22
- package/randomPicks.cjs +35 -0
- package/randomPicks.js +3 -22
- package/sleep.cjs +29 -0
- package/sleep.js +3 -22
- package/splitVersion.cjs +26 -0
- package/splitVersion.js +3 -22
- package/types.cjs +15 -0
- package/types.js +0 -15
- package/applyMixins.mjs +0 -23
- package/capitalize.mjs +0 -6
- package/deepObjectify.mjs +0 -30
- package/index.mjs +0 -36
- package/isDayjs.mjs +0 -4
- package/isQueryEqual.mjs +0 -30
- package/isValidDate.mjs +0 -16
- package/lowerlize.mjs +0 -6
- package/mergeVersion.mjs +0 -4
- package/objectify.mjs +0 -11
- package/pathGet.mjs +0 -7
- package/pathSet.mjs +0 -14
- package/pluralize.mjs +0 -4
- package/randomPick.mjs +0 -4
- package/randomPicks.mjs +0 -16
- package/sleep.mjs +0 -10
- package/splitVersion.mjs +0 -7
- package/types.mjs +0 -0
package/sleep.js
CHANGED
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var sleep_exports = {};
|
|
19
|
-
__export(sleep_exports, {
|
|
20
|
-
sleep: () => sleep
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(sleep_exports);
|
|
23
1
|
const sleep = async (ms) => {
|
|
24
2
|
return new Promise((resolve) => {
|
|
25
3
|
setTimeout(() => {
|
|
@@ -27,3 +5,6 @@ const sleep = async (ms) => {
|
|
|
27
5
|
}, ms);
|
|
28
6
|
});
|
|
29
7
|
};
|
|
8
|
+
export {
|
|
9
|
+
sleep
|
|
10
|
+
};
|
package/splitVersion.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var splitVersion_exports = {};
|
|
19
|
+
__export(splitVersion_exports, {
|
|
20
|
+
splitVersion: () => splitVersion
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(splitVersion_exports);
|
|
23
|
+
const splitVersion = (version) => {
|
|
24
|
+
const [major, minor, patch] = version.split(".");
|
|
25
|
+
return { major, minor, patch };
|
|
26
|
+
};
|
package/splitVersion.js
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var splitVersion_exports = {};
|
|
19
|
-
__export(splitVersion_exports, {
|
|
20
|
-
splitVersion: () => splitVersion
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(splitVersion_exports);
|
|
23
1
|
const splitVersion = (version) => {
|
|
24
2
|
const [major, minor, patch] = version.split(".");
|
|
25
3
|
return { major, minor, patch };
|
|
26
4
|
};
|
|
5
|
+
export {
|
|
6
|
+
splitVersion
|
|
7
|
+
};
|
package/types.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(types_exports);
|
package/types.js
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
-
var types_exports = {};
|
|
15
|
-
module.exports = __toCommonJS(types_exports);
|
package/applyMixins.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const getAllPropertyDescriptors = (objRef) => {
|
|
2
|
-
const descriptors = {};
|
|
3
|
-
let current = objRef.prototype;
|
|
4
|
-
while (current) {
|
|
5
|
-
Object.getOwnPropertyNames(current).forEach((name) => {
|
|
6
|
-
descriptors[name] ??= Object.getOwnPropertyDescriptor(current, name);
|
|
7
|
-
});
|
|
8
|
-
current = Object.getPrototypeOf(current);
|
|
9
|
-
}
|
|
10
|
-
return descriptors;
|
|
11
|
-
};
|
|
12
|
-
const applyMixins = (derivedCtor, constructors, avoidKeys) => {
|
|
13
|
-
constructors.forEach((baseCtor) => {
|
|
14
|
-
Object.entries(getAllPropertyDescriptors(baseCtor)).forEach(([name, descriptor]) => {
|
|
15
|
-
if (name === "constructor" || avoidKeys?.has(name))
|
|
16
|
-
return;
|
|
17
|
-
Object.defineProperty(derivedCtor.prototype, name, { ...descriptor, configurable: true });
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
export {
|
|
22
|
-
applyMixins
|
|
23
|
-
};
|
package/capitalize.mjs
DELETED
package/deepObjectify.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { isDayjs } from "./isDayjs";
|
|
2
|
-
const deepObjectify = (obj, option = {}) => {
|
|
3
|
-
if (isDayjs(obj) || obj?.constructor === Date) {
|
|
4
|
-
if (!option.serializable && !option.convertDate)
|
|
5
|
-
return obj;
|
|
6
|
-
if (option.convertDate === "string")
|
|
7
|
-
return obj.toISOString();
|
|
8
|
-
else if (option.convertDate === "number")
|
|
9
|
-
return isDayjs(obj) ? obj.toDate().getTime() : obj.getTime();
|
|
10
|
-
else
|
|
11
|
-
return isDayjs(obj) ? obj.toDate() : obj;
|
|
12
|
-
} else if (Array.isArray(obj)) {
|
|
13
|
-
return obj.map((o) => deepObjectify(o, option));
|
|
14
|
-
} else if (obj && typeof obj === "object") {
|
|
15
|
-
const val = {};
|
|
16
|
-
Object.keys(obj).forEach((key) => {
|
|
17
|
-
const fieldValue = obj[key];
|
|
18
|
-
if (fieldValue?.__ModelType__ && !option.serializable)
|
|
19
|
-
val[key] = fieldValue;
|
|
20
|
-
else if (typeof obj[key] !== "function")
|
|
21
|
-
val[key] = deepObjectify(fieldValue, option);
|
|
22
|
-
});
|
|
23
|
-
return val;
|
|
24
|
-
} else {
|
|
25
|
-
return obj;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
export {
|
|
29
|
-
deepObjectify
|
|
30
|
-
};
|
package/index.mjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { splitVersion } from "./splitVersion";
|
|
2
|
-
import { deepObjectify } from "./deepObjectify";
|
|
3
|
-
import { pathGet } from "./pathGet";
|
|
4
|
-
import { isQueryEqual } from "./isQueryEqual";
|
|
5
|
-
import { isValidDate } from "./isValidDate";
|
|
6
|
-
import { objectify } from "./objectify";
|
|
7
|
-
import { randomPick } from "./randomPick";
|
|
8
|
-
import { randomPicks } from "./randomPicks";
|
|
9
|
-
import { pathSet } from "./pathSet";
|
|
10
|
-
import { isDayjs } from "./isDayjs";
|
|
11
|
-
import { mergeVersion } from "./mergeVersion";
|
|
12
|
-
import { pluralize } from "./pluralize";
|
|
13
|
-
import { applyMixins } from "./applyMixins";
|
|
14
|
-
import { capitalize } from "./capitalize";
|
|
15
|
-
import { Logger } from "./Logger";
|
|
16
|
-
import { lowerlize } from "./lowerlize";
|
|
17
|
-
import { sleep } from "./sleep";
|
|
18
|
-
export {
|
|
19
|
-
Logger,
|
|
20
|
-
applyMixins,
|
|
21
|
-
capitalize,
|
|
22
|
-
deepObjectify,
|
|
23
|
-
isDayjs,
|
|
24
|
-
isQueryEqual,
|
|
25
|
-
isValidDate,
|
|
26
|
-
lowerlize,
|
|
27
|
-
mergeVersion,
|
|
28
|
-
objectify,
|
|
29
|
-
pathGet,
|
|
30
|
-
pathSet,
|
|
31
|
-
pluralize,
|
|
32
|
-
randomPick,
|
|
33
|
-
randomPicks,
|
|
34
|
-
sleep,
|
|
35
|
-
splitVersion
|
|
36
|
-
};
|
package/isDayjs.mjs
DELETED
package/isQueryEqual.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
import { isDayjs } from "./isDayjs";
|
|
3
|
-
const isQueryEqual = (value1, value2) => {
|
|
4
|
-
if (value1 === value2)
|
|
5
|
-
return true;
|
|
6
|
-
if (Array.isArray(value1) && Array.isArray(value2)) {
|
|
7
|
-
if (value1.length !== value2.length)
|
|
8
|
-
return false;
|
|
9
|
-
for (let i = 0; i < value1.length; i++)
|
|
10
|
-
if (!isQueryEqual(value1[i], value2[i]))
|
|
11
|
-
return false;
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
if ([value1, value2].some((val) => val instanceof Date || isDayjs(val)))
|
|
15
|
-
return dayjs(value1).isSame(dayjs(value2));
|
|
16
|
-
if (typeof value1 === "object" && typeof value2 === "object") {
|
|
17
|
-
if (value1 === null || value2 === null)
|
|
18
|
-
return value1 === value2;
|
|
19
|
-
if (Object.keys(value1).length !== Object.keys(value2).length)
|
|
20
|
-
return false;
|
|
21
|
-
for (const key of Object.keys(value1))
|
|
22
|
-
if (!isQueryEqual(value1[key], value2[key]))
|
|
23
|
-
return false;
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
};
|
|
28
|
-
export {
|
|
29
|
-
isQueryEqual
|
|
30
|
-
};
|
package/isValidDate.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
3
|
-
import { isDayjs } from "./isDayjs";
|
|
4
|
-
dayjs.extend(customParseFormat);
|
|
5
|
-
const isValidDate = (d) => {
|
|
6
|
-
const format = "YYYY-MM-DD";
|
|
7
|
-
if (typeof d === "string") {
|
|
8
|
-
return dayjs(d, format).isValid();
|
|
9
|
-
} else if (isDayjs(d))
|
|
10
|
-
return d.isValid();
|
|
11
|
-
else
|
|
12
|
-
return d instanceof Date && !isNaN(d.getTime());
|
|
13
|
-
};
|
|
14
|
-
export {
|
|
15
|
-
isValidDate
|
|
16
|
-
};
|
package/lowerlize.mjs
DELETED
package/mergeVersion.mjs
DELETED
package/objectify.mjs
DELETED
package/pathGet.mjs
DELETED
package/pathSet.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const pathSet = (obj, path, value) => {
|
|
2
|
-
if (Object(obj) !== obj)
|
|
3
|
-
return obj;
|
|
4
|
-
if (!Array.isArray(path))
|
|
5
|
-
path = path.toString().match(/[^.[\]]+/g) || [];
|
|
6
|
-
path.slice(0, -1).reduce(
|
|
7
|
-
(a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(path[i + 1]) >> 0 === +path[i + 1] ? [] : {},
|
|
8
|
-
obj
|
|
9
|
-
)[path[path.length - 1]] = value;
|
|
10
|
-
return obj;
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
pathSet
|
|
14
|
-
};
|
package/pluralize.mjs
DELETED
package/randomPick.mjs
DELETED
package/randomPicks.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const randomPicks = (arr, count = 1, allowDuplicate = false) => {
|
|
2
|
-
if (!allowDuplicate && arr.length <= count)
|
|
3
|
-
return arr;
|
|
4
|
-
const idxs = [];
|
|
5
|
-
let pickIdx;
|
|
6
|
-
for (let i = 0; i < count; i++) {
|
|
7
|
-
do {
|
|
8
|
-
pickIdx = Math.floor(Math.random() * arr.length);
|
|
9
|
-
} while (!allowDuplicate && idxs.includes(pickIdx));
|
|
10
|
-
idxs.push(pickIdx);
|
|
11
|
-
}
|
|
12
|
-
return idxs.map((idx) => arr[idx]);
|
|
13
|
-
};
|
|
14
|
-
export {
|
|
15
|
-
randomPicks
|
|
16
|
-
};
|
package/sleep.mjs
DELETED
package/splitVersion.mjs
DELETED
package/types.mjs
DELETED
|
File without changes
|