@naturalcycles/js-lib 14.269.0 → 14.270.1
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/browser/topbar.js +1 -1
- package/dist/datetime/localTime.js +1 -1
- package/dist/decorators/asyncMemo.decorator.d.ts +3 -3
- package/dist/decorators/memo.decorator.d.ts +3 -3
- package/dist/decorators/memoFn.d.ts +1 -1
- package/dist/decorators/memoFnAsync.d.ts +1 -1
- package/dist/types.d.ts +8 -1
- package/dist-esm/browser/topbar.js +1 -1
- package/dist-esm/datetime/localTime.js +1 -1
- package/package.json +1 -1
- package/src/browser/topbar.ts +1 -1
- package/src/datetime/localTime.ts +1 -1
- package/src/decorators/asyncMemo.decorator.ts +4 -4
- package/src/decorators/memo.decorator.ts +4 -4
- package/src/decorators/memoFn.ts +6 -6
- package/src/decorators/memoFnAsync.ts +6 -6
- package/src/types.ts +9 -1
package/dist/browser/topbar.js
CHANGED
|
@@ -108,7 +108,7 @@ exports.topbar = {
|
|
|
108
108
|
return currentProgress;
|
|
109
109
|
}
|
|
110
110
|
if (typeof to === 'string') {
|
|
111
|
-
to = (to.
|
|
111
|
+
to = (to.includes('+') || to.includes('-') ? currentProgress : 0) + parseFloat(to);
|
|
112
112
|
}
|
|
113
113
|
currentProgress = to > 1 ? 1 : to;
|
|
114
114
|
repaint();
|
|
@@ -52,7 +52,7 @@ class LocalTime {
|
|
|
52
52
|
* Opposite of `.utc()` method.
|
|
53
53
|
*/
|
|
54
54
|
toLocal() {
|
|
55
|
-
return new LocalTime(new Date(this.$date
|
|
55
|
+
return new LocalTime(new Date(this.$date));
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Returns [cloned] fake LocalTime that has yyyy-mm-dd hh:mm:ss in the provided timezone.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CommonLogger } from '../log/commonLogger';
|
|
2
2
|
import { AnyAsyncFunction, AnyFunction, AnyObject, MaybeParameters } from '../types';
|
|
3
3
|
import { AsyncMemoCache, MethodDecorator } from './memo.util';
|
|
4
|
-
export interface AsyncMemoOptions<
|
|
4
|
+
export interface AsyncMemoOptions<FN> {
|
|
5
5
|
/**
|
|
6
6
|
* Provide a custom implementation of AsyncMemoCache.
|
|
7
7
|
* Function that creates an instance of `AsyncMemoCache`.
|
|
@@ -10,7 +10,7 @@ export interface AsyncMemoOptions<T> {
|
|
|
10
10
|
/**
|
|
11
11
|
* Provide a custom implementation of CacheKey function.
|
|
12
12
|
*/
|
|
13
|
-
cacheKeyFn?: (args: MaybeParameters<
|
|
13
|
+
cacheKeyFn?: (args: MaybeParameters<FN>) => any;
|
|
14
14
|
/**
|
|
15
15
|
* Default to `console`
|
|
16
16
|
*/
|
|
@@ -32,7 +32,7 @@ export interface AsyncMemoInstance {
|
|
|
32
32
|
*
|
|
33
33
|
* @experimental consider normal @_Memo for most of the cases, it's stable and predictable
|
|
34
34
|
*/
|
|
35
|
-
export declare const _AsyncMemo: <
|
|
35
|
+
export declare const _AsyncMemo: <FN>(opt: AsyncMemoOptions<FN>) => MethodDecorator<FN>;
|
|
36
36
|
/**
|
|
37
37
|
Call it on a method that is decorated with `@_AsyncMemo` to get access to additional functions,
|
|
38
38
|
e.g `clear` to clear the cache, or get its underlying data.
|
|
@@ -2,7 +2,7 @@ import type { CommonLogger } from '../log/commonLogger';
|
|
|
2
2
|
import { AnyFunction, AnyObject, MaybeParameters } from '../types';
|
|
3
3
|
import type { MemoCache } from './memo.util';
|
|
4
4
|
import { MethodDecorator } from './memo.util';
|
|
5
|
-
export interface MemoOptions<
|
|
5
|
+
export interface MemoOptions<FN> {
|
|
6
6
|
/**
|
|
7
7
|
* Provide a custom implementation of MemoCache.
|
|
8
8
|
* Function that creates an instance of `MemoCache`.
|
|
@@ -12,7 +12,7 @@ export interface MemoOptions<T> {
|
|
|
12
12
|
/**
|
|
13
13
|
* Provide a custom implementation of CacheKey function.
|
|
14
14
|
*/
|
|
15
|
-
cacheKeyFn?: (args: MaybeParameters<
|
|
15
|
+
cacheKeyFn?: (args: MaybeParameters<FN>) => any;
|
|
16
16
|
/**
|
|
17
17
|
* Default to `console`
|
|
18
18
|
*/
|
|
@@ -46,7 +46,7 @@ export interface MemoInstance {
|
|
|
46
46
|
* http://inlehmansterms.net/2015/03/01/javascript-memoization/
|
|
47
47
|
* https://community.risingstack.com/the-worlds-fastest-javascript-memoization-library/
|
|
48
48
|
*/
|
|
49
|
-
export declare const _Memo: <
|
|
49
|
+
export declare const _Memo: <FN>(opt?: MemoOptions<FN>) => MethodDecorator<FN>;
|
|
50
50
|
/**
|
|
51
51
|
Call it on a method that is decorated with `@_Memo` to get access to additional functions,
|
|
52
52
|
e.g `clear` to clear the cache, or get its underlying data.
|
|
@@ -11,4 +11,4 @@ export interface MemoizedFunction {
|
|
|
11
11
|
*
|
|
12
12
|
* @experimental
|
|
13
13
|
*/
|
|
14
|
-
export declare function _memoFn<
|
|
14
|
+
export declare function _memoFn<FN extends AnyFunction>(fn: FN, opt?: MemoOptions<FN>): FN & MemoizedFunction;
|
|
@@ -7,4 +7,4 @@ export interface MemoizedAsyncFunction {
|
|
|
7
7
|
/**
|
|
8
8
|
* @experimental
|
|
9
9
|
*/
|
|
10
|
-
export declare function _memoFnAsync<
|
|
10
|
+
export declare function _memoFnAsync<FN extends AnyAsyncFunction>(fn: FN, opt: AsyncMemoOptions<FN>): FN & MemoizedAsyncFunction;
|
package/dist/types.d.ts
CHANGED
|
@@ -100,7 +100,7 @@ export type LazyNullablePromise<T> = () => Promise<T | null>;
|
|
|
100
100
|
/**
|
|
101
101
|
* Evaluates to the parameters if T is a function, otherwise never
|
|
102
102
|
*/
|
|
103
|
-
export type MaybeParameters<
|
|
103
|
+
export type MaybeParameters<FN> = FN extends AnyFunction ? Parameters<FN> : never;
|
|
104
104
|
/**
|
|
105
105
|
* Symbol to indicate END of Sequence.
|
|
106
106
|
*/
|
|
@@ -196,6 +196,13 @@ export type IsoDateTime = Branded<string, 'IsoDateTime'>;
|
|
|
196
196
|
* @example '2023-09'
|
|
197
197
|
*/
|
|
198
198
|
export type MonthId = string;
|
|
199
|
+
/**
|
|
200
|
+
* Identifies IANA timezone name.
|
|
201
|
+
* Branded type.
|
|
202
|
+
*
|
|
203
|
+
* @example 'America/New_York'
|
|
204
|
+
*/
|
|
205
|
+
export type IanaTimezone = Branded<string, 'IanaTimezone'>;
|
|
199
206
|
/**
|
|
200
207
|
* Branded UnixTimestamp in seconds.
|
|
201
208
|
* Extends (compatible with) `number`.
|
|
@@ -105,7 +105,7 @@ export const topbar = {
|
|
|
105
105
|
return currentProgress;
|
|
106
106
|
}
|
|
107
107
|
if (typeof to === 'string') {
|
|
108
|
-
to = (to.
|
|
108
|
+
to = (to.includes('+') || to.includes('-') ? currentProgress : 0) + parseFloat(to);
|
|
109
109
|
}
|
|
110
110
|
currentProgress = to > 1 ? 1 : to;
|
|
111
111
|
repaint();
|
|
@@ -49,7 +49,7 @@ export class LocalTime {
|
|
|
49
49
|
* Opposite of `.utc()` method.
|
|
50
50
|
*/
|
|
51
51
|
toLocal() {
|
|
52
|
-
return new LocalTime(new Date(this.$date
|
|
52
|
+
return new LocalTime(new Date(this.$date));
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Returns [cloned] fake LocalTime that has yyyy-mm-dd hh:mm:ss in the provided timezone.
|
package/package.json
CHANGED
package/src/browser/topbar.ts
CHANGED
|
@@ -120,7 +120,7 @@ export const topbar = {
|
|
|
120
120
|
return currentProgress
|
|
121
121
|
}
|
|
122
122
|
if (typeof to === 'string') {
|
|
123
|
-
to = (to.
|
|
123
|
+
to = (to.includes('+') || to.includes('-') ? currentProgress : 0) + parseFloat(to)
|
|
124
124
|
}
|
|
125
125
|
currentProgress = (to as number) > 1 ? 1 : to
|
|
126
126
|
repaint()
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { _getTargetMethodSignature } from './decorator.util'
|
|
12
12
|
import { AsyncMemoCache, jsonMemoSerializer, MethodDecorator } from './memo.util'
|
|
13
13
|
|
|
14
|
-
export interface AsyncMemoOptions<
|
|
14
|
+
export interface AsyncMemoOptions<FN> {
|
|
15
15
|
/**
|
|
16
16
|
* Provide a custom implementation of AsyncMemoCache.
|
|
17
17
|
* Function that creates an instance of `AsyncMemoCache`.
|
|
@@ -21,7 +21,7 @@ export interface AsyncMemoOptions<T> {
|
|
|
21
21
|
/**
|
|
22
22
|
* Provide a custom implementation of CacheKey function.
|
|
23
23
|
*/
|
|
24
|
-
cacheKeyFn?: (args: MaybeParameters<
|
|
24
|
+
cacheKeyFn?: (args: MaybeParameters<FN>) => any
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Default to `console`
|
|
@@ -50,7 +50,7 @@ export interface AsyncMemoInstance {
|
|
|
50
50
|
*/
|
|
51
51
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
52
52
|
export const _AsyncMemo =
|
|
53
|
-
<
|
|
53
|
+
<FN>(opt: AsyncMemoOptions<FN>): MethodDecorator<FN> =>
|
|
54
54
|
(target, key, descriptor) => {
|
|
55
55
|
_assertTypeOf<AnyFunction>(
|
|
56
56
|
descriptor.value,
|
|
@@ -75,7 +75,7 @@ export const _AsyncMemo =
|
|
|
75
75
|
const methodSignature = _getTargetMethodSignature(target, keyStr)
|
|
76
76
|
|
|
77
77
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
78
|
-
descriptor.value = function (this: typeof target, ...args: MaybeParameters<
|
|
78
|
+
descriptor.value = function (this: typeof target, ...args: MaybeParameters<FN>): Promise<any> {
|
|
79
79
|
const ctx = this
|
|
80
80
|
const cacheKey = cacheKeyFn(args)
|
|
81
81
|
|
|
@@ -5,7 +5,7 @@ import { _getTargetMethodSignature } from './decorator.util'
|
|
|
5
5
|
import type { MemoCache } from './memo.util'
|
|
6
6
|
import { jsonMemoSerializer, MapMemoCache, MethodDecorator } from './memo.util'
|
|
7
7
|
|
|
8
|
-
export interface MemoOptions<
|
|
8
|
+
export interface MemoOptions<FN> {
|
|
9
9
|
/**
|
|
10
10
|
* Provide a custom implementation of MemoCache.
|
|
11
11
|
* Function that creates an instance of `MemoCache`.
|
|
@@ -16,7 +16,7 @@ export interface MemoOptions<T> {
|
|
|
16
16
|
/**
|
|
17
17
|
* Provide a custom implementation of CacheKey function.
|
|
18
18
|
*/
|
|
19
|
-
cacheKeyFn?: (args: MaybeParameters<
|
|
19
|
+
cacheKeyFn?: (args: MaybeParameters<FN>) => any
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Default to `console`
|
|
@@ -57,7 +57,7 @@ export interface MemoInstance {
|
|
|
57
57
|
*/
|
|
58
58
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
59
59
|
export const _Memo =
|
|
60
|
-
<
|
|
60
|
+
<FN>(opt: MemoOptions<FN> = {}): MethodDecorator<FN> =>
|
|
61
61
|
(target, key, descriptor) => {
|
|
62
62
|
_assertTypeOf<AnyFunction>(
|
|
63
63
|
descriptor.value,
|
|
@@ -85,7 +85,7 @@ export const _Memo =
|
|
|
85
85
|
const keyStr = String(key)
|
|
86
86
|
const methodSignature = _getTargetMethodSignature(target, keyStr)
|
|
87
87
|
|
|
88
|
-
descriptor.value = function (this: typeof target, ...args: MaybeParameters<
|
|
88
|
+
descriptor.value = function (this: typeof target, ...args: MaybeParameters<FN>): any {
|
|
89
89
|
const ctx = this
|
|
90
90
|
const cacheKey = cacheKeyFn(args)
|
|
91
91
|
|
package/src/decorators/memoFn.ts
CHANGED
|
@@ -14,10 +14,10 @@ export interface MemoizedFunction {
|
|
|
14
14
|
*
|
|
15
15
|
* @experimental
|
|
16
16
|
*/
|
|
17
|
-
export function _memoFn<
|
|
18
|
-
fn:
|
|
19
|
-
opt: MemoOptions<
|
|
20
|
-
):
|
|
17
|
+
export function _memoFn<FN extends AnyFunction>(
|
|
18
|
+
fn: FN,
|
|
19
|
+
opt: MemoOptions<FN> = {},
|
|
20
|
+
): FN & MemoizedFunction {
|
|
21
21
|
const {
|
|
22
22
|
logger = console,
|
|
23
23
|
cacheFactory = () => new MapMemoCache(),
|
|
@@ -26,7 +26,7 @@ export function _memoFn<T extends AnyFunction>(
|
|
|
26
26
|
|
|
27
27
|
const cache = cacheFactory()
|
|
28
28
|
|
|
29
|
-
const memoizedFn = function (this: any, ...args: MaybeParameters<
|
|
29
|
+
const memoizedFn = function (this: any, ...args: MaybeParameters<FN>): FN {
|
|
30
30
|
const ctx = this
|
|
31
31
|
const cacheKey = cacheKeyFn(args)
|
|
32
32
|
|
|
@@ -46,5 +46,5 @@ export function _memoFn<T extends AnyFunction>(
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
Object.assign(memoizedFn, { cache })
|
|
49
|
-
return memoizedFn as
|
|
49
|
+
return memoizedFn as FN & MemoizedFunction
|
|
50
50
|
}
|
|
@@ -10,10 +10,10 @@ export interface MemoizedAsyncFunction {
|
|
|
10
10
|
/**
|
|
11
11
|
* @experimental
|
|
12
12
|
*/
|
|
13
|
-
export function _memoFnAsync<
|
|
14
|
-
fn:
|
|
15
|
-
opt: AsyncMemoOptions<
|
|
16
|
-
):
|
|
13
|
+
export function _memoFnAsync<FN extends AnyAsyncFunction>(
|
|
14
|
+
fn: FN,
|
|
15
|
+
opt: AsyncMemoOptions<FN>,
|
|
16
|
+
): FN & MemoizedAsyncFunction {
|
|
17
17
|
const {
|
|
18
18
|
logger = console,
|
|
19
19
|
cacheFactory = () => new MapMemoCache(),
|
|
@@ -22,7 +22,7 @@ export function _memoFnAsync<T extends AnyAsyncFunction>(
|
|
|
22
22
|
|
|
23
23
|
const cache = cacheFactory()
|
|
24
24
|
|
|
25
|
-
const memoizedFn = async function (this: any, ...args: MaybeParameters<
|
|
25
|
+
const memoizedFn = async function (this: any, ...args: MaybeParameters<FN>): Promise<any> {
|
|
26
26
|
const ctx = this
|
|
27
27
|
const cacheKey = cacheKeyFn(args)
|
|
28
28
|
let value: any
|
|
@@ -51,5 +51,5 @@ export function _memoFnAsync<T extends AnyAsyncFunction>(
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
Object.assign(memoizedFn, { cache })
|
|
54
|
-
return memoizedFn as
|
|
54
|
+
return memoizedFn as FN & MemoizedAsyncFunction
|
|
55
55
|
}
|
package/src/types.ts
CHANGED
|
@@ -122,7 +122,7 @@ export type LazyNullablePromise<T> = () => Promise<T | null>
|
|
|
122
122
|
/**
|
|
123
123
|
* Evaluates to the parameters if T is a function, otherwise never
|
|
124
124
|
*/
|
|
125
|
-
export type MaybeParameters<
|
|
125
|
+
export type MaybeParameters<FN> = FN extends AnyFunction ? Parameters<FN> : never
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
128
|
* Symbol to indicate END of Sequence.
|
|
@@ -254,6 +254,14 @@ export type IsoDateTime = Branded<string, 'IsoDateTime'>
|
|
|
254
254
|
*/
|
|
255
255
|
export type MonthId = string
|
|
256
256
|
|
|
257
|
+
/**
|
|
258
|
+
* Identifies IANA timezone name.
|
|
259
|
+
* Branded type.
|
|
260
|
+
*
|
|
261
|
+
* @example 'America/New_York'
|
|
262
|
+
*/
|
|
263
|
+
export type IanaTimezone = Branded<string, 'IanaTimezone'>
|
|
264
|
+
|
|
257
265
|
/**
|
|
258
266
|
* Branded UnixTimestamp in seconds.
|
|
259
267
|
* Extends (compatible with) `number`.
|