@naturalcycles/js-lib 14.269.0 → 14.270.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.
@@ -108,7 +108,7 @@ exports.topbar = {
108
108
  return currentProgress;
109
109
  }
110
110
  if (typeof to === 'string') {
111
- to = (to.indexOf('+') >= 0 || to.indexOf('-') >= 0 ? currentProgress : 0) + parseFloat(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.getTime()));
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<T> {
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<T>) => any;
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: <T>(opt: AsyncMemoOptions<T>) => MethodDecorator<T>;
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<T> {
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<T>) => any;
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: <T>(opt?: MemoOptions<T>) => MethodDecorator<T>;
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<T extends AnyFunction>(fn: T, opt?: MemoOptions<T>): T & MemoizedFunction;
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<T extends AnyAsyncFunction>(fn: T, opt: AsyncMemoOptions<T>): T & MemoizedAsyncFunction;
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<T> = T extends AnyFunction ? Parameters<T> : never;
103
+ export type MaybeParameters<FN> = FN extends AnyFunction ? Parameters<FN> : never;
104
104
  /**
105
105
  * Symbol to indicate END of Sequence.
106
106
  */
@@ -105,7 +105,7 @@ export const topbar = {
105
105
  return currentProgress;
106
106
  }
107
107
  if (typeof to === 'string') {
108
- to = (to.indexOf('+') >= 0 || to.indexOf('-') >= 0 ? currentProgress : 0) + parseFloat(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.getTime()));
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.269.0",
3
+ "version": "14.270.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build-esm-cjs",
@@ -120,7 +120,7 @@ export const topbar = {
120
120
  return currentProgress
121
121
  }
122
122
  if (typeof to === 'string') {
123
- to = (to.indexOf('+') >= 0 || to.indexOf('-') >= 0 ? currentProgress : 0) + parseFloat(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()
@@ -84,7 +84,7 @@ export class LocalTime {
84
84
  * Opposite of `.utc()` method.
85
85
  */
86
86
  toLocal(): LocalTime {
87
- return new LocalTime(new Date(this.$date.getTime()))
87
+ return new LocalTime(new Date(this.$date))
88
88
  }
89
89
 
90
90
  /**
@@ -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<T> {
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<T>) => any
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
- <T>(opt: AsyncMemoOptions<T>): MethodDecorator<T> =>
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<T>): Promise<any> {
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<T> {
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<T>) => any
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
- <T>(opt: MemoOptions<T> = {}): MethodDecorator<T> =>
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<T>): any {
88
+ descriptor.value = function (this: typeof target, ...args: MaybeParameters<FN>): any {
89
89
  const ctx = this
90
90
  const cacheKey = cacheKeyFn(args)
91
91
 
@@ -14,10 +14,10 @@ export interface MemoizedFunction {
14
14
  *
15
15
  * @experimental
16
16
  */
17
- export function _memoFn<T extends AnyFunction>(
18
- fn: T,
19
- opt: MemoOptions<T> = {},
20
- ): T & MemoizedFunction {
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<T>): T {
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 T & MemoizedFunction
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<T extends AnyAsyncFunction>(
14
- fn: T,
15
- opt: AsyncMemoOptions<T>,
16
- ): T & MemoizedAsyncFunction {
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<T>): Promise<any> {
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 T & MemoizedAsyncFunction
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<T> = T extends AnyFunction ? Parameters<T> : never
125
+ export type MaybeParameters<FN> = FN extends AnyFunction ? Parameters<FN> : never
126
126
 
127
127
  /**
128
128
  * Symbol to indicate END of Sequence.