ag-common 0.0.319 → 0.0.320
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/common/helpers/date.d.ts +15 -1
- package/dist/common/helpers/date.js +19 -8
- package/dist/common/helpers/string.d.ts +1 -0
- package/dist/common/helpers/string.js +12 -1
- package/dist/ui/helpers/date.d.ts +7 -1
- package/dist/ui/helpers/date.js +17 -16
- package/dist/ui/helpers/useLocalStorage.js +3 -3
- package/package.json +1 -1
|
@@ -3,7 +3,21 @@ export declare const addHours: (d: number, h: number) => Date;
|
|
|
3
3
|
export declare const addDays: (dIn: Date, count: number) => Date;
|
|
4
4
|
export declare const addMinutes: (date: Date, minutes: number) => Date;
|
|
5
5
|
export declare const lastDayInMonth: (date: Date) => Date;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* breaks ticks into time diffs
|
|
8
|
+
* @param lowDate
|
|
9
|
+
* @param highDate defaults to Date.Now
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const dateDiff: (lowDate: Date, highDate?: Date) => {
|
|
13
|
+
totalMinutes: number;
|
|
14
|
+
totalHours: number;
|
|
15
|
+
totalDays: number;
|
|
16
|
+
totalYears: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* convert csharp datetime to js datetime
|
|
20
|
+
*/
|
|
7
21
|
export declare const CSharpToJs: (charpTicks: number) => Date;
|
|
8
22
|
/**
|
|
9
23
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dateTimeToNearestMinute = exports.CSharpToJs = exports.
|
|
3
|
+
exports.dateTimeToNearestMinute = exports.CSharpToJs = exports.dateDiff = exports.lastDayInMonth = exports.addMinutes = exports.addDays = exports.addHours = exports.getTimeSeconds = void 0;
|
|
4
|
+
const math_1 = require("./math");
|
|
4
5
|
const getTimeSeconds = () => Math.ceil(new Date().getTime() / 1000);
|
|
5
6
|
exports.getTimeSeconds = getTimeSeconds;
|
|
6
7
|
const addHours = (d, h) => {
|
|
@@ -17,14 +18,24 @@ const addMinutes = (date, minutes) => new Date(date.getTime() + minutes * 60000)
|
|
|
17
18
|
exports.addMinutes = addMinutes;
|
|
18
19
|
const lastDayInMonth = (date) => new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
19
20
|
exports.lastDayInMonth = lastDayInMonth;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
/**
|
|
22
|
+
* breaks ticks into time diffs
|
|
23
|
+
* @param lowDate
|
|
24
|
+
* @param highDate defaults to Date.Now
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
const dateDiff = (lowDate, highDate) => {
|
|
28
|
+
const ticksSince = (highDate !== null && highDate !== void 0 ? highDate : new Date()).getTime() - lowDate.getTime();
|
|
29
|
+
const totalMinutes = (0, math_1.toFixedDown)(ticksSince / 1000 / 60, 0);
|
|
30
|
+
const totalHours = (0, math_1.toFixedDown)(totalMinutes / 60, 0);
|
|
31
|
+
const totalDays = (0, math_1.toFixedDown)(totalHours / 24, 0);
|
|
32
|
+
const totalYears = (0, math_1.toFixedDown)(totalDays / 365, 0);
|
|
33
|
+
return { totalMinutes, totalHours, totalDays, totalYears };
|
|
26
34
|
};
|
|
27
|
-
exports.
|
|
35
|
+
exports.dateDiff = dateDiff;
|
|
36
|
+
/**
|
|
37
|
+
* convert csharp datetime to js datetime
|
|
38
|
+
*/
|
|
28
39
|
const CSharpToJs = (charpTicks) => {
|
|
29
40
|
// ticks are in nanotime; convert to microtime
|
|
30
41
|
const ticks = charpTicks / 10000;
|
|
@@ -61,3 +61,4 @@ export declare const chunkString: (str: string, length: number) => string[];
|
|
|
61
61
|
*/
|
|
62
62
|
export declare function stringToObject(raw: string, splitKeyValue: string, splitKeys: string): Record<string, string>;
|
|
63
63
|
export declare const indexOfNumber: (str: string, char: string, num?: number) => number | undefined;
|
|
64
|
+
export declare function isValidUrl(raw: string): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.indexOfNumber = exports.stringToObject = exports.chunkString = exports.safeStringify = exports.containsInsensitive = exports.containsInsensitiveIndex = exports.replaceRemove = exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = exports.fromBase64 = exports.toBase64 = void 0;
|
|
3
|
+
exports.isValidUrl = exports.indexOfNumber = exports.stringToObject = exports.chunkString = exports.safeStringify = exports.containsInsensitive = exports.containsInsensitiveIndex = exports.replaceRemove = exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = exports.fromBase64 = exports.toBase64 = void 0;
|
|
4
4
|
const toBase64 = (str) => Buffer.from(str).toString('base64');
|
|
5
5
|
exports.toBase64 = toBase64;
|
|
6
6
|
const fromBase64 = (str) => Buffer.from(decodeURIComponent(str), 'base64').toString();
|
|
@@ -197,3 +197,14 @@ const indexOfNumber = (str, char, num = 0) => {
|
|
|
197
197
|
return ret;
|
|
198
198
|
};
|
|
199
199
|
exports.indexOfNumber = indexOfNumber;
|
|
200
|
+
function isValidUrl(raw) {
|
|
201
|
+
let url;
|
|
202
|
+
try {
|
|
203
|
+
url = new URL(raw);
|
|
204
|
+
}
|
|
205
|
+
catch (_) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
209
|
+
}
|
|
210
|
+
exports.isValidUrl = isValidUrl;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* returns appropriate time diff string
|
|
3
|
+
* @param lowDate
|
|
4
|
+
* @param highDate defaults to Date.Now
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare const dateDiffToString: (lowDate: Date, highDate?: Date) => string;
|
|
2
8
|
export declare const getDMY: (date: Date, dayOffset?: number) => string;
|
package/dist/ui/helpers/date.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDMY = exports.
|
|
3
|
+
exports.getDMY = exports.dateDiffToString = void 0;
|
|
4
4
|
const plural_1 = require("./plural");
|
|
5
5
|
const date_1 = require("../../common/helpers/date");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
/**
|
|
7
|
+
* returns appropriate time diff string
|
|
8
|
+
* @param lowDate
|
|
9
|
+
* @param highDate defaults to Date.Now
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
const dateDiffToString = (lowDate, highDate) => {
|
|
13
|
+
const d = (0, date_1.dateDiff)(lowDate, highDate !== null && highDate !== void 0 ? highDate : new Date());
|
|
14
|
+
let ts = `${d.totalYears} ${(0, plural_1.plural)('yr', d.totalYears)} ago `;
|
|
15
|
+
if (d.totalMinutes < 60) {
|
|
16
|
+
ts = `${d.totalMinutes} ${(0, plural_1.plural)('min', d.totalMinutes)} ago `;
|
|
16
17
|
}
|
|
17
|
-
else if (totalHours < 24) {
|
|
18
|
-
ts = `${totalHours} ${(0, plural_1.plural)('hr', totalHours)} ago `;
|
|
18
|
+
else if (d.totalHours < 24) {
|
|
19
|
+
ts = `${d.totalHours} ${(0, plural_1.plural)('hr', d.totalHours)} ago `;
|
|
19
20
|
}
|
|
20
|
-
else if (totalDays < 365) {
|
|
21
|
-
ts = `${totalDays} ${(0, plural_1.plural)('day', totalDays)} ago `;
|
|
21
|
+
else if (d.totalDays < 365) {
|
|
22
|
+
ts = `${d.totalDays} ${(0, plural_1.plural)('day', d.totalDays)} ago `;
|
|
22
23
|
}
|
|
23
24
|
return ts;
|
|
24
25
|
};
|
|
25
|
-
exports.
|
|
26
|
+
exports.dateDiffToString = dateDiffToString;
|
|
26
27
|
const getDMY = (date, dayOffset) => {
|
|
27
28
|
const date1 = (0, date_1.addDays)(date, dayOffset || 0);
|
|
28
29
|
const d = String(date1.getDate()).padStart(2, '0');
|
|
@@ -4,7 +4,7 @@ exports.UseLocalStorage = exports.getLocalStorageItem = exports.setLocalStorageI
|
|
|
4
4
|
const log_1 = require("../../common/helpers/log");
|
|
5
5
|
const object_1 = require("../../common/helpers/object");
|
|
6
6
|
const react_1 = require("react");
|
|
7
|
-
const
|
|
7
|
+
const date_1 = require("../../common/helpers/date");
|
|
8
8
|
const clearLocalStorageItem = (key) => {
|
|
9
9
|
if (typeof window === 'undefined') {
|
|
10
10
|
return;
|
|
@@ -41,7 +41,7 @@ const setLocalStorageItem = (key, value, ttl) => {
|
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
const set = {
|
|
44
|
-
expiry: !ttl ? undefined : getTimeSeconds() + ttl,
|
|
44
|
+
expiry: !ttl ? undefined : (0, date_1.getTimeSeconds)() + ttl,
|
|
45
45
|
val: JSON.stringify(value),
|
|
46
46
|
};
|
|
47
47
|
window.localStorage.setItem(key, JSON.stringify(set));
|
|
@@ -58,7 +58,7 @@ const getLocalStorageItem = (key, initialValue, ttl) => {
|
|
|
58
58
|
}
|
|
59
59
|
const itemraw = window.localStorage.getItem(key);
|
|
60
60
|
const item = (0, object_1.tryJsonParse)(itemraw, undefined);
|
|
61
|
-
if (!item || (item.expiry && getTimeSeconds() > item.expiry)) {
|
|
61
|
+
if (!item || (item.expiry && (0, date_1.getTimeSeconds)() > item.expiry)) {
|
|
62
62
|
(0, exports.setLocalStorageItem)(key, initialValue, ttl);
|
|
63
63
|
return initialValue;
|
|
64
64
|
}
|