diginext-utils 2.0.22 → 2.0.23
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/math/diffDate.d.ts +1 -0
- package/dist/math/diffDate.js +1 -0
- package/dist/math/diffDate.js.map +1 -1
- package/dist/math/index.d.ts +7 -45
- package/dist/math/index.js +45 -51
- package/dist/math/index.js.map +1 -1
- package/dist/math/positiveNumber.d.ts +1 -0
- package/dist/math/positiveNumber.js +1 -0
- package/dist/math/positiveNumber.js.map +1 -1
- package/dist/object.d.ts +0 -13
- package/dist/object.js +1 -15
- package/dist/object.js.map +1 -1
- package/dist/permission/requestCamera.d.ts +2 -2
- package/dist/permission/requestCamera.js +1 -0
- package/dist/permission/requestCamera.js.map +1 -1
- package/dist/permission/requestDeviceOrientationControl.d.ts +2 -2
- package/dist/permission/requestDeviceOrientationControl.js +1 -0
- package/dist/permission/requestDeviceOrientationControl.js.map +1 -1
- package/dist/string/formatNumber.d.ts +1 -0
- package/dist/string/formatNumber.js +1 -0
- package/dist/string/formatNumber.js.map +1 -1
- package/dist/string/generatePassword.d.ts +1 -0
- package/dist/string/generatePassword.js +1 -0
- package/dist/string/generatePassword.js.map +1 -1
- package/dist/string/generateUUID.d.ts +1 -0
- package/dist/string/generateUUID.js +1 -0
- package/dist/string/generateUUID.js.map +1 -1
- package/dist/string/index.d.ts +0 -2
- package/dist/string/index.js +0 -2
- package/dist/string/index.js.map +1 -1
- package/dist/string/trimNull.d.ts +1 -0
- package/dist/string/trimNull.js +1 -0
- package/dist/string/trimNull.js.map +1 -1
- package/esm/math/diffDate.d.ts +1 -0
- package/esm/math/diffDate.js +1 -0
- package/esm/math/diffDate.js.map +1 -1
- package/esm/math/index.d.ts +7 -45
- package/esm/math/index.js +40 -50
- package/esm/math/index.js.map +1 -1
- package/esm/math/positiveNumber.d.ts +1 -0
- package/esm/math/positiveNumber.js +1 -0
- package/esm/math/positiveNumber.js.map +1 -1
- package/esm/object.d.ts +0 -13
- package/esm/object.js +0 -13
- package/esm/object.js.map +1 -1
- package/esm/permission/requestCamera.d.ts +2 -2
- package/esm/permission/requestCamera.js +2 -2
- package/esm/permission/requestCamera.js.map +1 -1
- package/esm/permission/requestDeviceOrientationControl.d.ts +2 -2
- package/esm/permission/requestDeviceOrientationControl.js +2 -2
- package/esm/permission/requestDeviceOrientationControl.js.map +1 -1
- package/esm/string/formatNumber.d.ts +1 -0
- package/esm/string/formatNumber.js +1 -0
- package/esm/string/formatNumber.js.map +1 -1
- package/esm/string/generatePassword.d.ts +1 -0
- package/esm/string/generatePassword.js +1 -0
- package/esm/string/generatePassword.js.map +1 -1
- package/esm/string/generateUUID.d.ts +1 -0
- package/esm/string/generateUUID.js +1 -0
- package/esm/string/generateUUID.js.map +1 -1
- package/esm/string/index.d.ts +0 -2
- package/esm/string/index.js +0 -2
- package/esm/string/index.js.map +1 -1
- package/esm/string/trimNull.d.ts +1 -0
- package/esm/string/trimNull.js +1 -0
- package/esm/string/trimNull.js.map +1 -1
- package/package.json +1 -1
- package/src/math/diffDate.ts +2 -0
- package/src/math/index.ts +45 -50
- package/src/math/positiveNumber.ts +2 -0
- package/src/object.ts +0 -13
- package/src/permission/requestCamera.ts +2 -2
- package/src/permission/requestDeviceOrientationControl.ts +2 -2
- package/src/string/formatNumber.ts +2 -0
- package/src/string/generatePassword.ts +2 -0
- package/src/string/generateUUID.ts +2 -0
- package/src/string/index.ts +0 -2
- package/src/string/trimNull.ts +2 -0
- package/dist/string/makeDaySlug.d.ts +0 -31
- package/dist/string/makeDaySlug.js +0 -23
- package/dist/string/makeDaySlug.js.map +0 -1
- package/esm/string/makeDaySlug.d.ts +0 -31
- package/esm/string/makeDaySlug.js +0 -16
- package/esm/string/makeDaySlug.js.map +0 -1
- package/src/string/makeDaySlug.ts +0 -40
package/src/math/index.ts
CHANGED
|
@@ -1,29 +1,14 @@
|
|
|
1
1
|
const DEG2RAD = Math.PI / 180;
|
|
2
2
|
const RAD2DEG = 180 / Math.PI;
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {Number} number
|
|
7
|
-
* @return {Number}
|
|
8
|
-
*/
|
|
9
4
|
export const randRound = (number: number) => {
|
|
10
5
|
return Math.round(Math.random() * number);
|
|
11
6
|
};
|
|
12
7
|
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @param {Number} number
|
|
16
|
-
* @return {Number}
|
|
17
|
-
*/
|
|
18
8
|
export const rand = (number: number) => {
|
|
19
9
|
return (Math.random() - Math.random()) * number;
|
|
20
10
|
};
|
|
21
11
|
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @param {Number} number
|
|
25
|
-
* @return {Number}
|
|
26
|
-
*/
|
|
27
12
|
export const randHalt = (number: number) => {
|
|
28
13
|
var rand = Math.random() - Math.random();
|
|
29
14
|
var res;
|
|
@@ -34,62 +19,72 @@ export const randHalt = (number: number) => {
|
|
|
34
19
|
}
|
|
35
20
|
return Math.abs(res);
|
|
36
21
|
};
|
|
37
|
-
|
|
38
|
-
*
|
|
39
|
-
* @param {Number} low
|
|
40
|
-
* @param {Number} high
|
|
41
|
-
* @return {Number}
|
|
42
|
-
*/
|
|
22
|
+
|
|
43
23
|
export const randInt = (low: number, high: number) => {
|
|
44
24
|
return low + Math.floor(Math.random() * (high - low + 1));
|
|
45
25
|
};
|
|
46
26
|
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @param {Number} low
|
|
50
|
-
* @param {Number} high
|
|
51
|
-
* @return {Number}
|
|
52
|
-
*/
|
|
53
27
|
export const randFloat = (low: number, high: number) => {
|
|
54
28
|
return low + Math.random() * (high - low);
|
|
55
29
|
};
|
|
56
|
-
|
|
57
|
-
*
|
|
58
|
-
* @param {Number} degrees
|
|
59
|
-
* @return {Number}
|
|
60
|
-
*/
|
|
30
|
+
|
|
61
31
|
export const degToRad = (degrees: number) => {
|
|
62
32
|
return degrees * DEG2RAD;
|
|
63
33
|
};
|
|
64
34
|
|
|
65
|
-
/**
|
|
66
|
-
*
|
|
67
|
-
* @param {Number} degrees
|
|
68
|
-
* @return {Number}
|
|
69
|
-
*/
|
|
70
35
|
export const radToDeg = (radians: number) => {
|
|
71
36
|
return radians * RAD2DEG;
|
|
72
37
|
};
|
|
73
38
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
39
|
+
export const clamp = (value: number, min: number, max: number) => {
|
|
40
|
+
const result = Math.max(min, Math.min(max, value));
|
|
41
|
+
return Number.isFinite(result) ? result : 0;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const degBetweenPoints360 = (cx: number, cy: number, ex: number, ey: number) => {
|
|
45
|
+
let theta = degBetweenPoints(cx, cy, ex, ey); // range (-180, 180]
|
|
46
|
+
if (theta < 0) theta = 360 + theta; // range [0, 360)
|
|
47
|
+
return Number.isFinite(theta) ? theta : 0;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const degBetweenPoints = (cx: number, cy: number, ex: number, ey: number) => {
|
|
51
|
+
const dy = ey - cy;
|
|
52
|
+
const dx = ex - cx;
|
|
53
|
+
let theta = Math.atan2(dy, dx); // range (-PI, PI]
|
|
54
|
+
theta *= 180 / Math.PI; // rads to degs, range (-180, 180]
|
|
55
|
+
return Number.isFinite(theta) ? theta : 0;
|
|
56
|
+
};
|
|
57
|
+
|
|
82
58
|
export const angleBetweenPoints = (cx: number, cy: number, ex: number, ey: number) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
59
|
+
const dy = ey - cy;
|
|
60
|
+
const dx = ex - cx;
|
|
61
|
+
let theta = Math.atan2(dy, dx); // range (-PI, PI]
|
|
86
62
|
theta *= 180 / Math.PI; // rads to degs, range (-180, 180]
|
|
87
|
-
return theta;
|
|
63
|
+
return Number.isFinite(theta) ? theta : 0;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const distance2Point = (x1: number, y1: number, x2: number, y2: number) => {
|
|
67
|
+
const dist = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
|
|
68
|
+
return Number.isFinite(dist) ? dist : 0;
|
|
88
69
|
};
|
|
89
70
|
|
|
90
71
|
import { diffDate } from "./diffDate";
|
|
91
72
|
import { positiveNumber } from "./positiveNumber";
|
|
92
73
|
|
|
93
|
-
const xmath = {
|
|
74
|
+
const xmath = {
|
|
75
|
+
rand,
|
|
76
|
+
randRound,
|
|
77
|
+
randHalt,
|
|
78
|
+
randInt,
|
|
79
|
+
randFloat,
|
|
80
|
+
degToRad,
|
|
81
|
+
radToDeg,
|
|
82
|
+
degBetweenPoints360,
|
|
83
|
+
degBetweenPoints,
|
|
84
|
+
angleBetweenPoints,
|
|
85
|
+
distance2Point,
|
|
86
|
+
diffDate,
|
|
87
|
+
positiveNumber,
|
|
88
|
+
};
|
|
94
89
|
|
|
95
90
|
export default xmath;
|
package/src/object.ts
CHANGED
|
@@ -48,18 +48,6 @@ export const objectToArray = (obj: { [key: string]: any }) => {
|
|
|
48
48
|
return array;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
/**
|
|
52
|
-
* Iterate through every keys & values of the object
|
|
53
|
-
*/
|
|
54
|
-
export const iterate = (obj: { [key: string]: any }, callbackFn: (obj: any, key?: string, value?: any) => any) => {
|
|
55
|
-
Object.keys(obj).forEach((key) => {
|
|
56
|
-
const val = obj[key];
|
|
57
|
-
callbackFn(obj, key, val);
|
|
58
|
-
if (typeof val === "object" && val !== null) iterate(val, callbackFn);
|
|
59
|
-
});
|
|
60
|
-
return obj;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
51
|
const xobject = {
|
|
64
52
|
isNull,
|
|
65
53
|
toBool,
|
|
@@ -67,6 +55,5 @@ const xobject = {
|
|
|
67
55
|
toFloat,
|
|
68
56
|
toArray,
|
|
69
57
|
objectToArray,
|
|
70
|
-
iterate,
|
|
71
58
|
};
|
|
72
59
|
export default xobject;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const requestCamera = ({ audio = true, video = true }) => {
|
|
1
|
+
export const requestCamera = ({ audio = true, video = true }) => {
|
|
2
2
|
if (typeof window == "undefined") return false;
|
|
3
3
|
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
@@ -40,4 +40,4 @@ const requestCamera = ({ audio = true, video = true }) => {
|
|
|
40
40
|
});
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
export
|
|
43
|
+
export default requestCamera;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isAndroid } from "../device";
|
|
2
2
|
|
|
3
|
-
const requestDeviceOrientationControl = () => {
|
|
3
|
+
export const requestDeviceOrientationControl = () => {
|
|
4
4
|
if (typeof window == "undefined") return false;
|
|
5
5
|
return new Promise((resolve, reject) => {
|
|
6
6
|
if (isAndroid()) resolve(true);
|
|
@@ -30,4 +30,4 @@ const requestDeviceOrientationControl = () => {
|
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
export
|
|
33
|
+
export default requestDeviceOrientationControl;
|
|
@@ -8,3 +8,5 @@ export function formatNumber(num: number, prefix = "$") {
|
|
|
8
8
|
const numRound = Math.round((toInt(num) + Number.EPSILON) * 100) / 100;
|
|
9
9
|
return Number.isNaN(numRound) ? "0" : "" + numRound.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, prefix + "1,");
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
export default formatNumber;
|
package/src/string/index.ts
CHANGED
|
@@ -144,7 +144,6 @@ export const clearUnicodeCharacters = (s: string, opt: { [key: string]: any } =
|
|
|
144
144
|
return opt.lowercase ? s.toLowerCase() : s;
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
import { makeDaySlug } from "./makeDaySlug";
|
|
148
147
|
import { generateUUID } from "./generateUUID";
|
|
149
148
|
import { randAllCharacterByLength, randomStringByLength } from "./random";
|
|
150
149
|
import { formatNumber } from "./formatNumber";
|
|
@@ -155,7 +154,6 @@ import { addQueryParam, getUrlParams, isLink, getFileNameWithoutExtension, getFi
|
|
|
155
154
|
const xstring = {
|
|
156
155
|
getBetween,
|
|
157
156
|
makeString,
|
|
158
|
-
makeDaySlug,
|
|
159
157
|
toUpperCase,
|
|
160
158
|
toLowerCase,
|
|
161
159
|
titleize,
|
package/src/string/trimNull.ts
CHANGED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
declare type DaySlugOptions = {
|
|
2
|
-
/**
|
|
3
|
-
* @default ""
|
|
4
|
-
*/
|
|
5
|
-
prefix?: string;
|
|
6
|
-
/**
|
|
7
|
-
* @default ""
|
|
8
|
-
*/
|
|
9
|
-
surfix?: string;
|
|
10
|
-
/**
|
|
11
|
-
* @default true
|
|
12
|
-
*/
|
|
13
|
-
useDate?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* @default true
|
|
16
|
-
*/
|
|
17
|
-
useTime?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* @default "-"
|
|
20
|
-
*/
|
|
21
|
-
divider?: string;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Format the input number with commas
|
|
25
|
-
* @example 1000000 -> 1,000,000
|
|
26
|
-
*/
|
|
27
|
-
export declare function makeDaySlug(options?: DaySlugOptions): string;
|
|
28
|
-
declare const _default: {
|
|
29
|
-
makeDaySlug: typeof makeDaySlug;
|
|
30
|
-
};
|
|
31
|
-
export default _default;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.makeDaySlug = void 0;
|
|
7
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
-
/**
|
|
9
|
-
* Format the input number with commas
|
|
10
|
-
* @example 1000000 -> 1,000,000
|
|
11
|
-
*/
|
|
12
|
-
function makeDaySlug(options = {}) {
|
|
13
|
-
const { prefix = "", surfix = "", divider = "-", useDate = true, useTime = true } = options;
|
|
14
|
-
let mainStr = "";
|
|
15
|
-
if (useDate)
|
|
16
|
-
mainStr += (0, dayjs_1.default)().format(`YYYY${divider}MM${divider}DD`);
|
|
17
|
-
if (useTime)
|
|
18
|
-
mainStr += (mainStr == "" ? "" : divider) + (0, dayjs_1.default)().format(`HH${divider}mm${divider}ss`);
|
|
19
|
-
return prefix + (prefix ? divider : "") + mainStr + (surfix ? divider : "") + surfix;
|
|
20
|
-
}
|
|
21
|
-
exports.makeDaySlug = makeDaySlug;
|
|
22
|
-
exports.default = { makeDaySlug };
|
|
23
|
-
//# sourceMappingURL=makeDaySlug.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"makeDaySlug.js","sourceRoot":"","sources":["../../src/string/makeDaySlug.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAyB1B;;;GAGG;AACH,SAAgB,WAAW,CAAC,UAA0B,EAAE;IACvD,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE,OAAO,GAAG,GAAG,EAAE,OAAO,GAAG,IAAI,EAAE,OAAO,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAE5F,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,OAAO;QAAE,OAAO,IAAI,IAAA,eAAK,GAAE,CAAC,MAAM,CAAC,OAAO,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC;IACvE,IAAI,OAAO;QAAE,OAAO,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,IAAA,eAAK,GAAE,CAAC,MAAM,CAAC,KAAK,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC;IAEtG,OAAO,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;AACtF,CAAC;AARD,kCAQC;AAED,kBAAe,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
declare type DaySlugOptions = {
|
|
2
|
-
/**
|
|
3
|
-
* @default ""
|
|
4
|
-
*/
|
|
5
|
-
prefix?: string;
|
|
6
|
-
/**
|
|
7
|
-
* @default ""
|
|
8
|
-
*/
|
|
9
|
-
surfix?: string;
|
|
10
|
-
/**
|
|
11
|
-
* @default true
|
|
12
|
-
*/
|
|
13
|
-
useDate?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* @default true
|
|
16
|
-
*/
|
|
17
|
-
useTime?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* @default "-"
|
|
20
|
-
*/
|
|
21
|
-
divider?: string;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Format the input number with commas
|
|
25
|
-
* @example 1000000 -> 1,000,000
|
|
26
|
-
*/
|
|
27
|
-
export declare function makeDaySlug(options?: DaySlugOptions): string;
|
|
28
|
-
declare const _default: {
|
|
29
|
-
makeDaySlug: typeof makeDaySlug;
|
|
30
|
-
};
|
|
31
|
-
export default _default;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
/**
|
|
3
|
-
* Format the input number with commas
|
|
4
|
-
* @example 1000000 -> 1,000,000
|
|
5
|
-
*/
|
|
6
|
-
export function makeDaySlug(options = {}) {
|
|
7
|
-
const { prefix = "", surfix = "", divider = "-", useDate = true, useTime = true } = options;
|
|
8
|
-
let mainStr = "";
|
|
9
|
-
if (useDate)
|
|
10
|
-
mainStr += dayjs().format(`YYYY${divider}MM${divider}DD`);
|
|
11
|
-
if (useTime)
|
|
12
|
-
mainStr += (mainStr == "" ? "" : divider) + dayjs().format(`HH${divider}mm${divider}ss`);
|
|
13
|
-
return prefix + (prefix ? divider : "") + mainStr + (surfix ? divider : "") + surfix;
|
|
14
|
-
}
|
|
15
|
-
export default { makeDaySlug };
|
|
16
|
-
//# sourceMappingURL=makeDaySlug.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"makeDaySlug.js","sourceRoot":"","sources":["../../src/string/makeDaySlug.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAyB1B;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,UAA0B,EAAE;IACvD,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE,OAAO,GAAG,GAAG,EAAE,OAAO,GAAG,IAAI,EAAE,OAAO,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAE5F,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,OAAO;QAAE,OAAO,IAAI,KAAK,EAAE,CAAC,MAAM,CAAC,OAAO,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC;IACvE,IAAI,OAAO;QAAE,OAAO,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,KAAK,EAAE,CAAC,MAAM,CAAC,KAAK,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC;IAEtG,OAAO,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;AACtF,CAAC;AAED,eAAe,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
|
|
3
|
-
type DaySlugOptions = {
|
|
4
|
-
/**
|
|
5
|
-
* @default ""
|
|
6
|
-
*/
|
|
7
|
-
prefix?: string;
|
|
8
|
-
/**
|
|
9
|
-
* @default ""
|
|
10
|
-
*/
|
|
11
|
-
surfix?: string;
|
|
12
|
-
/**
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
useDate?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* @default true
|
|
18
|
-
*/
|
|
19
|
-
useTime?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* @default "-"
|
|
22
|
-
*/
|
|
23
|
-
divider?: string;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Format the input number with commas
|
|
28
|
-
* @example 1000000 -> 1,000,000
|
|
29
|
-
*/
|
|
30
|
-
export function makeDaySlug(options: DaySlugOptions = {}) {
|
|
31
|
-
const { prefix = "", surfix = "", divider = "-", useDate = true, useTime = true } = options;
|
|
32
|
-
|
|
33
|
-
let mainStr = "";
|
|
34
|
-
if (useDate) mainStr += dayjs().format(`YYYY${divider}MM${divider}DD`);
|
|
35
|
-
if (useTime) mainStr += (mainStr == "" ? "" : divider) + dayjs().format(`HH${divider}mm${divider}ss`);
|
|
36
|
-
|
|
37
|
-
return prefix + (prefix ? divider : "") + mainStr + (surfix ? divider : "") + surfix;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export default { makeDaySlug };
|