@naturalcycles/js-lib 14.219.2 → 14.221.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/datetime/localTime.d.ts +5 -0
- package/dist/datetime/localTime.js +9 -1
- package/dist/decorators/memo.util.d.ts +10 -3
- package/dist/object/object.util.js +1 -1
- package/dist-esm/datetime/localTime.js +7 -0
- package/dist-esm/object/object.util.js +1 -1
- package/package.json +1 -1
- package/src/datetime/localTime.ts +8 -0
- package/src/decorators/memo.util.ts +11 -3
- package/src/object/object.util.ts +1 -1
|
@@ -176,3 +176,8 @@ export declare function localTimeOrUndefined(d?: LocalTimeInput | null): LocalTi
|
|
|
176
176
|
* Creates a LocalTime from the input, unless it's falsy - then returns LocalTime.now
|
|
177
177
|
*/
|
|
178
178
|
export declare function localTimeOrNow(d?: LocalTimeInput | null): LocalTime;
|
|
179
|
+
/**
|
|
180
|
+
Convenience function to return current Unix timestamp in seconds.
|
|
181
|
+
Like Date.now(), but in seconds.
|
|
182
|
+
*/
|
|
183
|
+
export declare function nowUnix(): UnixTimestampNumber;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.localTimeOrNow = exports.localTimeOrUndefined = exports.localTimeNow = exports.localTime = exports.LocalTime = exports.ISODayOfWeek = void 0;
|
|
3
|
+
exports.nowUnix = exports.localTimeOrNow = exports.localTimeOrUndefined = exports.localTimeNow = exports.localTime = exports.LocalTime = exports.ISODayOfWeek = void 0;
|
|
4
4
|
const assert_1 = require("../error/assert");
|
|
5
5
|
const time_util_1 = require("../time/time.util");
|
|
6
6
|
const localDate_1 = require("./localDate");
|
|
@@ -569,6 +569,14 @@ function localTimeOrNow(d) {
|
|
|
569
569
|
return d ? LocalTime.of(d) : LocalTime.now();
|
|
570
570
|
}
|
|
571
571
|
exports.localTimeOrNow = localTimeOrNow;
|
|
572
|
+
/**
|
|
573
|
+
Convenience function to return current Unix timestamp in seconds.
|
|
574
|
+
Like Date.now(), but in seconds.
|
|
575
|
+
*/
|
|
576
|
+
function nowUnix() {
|
|
577
|
+
return Math.floor(Date.now() / 1000);
|
|
578
|
+
}
|
|
579
|
+
exports.nowUnix = nowUnix;
|
|
572
580
|
// based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
|
|
573
581
|
function getWeek(date) {
|
|
574
582
|
const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime();
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import { MISS } from '..';
|
|
1
|
+
import { MISS, UnixTimestampNumber } from '..';
|
|
2
2
|
export type MemoSerializer = (args: any[]) => any;
|
|
3
3
|
export declare const jsonMemoSerializer: MemoSerializer;
|
|
4
|
+
export interface MemoCacheOptions {
|
|
5
|
+
/**
|
|
6
|
+
* If set (and if it's implemented by the driver) - will set expiry TTL for each key of the batch.
|
|
7
|
+
* E.g EXAT in Redis.
|
|
8
|
+
*/
|
|
9
|
+
expireAt?: UnixTimestampNumber;
|
|
10
|
+
}
|
|
4
11
|
export interface MemoCache<KEY = any, VALUE = any> {
|
|
5
12
|
has: (k: KEY) => boolean;
|
|
6
13
|
/**
|
|
@@ -10,7 +17,7 @@ export interface MemoCache<KEY = any, VALUE = any> {
|
|
|
10
17
|
* Cache misses are checked by calling `has` method instead.
|
|
11
18
|
*/
|
|
12
19
|
get: (k: KEY) => VALUE;
|
|
13
|
-
set: (k: KEY, v: VALUE) => void;
|
|
20
|
+
set: (k: KEY, v: VALUE, opt?: MemoCacheOptions) => void;
|
|
14
21
|
/**
|
|
15
22
|
* Clear is only called when `_getMemoCache().clear()` is called.
|
|
16
23
|
* Otherwise the Cache is "persistent" (never cleared).
|
|
@@ -24,7 +31,7 @@ export interface AsyncMemoCache<KEY = any, VALUE = any> {
|
|
|
24
31
|
* they will not be interpreted as a cache miss, because there is a special MISS symbol for that.
|
|
25
32
|
*/
|
|
26
33
|
get: (k: KEY) => Promise<VALUE | typeof MISS>;
|
|
27
|
-
set: (k: KEY, v: VALUE) => Promise<void>;
|
|
34
|
+
set: (k: KEY, v: VALUE, opt?: MemoCacheOptions) => Promise<void>;
|
|
28
35
|
/**
|
|
29
36
|
* Clear is only called when `_getAsyncMemo().clear()` is called.
|
|
30
37
|
* Otherwise the Cache is "persistent" (never cleared).
|
|
@@ -263,7 +263,7 @@ function _unset(obj, prop) {
|
|
|
263
263
|
last = segs.pop().slice(0, -1) + '.' + last;
|
|
264
264
|
}
|
|
265
265
|
while (segs.length && (0, is_util_1._isObject)(obj)) {
|
|
266
|
-
const k =
|
|
266
|
+
const k = segs.shift();
|
|
267
267
|
obj = obj[k];
|
|
268
268
|
}
|
|
269
269
|
if (!(0, is_util_1._isObject)(obj))
|
|
@@ -562,6 +562,13 @@ export function localTimeOrUndefined(d) {
|
|
|
562
562
|
export function localTimeOrNow(d) {
|
|
563
563
|
return d ? LocalTime.of(d) : LocalTime.now();
|
|
564
564
|
}
|
|
565
|
+
/**
|
|
566
|
+
Convenience function to return current Unix timestamp in seconds.
|
|
567
|
+
Like Date.now(), but in seconds.
|
|
568
|
+
*/
|
|
569
|
+
export function nowUnix() {
|
|
570
|
+
return Math.floor(Date.now() / 1000);
|
|
571
|
+
}
|
|
565
572
|
// based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
|
|
566
573
|
function getWeek(date) {
|
|
567
574
|
const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime();
|
package/package.json
CHANGED
|
@@ -686,6 +686,14 @@ export function localTimeOrNow(d?: LocalTimeInput | null): LocalTime {
|
|
|
686
686
|
return d ? LocalTime.of(d) : LocalTime.now()
|
|
687
687
|
}
|
|
688
688
|
|
|
689
|
+
/**
|
|
690
|
+
Convenience function to return current Unix timestamp in seconds.
|
|
691
|
+
Like Date.now(), but in seconds.
|
|
692
|
+
*/
|
|
693
|
+
export function nowUnix(): UnixTimestampNumber {
|
|
694
|
+
return Math.floor(Date.now() / 1000)
|
|
695
|
+
}
|
|
696
|
+
|
|
689
697
|
// based on: https://github.com/date-fns/date-fns/blob/master/src/getISOWeek/index.ts
|
|
690
698
|
function getWeek(date: Date): number {
|
|
691
699
|
const diff = startOfWeek(date).getTime() - startOfWeekYear(date).getTime()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _isPrimitive, MISS, pDelay } from '..'
|
|
1
|
+
import { _isPrimitive, MISS, pDelay, UnixTimestampNumber } from '..'
|
|
2
2
|
|
|
3
3
|
export type MemoSerializer = (args: any[]) => any
|
|
4
4
|
|
|
@@ -8,6 +8,14 @@ export const jsonMemoSerializer: MemoSerializer = args => {
|
|
|
8
8
|
return JSON.stringify(args)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export interface MemoCacheOptions {
|
|
12
|
+
/**
|
|
13
|
+
* If set (and if it's implemented by the driver) - will set expiry TTL for each key of the batch.
|
|
14
|
+
* E.g EXAT in Redis.
|
|
15
|
+
*/
|
|
16
|
+
expireAt?: UnixTimestampNumber
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
export interface MemoCache<KEY = any, VALUE = any> {
|
|
12
20
|
has: (k: KEY) => boolean
|
|
13
21
|
/**
|
|
@@ -17,7 +25,7 @@ export interface MemoCache<KEY = any, VALUE = any> {
|
|
|
17
25
|
* Cache misses are checked by calling `has` method instead.
|
|
18
26
|
*/
|
|
19
27
|
get: (k: KEY) => VALUE
|
|
20
|
-
set: (k: KEY, v: VALUE) => void
|
|
28
|
+
set: (k: KEY, v: VALUE, opt?: MemoCacheOptions) => void
|
|
21
29
|
|
|
22
30
|
/**
|
|
23
31
|
* Clear is only called when `_getMemoCache().clear()` is called.
|
|
@@ -35,7 +43,7 @@ export interface AsyncMemoCache<KEY = any, VALUE = any> {
|
|
|
35
43
|
* they will not be interpreted as a cache miss, because there is a special MISS symbol for that.
|
|
36
44
|
*/
|
|
37
45
|
get: (k: KEY) => Promise<VALUE | typeof MISS>
|
|
38
|
-
set: (k: KEY, v: VALUE) => Promise<void>
|
|
46
|
+
set: (k: KEY, v: VALUE, opt?: MemoCacheOptions) => Promise<void>
|
|
39
47
|
|
|
40
48
|
/**
|
|
41
49
|
* Clear is only called when `_getAsyncMemo().clear()` is called.
|
|
@@ -289,7 +289,7 @@ export function _unset<T extends AnyObject>(obj: T, prop: string): void {
|
|
|
289
289
|
last = segs.pop()!.slice(0, -1) + '.' + last
|
|
290
290
|
}
|
|
291
291
|
while (segs.length && _isObject(obj)) {
|
|
292
|
-
const k =
|
|
292
|
+
const k = segs.shift()!
|
|
293
293
|
obj = obj[k]
|
|
294
294
|
}
|
|
295
295
|
if (!_isObject(obj)) return
|