@naturalcycles/js-lib 14.273.0 → 14.274.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/array/array.util.d.ts +1 -1
- package/dist/browser/adminService.d.ts +1 -1
- package/dist/browser/i18n/fetchTranslationLoader.d.ts +3 -3
- package/dist/browser/i18n/translation.service.d.ts +1 -1
- package/dist/datetime/dateInterval.d.ts +2 -2
- package/dist/datetime/localDate.d.ts +1 -1
- package/dist/datetime/localTime.d.ts +2 -1
- package/dist/datetime/localTime.js +3 -0
- package/dist/datetime/timeInterval.d.ts +1 -1
- package/dist/datetime/wallTime.d.ts +17 -2
- package/dist/datetime/wallTime.js +26 -0
- package/dist/decorators/asyncMemo.decorator.d.ts +2 -2
- package/dist/decorators/memo.decorator.d.ts +2 -3
- package/dist/decorators/memoFn.d.ts +1 -1
- package/dist/decorators/memoFnAsync.d.ts +1 -1
- package/dist/env.js +2 -3
- package/dist/error/error.model.d.ts +2 -2
- package/dist/http/fetcher.d.ts +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/iter/asyncIterable2.d.ts +3 -2
- package/dist/iter/iterable2.d.ts +2 -1
- package/dist/json-schema/jsonSchema.util.d.ts +1 -1
- package/dist/object/object.util.d.ts +2 -1
- package/dist/promise/abortable.d.ts +1 -1
- package/dist/promise/pDelay.d.ts +1 -1
- package/dist/promise/pTimeout.d.ts +1 -1
- package/dist/semver.d.ts +1 -1
- package/dist/string/hash.util.d.ts +1 -1
- package/dist/string/json.util.d.ts +1 -1
- package/dist/web.d.ts +1 -1
- package/dist-esm/array/array.util.js +1 -1
- package/dist-esm/datetime/localTime.js +3 -0
- package/dist-esm/datetime/wallTime.js +26 -0
- package/dist-esm/decorators/asyncMemo.decorator.js +1 -1
- package/dist-esm/env.js +2 -3
- package/dist-esm/object/object.util.js +1 -1
- package/package.json +5 -4
- package/src/array/array.util.ts +2 -2
- package/src/browser/adminService.ts +1 -1
- package/src/browser/i18n/fetchTranslationLoader.ts +3 -3
- package/src/browser/i18n/translation.service.ts +1 -1
- package/src/datetime/dateInterval.ts +3 -2
- package/src/datetime/localDate.ts +2 -1
- package/src/datetime/localTime.ts +6 -1
- package/src/datetime/timeInterval.ts +2 -1
- package/src/datetime/wallTime.ts +33 -2
- package/src/decorators/asyncMemo.decorator.ts +4 -9
- package/src/decorators/memo.decorator.ts +4 -3
- package/src/decorators/memoFn.ts +1 -1
- package/src/decorators/memoFnAsync.ts +2 -1
- package/src/decorators/swarmSafe.decorator.ts +1 -1
- package/src/env.ts +2 -3
- package/src/error/error.model.ts +2 -2
- package/src/http/fetcher.ts +3 -3
- package/src/index.ts +2 -1
- package/src/iter/asyncIterable2.ts +3 -2
- package/src/iter/iterable2.ts +2 -1
- package/src/json-schema/jsonSchema.util.ts +2 -1
- package/src/object/object.util.ts +2 -3
- package/src/promise/abortable.ts +1 -1
- package/src/promise/pDelay.ts +2 -1
- package/src/promise/pTimeout.ts +2 -1
- package/src/semver.ts +1 -1
- package/src/string/hash.util.ts +1 -1
- package/src/string/json.util.ts +1 -1
- package/src/web.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbortablePredicate, FalsyValue, Mapper, Predicate, SortDirection, StringMap } from '../types';
|
|
1
|
+
import type { AbortablePredicate, FalsyValue, Mapper, Predicate, SortDirection, StringMap } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Creates an array of elements split into groups the length of size. If collection can’t be split evenly, the
|
|
4
4
|
* final chunk will be the remaining elements.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Fetcher } from '../../http/fetcher';
|
|
2
|
-
import { StringMap } from '../../types';
|
|
3
|
-
import { TranslationLoader } from './translation.service';
|
|
1
|
+
import type { Fetcher } from '../../http/fetcher';
|
|
2
|
+
import type { StringMap } from '../../types';
|
|
3
|
+
import type { TranslationLoader } from './translation.service';
|
|
4
4
|
/**
|
|
5
5
|
* Use `baseUrl` to prefix your language files.
|
|
6
6
|
* Example URL structure:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StringMap } from '../../types';
|
|
1
|
+
import type { StringMap } from '../../types';
|
|
2
2
|
export type MissingTranslationHandler = (key: string, params?: StringMap<any>) => string;
|
|
3
3
|
export declare const defaultMissingTranslationHandler: MissingTranslationHandler;
|
|
4
4
|
export interface TranslationServiceCfg {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Inclusiveness } from '../types';
|
|
2
|
-
import { LocalDate, LocalDateInput, LocalDateUnit } from './localDate';
|
|
1
|
+
import type { Inclusiveness } from '../types';
|
|
2
|
+
import type { LocalDate, LocalDateInput, LocalDateUnit } from './localDate';
|
|
3
3
|
export type DateIntervalConfig = DateInterval | DateIntervalString;
|
|
4
4
|
export type DateIntervalString = string;
|
|
5
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Iterable2 } from '../iter/iterable2';
|
|
2
2
|
import type { Inclusiveness, IsoDate, IsoDateTime, MonthId, SortDirection, UnixTimestamp, UnixTimestampMillis } from '../types';
|
|
3
|
-
import { DateObject, ISODayOfWeek, LocalTime } from './localTime';
|
|
3
|
+
import type { DateObject, ISODayOfWeek, LocalTime } from './localTime';
|
|
4
4
|
export type LocalDateUnit = LocalDateUnitStrict | 'week';
|
|
5
5
|
export type LocalDateUnitStrict = 'year' | 'month' | 'day';
|
|
6
6
|
export type LocalDateInput = LocalDate | Date | IsoDate;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IANATimezone, Inclusiveness, IsoDate, IsoDateTime, MonthId, NumberOfHours, NumberOfMinutes, SortDirection, UnixTimestamp, UnixTimestampMillis } from '../types';
|
|
2
|
-
import { LocalDate } from './localDate';
|
|
2
|
+
import type { LocalDate } from './localDate';
|
|
3
3
|
import { WallTime } from './wallTime';
|
|
4
4
|
export type LocalTimeUnit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
|
|
5
5
|
export declare enum ISODayOfWeek {
|
|
@@ -220,6 +220,7 @@ export declare class LocalTime {
|
|
|
220
220
|
* Returns e.g: `17:03:15` (or `17:03` with seconds=false)
|
|
221
221
|
*/
|
|
222
222
|
toISOTime(seconds?: boolean): string;
|
|
223
|
+
toWallTime(): WallTime;
|
|
223
224
|
/**
|
|
224
225
|
* Returns e.g: `19840621_1705`
|
|
225
226
|
*/
|
|
@@ -607,6 +607,9 @@ class LocalTime {
|
|
|
607
607
|
// !! Not using toISOString(), as it returns time in UTC, not in local timezone (unexpected!)
|
|
608
608
|
// return this.$date.toISOString().slice(11, seconds ? 19 : 16)
|
|
609
609
|
}
|
|
610
|
+
toWallTime() {
|
|
611
|
+
return new wallTime_1.WallTime(this.toDateTimeObject());
|
|
612
|
+
}
|
|
610
613
|
/**
|
|
611
614
|
* Returns e.g: `19840621_1705`
|
|
612
615
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Inclusiveness, UnixTimestamp } from '../types';
|
|
2
|
-
import { LocalTime, LocalTimeInput } from './localTime';
|
|
2
|
+
import type { LocalTime, LocalTimeInput } from './localTime';
|
|
3
3
|
export type TimeIntervalConfig = TimeInterval | TimeIntervalString;
|
|
4
4
|
export type TimeIntervalString = string;
|
|
5
5
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { IsoDate } from '../types';
|
|
2
|
-
import {
|
|
1
|
+
import type { IsoDate, IsoDateTime } from '../types';
|
|
2
|
+
import { LocalDate } from './localDate';
|
|
3
|
+
import type { DateTimeObject, LocalTime } from './localTime';
|
|
3
4
|
/**
|
|
4
5
|
* Representation of a "time on the wall clock",
|
|
5
6
|
* which means "local time, regardless of timezone".
|
|
@@ -17,12 +18,26 @@ export declare class WallTime implements DateTimeObject {
|
|
|
17
18
|
minute: number;
|
|
18
19
|
second: number;
|
|
19
20
|
constructor(obj: DateTimeObject);
|
|
21
|
+
toLocalDate(): LocalDate;
|
|
22
|
+
/**
|
|
23
|
+
* Example:
|
|
24
|
+
* WallTime is 1984-06-21 17:56:21
|
|
25
|
+
* .toLocalTime() will return a LocalTime Date instance
|
|
26
|
+
* holding that time in the local timezone.
|
|
27
|
+
*/
|
|
28
|
+
toLocalTime(): LocalTime;
|
|
29
|
+
toJSON(): IsoDateTime;
|
|
30
|
+
toString(): IsoDateTime;
|
|
20
31
|
/**
|
|
21
32
|
* Returns e.g: `1984-06-21 17:56:21`
|
|
22
33
|
* or (if seconds=false):
|
|
23
34
|
* `1984-06-21 17:56`
|
|
24
35
|
*/
|
|
25
36
|
toPretty(seconds?: boolean): string;
|
|
37
|
+
/**
|
|
38
|
+
* Returns e.g: `1984-06-21T17:56:21`
|
|
39
|
+
*/
|
|
40
|
+
toISODateTime(): IsoDateTime;
|
|
26
41
|
/**
|
|
27
42
|
* Returns e.g: `1984-06-21`, only the date part of DateTime
|
|
28
43
|
*/
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WallTime = void 0;
|
|
4
|
+
const localDate_1 = require("./localDate");
|
|
5
|
+
const localTime_1 = require("./localTime");
|
|
4
6
|
/**
|
|
5
7
|
* Representation of a "time on the wall clock",
|
|
6
8
|
* which means "local time, regardless of timezone".
|
|
@@ -14,6 +16,24 @@ class WallTime {
|
|
|
14
16
|
constructor(obj) {
|
|
15
17
|
Object.assign(this, obj);
|
|
16
18
|
}
|
|
19
|
+
toLocalDate() {
|
|
20
|
+
return new localDate_1.LocalDate(this.year, this.month, this.day);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Example:
|
|
24
|
+
* WallTime is 1984-06-21 17:56:21
|
|
25
|
+
* .toLocalTime() will return a LocalTime Date instance
|
|
26
|
+
* holding that time in the local timezone.
|
|
27
|
+
*/
|
|
28
|
+
toLocalTime() {
|
|
29
|
+
return localTime_1.localTime.fromDateTimeObject(this);
|
|
30
|
+
}
|
|
31
|
+
toJSON() {
|
|
32
|
+
return this.toISODateTime();
|
|
33
|
+
}
|
|
34
|
+
toString() {
|
|
35
|
+
return this.toISODateTime();
|
|
36
|
+
}
|
|
17
37
|
/**
|
|
18
38
|
* Returns e.g: `1984-06-21 17:56:21`
|
|
19
39
|
* or (if seconds=false):
|
|
@@ -22,6 +42,12 @@ class WallTime {
|
|
|
22
42
|
toPretty(seconds = true) {
|
|
23
43
|
return this.toISODate() + ' ' + this.toISOTime(seconds);
|
|
24
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns e.g: `1984-06-21T17:56:21`
|
|
47
|
+
*/
|
|
48
|
+
toISODateTime() {
|
|
49
|
+
return (this.toISODate() + 'T' + this.toISOTime());
|
|
50
|
+
}
|
|
25
51
|
/**
|
|
26
52
|
* Returns e.g: `1984-06-21`, only the date part of DateTime
|
|
27
53
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CommonLogger } from '../log/commonLogger';
|
|
2
|
-
import { AnyAsyncFunction, AnyFunction, AnyObject, MaybeParameters } from '../types';
|
|
3
|
-
import { AsyncMemoCache, MethodDecorator } from './memo.util';
|
|
2
|
+
import type { AnyAsyncFunction, AnyFunction, AnyObject, MaybeParameters } from '../types';
|
|
3
|
+
import type { AsyncMemoCache, MethodDecorator } from './memo.util';
|
|
4
4
|
export interface AsyncMemoOptions<FN> {
|
|
5
5
|
/**
|
|
6
6
|
* Provide a custom implementation of AsyncMemoCache.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { CommonLogger } from '../log/commonLogger';
|
|
2
|
-
import { AnyFunction, AnyObject, MaybeParameters } from '../types';
|
|
3
|
-
import type { MemoCache } from './memo.util';
|
|
4
|
-
import { MethodDecorator } from './memo.util';
|
|
2
|
+
import type { AnyFunction, AnyObject, MaybeParameters } from '../types';
|
|
3
|
+
import type { MemoCache, MethodDecorator } from './memo.util';
|
|
5
4
|
export interface MemoOptions<FN> {
|
|
6
5
|
/**
|
|
7
6
|
* Provide a custom implementation of MemoCache.
|
package/dist/env.js
CHANGED
|
@@ -9,8 +9,7 @@ exports.isClientSide = isClientSide;
|
|
|
9
9
|
* Will return `false` in the Browser.
|
|
10
10
|
*/
|
|
11
11
|
function isServerSide() {
|
|
12
|
-
|
|
13
|
-
return typeof window === 'undefined';
|
|
12
|
+
return !isClientSide();
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
16
15
|
* Use it to detect Browser (not SSR/Node) environment.
|
|
@@ -20,5 +19,5 @@ function isServerSide() {
|
|
|
20
19
|
*/
|
|
21
20
|
function isClientSide() {
|
|
22
21
|
// eslint-disable-next-line unicorn/prefer-global-this
|
|
23
|
-
return typeof window !== 'undefined';
|
|
22
|
+
return typeof window !== 'undefined' && !!window?.document;
|
|
24
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpMethod, HttpStatusCode } from '../http/http.model';
|
|
2
|
-
import { NumberOfMilliseconds } from '../types';
|
|
1
|
+
import type { HttpMethod, HttpStatusCode } from '../http/http.model';
|
|
2
|
+
import type { NumberOfMilliseconds } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Extendable payload object to transfer custom additional data with AppError.
|
|
5
5
|
*/
|
package/dist/http/fetcher.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/// <reference lib="dom" preserve="true" />
|
|
3
3
|
/// <reference lib="dom.iterable" preserve="true" />
|
|
4
4
|
import { HttpRequestError } from '../error/error.util';
|
|
5
|
-
import { ErrorDataTuple } from '../types';
|
|
6
|
-
import { FetcherAfterResponseHook, FetcherBeforeRequestHook, FetcherBeforeRetryHook, FetcherCfg, FetcherGraphQLOptions, FetcherNormalizedCfg, FetcherOnErrorHook, FetcherOptions, FetcherResponse, RequestInitNormalized } from './fetcher.model';
|
|
5
|
+
import type { ErrorDataTuple } from '../types';
|
|
6
|
+
import type { FetcherAfterResponseHook, FetcherBeforeRequestHook, FetcherBeforeRetryHook, FetcherCfg, FetcherGraphQLOptions, FetcherNormalizedCfg, FetcherOnErrorHook, FetcherOptions, FetcherResponse, RequestInitNormalized } from './fetcher.model';
|
|
7
7
|
/**
|
|
8
8
|
* Experimental wrapper around Fetch.
|
|
9
9
|
* Works in both Browser and Node, using `globalThis.fetch`.
|
package/dist/index.d.ts
CHANGED
|
@@ -96,6 +96,7 @@ export * from './unit/size.util';
|
|
|
96
96
|
export * from './web';
|
|
97
97
|
export * from './zod/zod.shared.schemas';
|
|
98
98
|
export * from './zod/zod.util';
|
|
99
|
-
import {
|
|
99
|
+
import type { ZodIssue } from 'zod';
|
|
100
|
+
import { z, ZodError, ZodSchema } from 'zod';
|
|
100
101
|
export { z, ZodError, ZodSchema };
|
|
101
102
|
export type { ZodIssue };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Promisable } from '../typeFest';
|
|
2
|
-
import { AbortableAsyncMapper, AbortableAsyncPredicate
|
|
1
|
+
import type { Promisable } from '../typeFest';
|
|
2
|
+
import type { AbortableAsyncMapper, AbortableAsyncPredicate } from '../types';
|
|
3
|
+
import { END } from '../types';
|
|
3
4
|
/**
|
|
4
5
|
* Similar to Iterable2, but for AsyncIterable.
|
|
5
6
|
*
|
package/dist/iter/iterable2.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AbortableMapper, AbortablePredicate
|
|
1
|
+
import type { AbortableMapper, AbortablePredicate } from '../types';
|
|
2
|
+
import { END } from '../types';
|
|
2
3
|
/**
|
|
3
4
|
* Iterable2 is a wrapper around Iterable that implements "Iterator Helpers proposal":
|
|
4
5
|
* https://github.com/tc39/proposal-iterator-helpers
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AnyObject, KeyValueTuple, ObjectMapper, ObjectPredicate, Reviver,
|
|
1
|
+
import type { AnyObject, KeyValueTuple, ObjectMapper, ObjectPredicate, Reviver, ValueOf } from '../types';
|
|
2
|
+
import { SKIP } from '../types';
|
|
2
3
|
/**
|
|
3
4
|
* Returns clone of `obj` with only `props` preserved.
|
|
4
5
|
* Opposite of Omit.
|
package/dist/promise/pDelay.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ErrorData } from '../error/error.model';
|
|
2
2
|
import { TimeoutError } from '../error/error.util';
|
|
3
|
-
import { AnyAsyncFunction, NumberOfMilliseconds } from '../types';
|
|
3
|
+
import type { AnyAsyncFunction, NumberOfMilliseconds } from '../types';
|
|
4
4
|
export interface PTimeoutOptions {
|
|
5
5
|
/**
|
|
6
6
|
* Timeout in milliseconds.
|
package/dist/semver.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SortDirection } from './types';
|
|
1
|
+
import type { SortDirection } from './types';
|
|
2
2
|
export type SemverInput = string | Semver;
|
|
3
3
|
export type SemverInputNullable = SemverInput | null | undefined;
|
|
4
4
|
export type SemverTokens = [major: number, minor: number, patch: number];
|
package/dist/web.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference lib="es2022" preserve="true" />
|
|
2
2
|
/// <reference lib="dom" preserve="true" />
|
|
3
|
-
import { StringMap } from './types';
|
|
3
|
+
import type { StringMap } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Implements WebStorage API by using in-memory storage.
|
|
6
6
|
* Can be useful in SSR environment or unit tests.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _assert } from '../error/assert';
|
|
2
|
-
import { END
|
|
2
|
+
import { END } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Creates an array of elements split into groups the length of size. If collection can’t be split evenly, the
|
|
5
5
|
* final chunk will be the remaining elements.
|
|
@@ -604,6 +604,9 @@ export class LocalTime {
|
|
|
604
604
|
// !! Not using toISOString(), as it returns time in UTC, not in local timezone (unexpected!)
|
|
605
605
|
// return this.$date.toISOString().slice(11, seconds ? 19 : 16)
|
|
606
606
|
}
|
|
607
|
+
toWallTime() {
|
|
608
|
+
return new WallTime(this.toDateTimeObject());
|
|
609
|
+
}
|
|
607
610
|
/**
|
|
608
611
|
* Returns e.g: `19840621_1705`
|
|
609
612
|
*/
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { LocalDate } from './localDate';
|
|
2
|
+
import { localTime } from './localTime';
|
|
1
3
|
/**
|
|
2
4
|
* Representation of a "time on the wall clock",
|
|
3
5
|
* which means "local time, regardless of timezone".
|
|
@@ -11,6 +13,24 @@ export class WallTime {
|
|
|
11
13
|
constructor(obj) {
|
|
12
14
|
Object.assign(this, obj);
|
|
13
15
|
}
|
|
16
|
+
toLocalDate() {
|
|
17
|
+
return new LocalDate(this.year, this.month, this.day);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Example:
|
|
21
|
+
* WallTime is 1984-06-21 17:56:21
|
|
22
|
+
* .toLocalTime() will return a LocalTime Date instance
|
|
23
|
+
* holding that time in the local timezone.
|
|
24
|
+
*/
|
|
25
|
+
toLocalTime() {
|
|
26
|
+
return localTime.fromDateTimeObject(this);
|
|
27
|
+
}
|
|
28
|
+
toJSON() {
|
|
29
|
+
return this.toISODateTime();
|
|
30
|
+
}
|
|
31
|
+
toString() {
|
|
32
|
+
return this.toISODateTime();
|
|
33
|
+
}
|
|
14
34
|
/**
|
|
15
35
|
* Returns e.g: `1984-06-21 17:56:21`
|
|
16
36
|
* or (if seconds=false):
|
|
@@ -19,6 +39,12 @@ export class WallTime {
|
|
|
19
39
|
toPretty(seconds = true) {
|
|
20
40
|
return this.toISODate() + ' ' + this.toISOTime(seconds);
|
|
21
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns e.g: `1984-06-21T17:56:21`
|
|
44
|
+
*/
|
|
45
|
+
toISODateTime() {
|
|
46
|
+
return (this.toISODate() + 'T' + this.toISOTime());
|
|
47
|
+
}
|
|
22
48
|
/**
|
|
23
49
|
* Returns e.g: `1984-06-21`, only the date part of DateTime
|
|
24
50
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _assert, _assertTypeOf } from '../error/assert';
|
|
2
|
-
import { _objectAssign, MISS
|
|
2
|
+
import { _objectAssign, MISS } from '../types';
|
|
3
3
|
import { _getTargetMethodSignature } from './decorator.util';
|
|
4
4
|
import { jsonMemoSerializer } from './memo.util';
|
|
5
5
|
/**
|
package/dist-esm/env.js
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* Will return `false` in the Browser.
|
|
6
6
|
*/
|
|
7
7
|
export function isServerSide() {
|
|
8
|
-
|
|
9
|
-
return typeof window === 'undefined';
|
|
8
|
+
return !isClientSide();
|
|
10
9
|
}
|
|
11
10
|
/**
|
|
12
11
|
* Use it to detect Browser (not SSR/Node) environment.
|
|
@@ -16,5 +15,5 @@ export function isServerSide() {
|
|
|
16
15
|
*/
|
|
17
16
|
export function isClientSide() {
|
|
18
17
|
// eslint-disable-next-line unicorn/prefer-global-this
|
|
19
|
-
return typeof window !== 'undefined';
|
|
18
|
+
return typeof window !== 'undefined' && !!window?.document;
|
|
20
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.274.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky",
|
|
6
6
|
"build": "dev-lib build-esm-cjs",
|
|
@@ -21,16 +21,17 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@naturalcycles/bench-lib": "^3",
|
|
24
|
-
"@naturalcycles/dev-lib": "^
|
|
24
|
+
"@naturalcycles/dev-lib": "^17",
|
|
25
25
|
"@naturalcycles/nodejs-lib": "^13",
|
|
26
26
|
"@naturalcycles/time-lib": "^3",
|
|
27
27
|
"@types/crypto-js": "^4",
|
|
28
28
|
"@types/node": "^22",
|
|
29
29
|
"@types/semver": "^7",
|
|
30
|
+
"@vitest/coverage-v8": "^3",
|
|
30
31
|
"crypto-js": "^4",
|
|
31
|
-
"
|
|
32
|
-
"prettier": "^3",
|
|
32
|
+
"tsx": "^4.19.3",
|
|
33
33
|
"vitepress": "^1",
|
|
34
|
+
"vitest": "^3",
|
|
34
35
|
"vue": "^3"
|
|
35
36
|
},
|
|
36
37
|
"files": [
|
package/src/array/array.util.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { _assert } from '../error/assert'
|
|
2
|
-
import {
|
|
2
|
+
import type {
|
|
3
3
|
AbortablePredicate,
|
|
4
|
-
END,
|
|
5
4
|
FalsyValue,
|
|
6
5
|
Mapper,
|
|
7
6
|
Predicate,
|
|
8
7
|
SortDirection,
|
|
9
8
|
StringMap,
|
|
10
9
|
} from '../types'
|
|
10
|
+
import { END } from '../types'
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Creates an array of elements split into groups the length of size. If collection can’t be split evenly, the
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _Memo } from '../decorators/memo.decorator'
|
|
2
2
|
import { isServerSide } from '../env'
|
|
3
3
|
import { _stringify } from '../string/stringify'
|
|
4
|
-
import { Promisable } from '../typeFest'
|
|
4
|
+
import type { Promisable } from '../typeFest'
|
|
5
5
|
|
|
6
6
|
export interface AdminModeCfg {
|
|
7
7
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Fetcher } from '../../http/fetcher'
|
|
2
|
-
import { StringMap } from '../../types'
|
|
3
|
-
import { TranslationLoader } from './translation.service'
|
|
1
|
+
import type { Fetcher } from '../../http/fetcher'
|
|
2
|
+
import type { StringMap } from '../../types'
|
|
3
|
+
import type { TranslationLoader } from './translation.service'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Use `baseUrl` to prefix your language files.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Inclusiveness, IsoDate } from '../types'
|
|
2
|
-
import { LocalDate,
|
|
1
|
+
import type { Inclusiveness, IsoDate } from '../types'
|
|
2
|
+
import type { LocalDate, LocalDateInput, LocalDateUnit } from './localDate'
|
|
3
|
+
import { localDate } from './localDate'
|
|
3
4
|
|
|
4
5
|
export type DateIntervalConfig = DateInterval | DateIntervalString
|
|
5
6
|
export type DateIntervalString = string
|
|
@@ -9,7 +9,8 @@ import type {
|
|
|
9
9
|
UnixTimestamp,
|
|
10
10
|
UnixTimestampMillis,
|
|
11
11
|
} from '../types'
|
|
12
|
-
import { DateObject, ISODayOfWeek, LocalTime
|
|
12
|
+
import type { DateObject, ISODayOfWeek, LocalTime } from './localTime'
|
|
13
|
+
import { localTime, VALID_DAYS_OF_WEEK } from './localTime'
|
|
13
14
|
|
|
14
15
|
export type LocalDateUnit = LocalDateUnitStrict | 'week'
|
|
15
16
|
export type LocalDateUnitStrict = 'year' | 'month' | 'day'
|
|
@@ -12,7 +12,8 @@ import type {
|
|
|
12
12
|
UnixTimestamp,
|
|
13
13
|
UnixTimestampMillis,
|
|
14
14
|
} from '../types'
|
|
15
|
-
import { LocalDate
|
|
15
|
+
import type { LocalDate } from './localDate'
|
|
16
|
+
import { localDate } from './localDate'
|
|
16
17
|
import { WallTime } from './wallTime'
|
|
17
18
|
|
|
18
19
|
export type LocalTimeUnit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second'
|
|
@@ -727,6 +728,10 @@ export class LocalTime {
|
|
|
727
728
|
// return this.$date.toISOString().slice(11, seconds ? 19 : 16)
|
|
728
729
|
}
|
|
729
730
|
|
|
731
|
+
toWallTime(): WallTime {
|
|
732
|
+
return new WallTime(this.toDateTimeObject())
|
|
733
|
+
}
|
|
734
|
+
|
|
730
735
|
/**
|
|
731
736
|
* Returns e.g: `19840621_1705`
|
|
732
737
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Inclusiveness, UnixTimestamp } from '../types'
|
|
2
|
-
import { LocalTime,
|
|
2
|
+
import type { LocalTime, LocalTimeInput } from './localTime'
|
|
3
|
+
import { localTime } from './localTime'
|
|
3
4
|
|
|
4
5
|
export type TimeIntervalConfig = TimeInterval | TimeIntervalString
|
|
5
6
|
export type TimeIntervalString = string
|
package/src/datetime/wallTime.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { IsoDate } from '../types'
|
|
2
|
-
import {
|
|
1
|
+
import type { IsoDate, IsoDateTime } from '../types'
|
|
2
|
+
import { LocalDate } from './localDate'
|
|
3
|
+
import type { DateTimeObject, LocalTime } from './localTime'
|
|
4
|
+
import { localTime } from './localTime'
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Representation of a "time on the wall clock",
|
|
@@ -22,6 +24,28 @@ export class WallTime implements DateTimeObject {
|
|
|
22
24
|
Object.assign(this, obj)
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
toLocalDate(): LocalDate {
|
|
28
|
+
return new LocalDate(this.year, this.month, this.day)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Example:
|
|
33
|
+
* WallTime is 1984-06-21 17:56:21
|
|
34
|
+
* .toLocalTime() will return a LocalTime Date instance
|
|
35
|
+
* holding that time in the local timezone.
|
|
36
|
+
*/
|
|
37
|
+
toLocalTime(): LocalTime {
|
|
38
|
+
return localTime.fromDateTimeObject(this)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
toJSON(): IsoDateTime {
|
|
42
|
+
return this.toISODateTime()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
toString(): IsoDateTime {
|
|
46
|
+
return this.toISODateTime()
|
|
47
|
+
}
|
|
48
|
+
|
|
25
49
|
/**
|
|
26
50
|
* Returns e.g: `1984-06-21 17:56:21`
|
|
27
51
|
* or (if seconds=false):
|
|
@@ -31,6 +55,13 @@ export class WallTime implements DateTimeObject {
|
|
|
31
55
|
return this.toISODate() + ' ' + this.toISOTime(seconds)
|
|
32
56
|
}
|
|
33
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Returns e.g: `1984-06-21T17:56:21`
|
|
60
|
+
*/
|
|
61
|
+
toISODateTime(): IsoDateTime {
|
|
62
|
+
return (this.toISODate() + 'T' + this.toISOTime()) as IsoDateTime
|
|
63
|
+
}
|
|
64
|
+
|
|
34
65
|
/**
|
|
35
66
|
* Returns e.g: `1984-06-21`, only the date part of DateTime
|
|
36
67
|
*/
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { _assert, _assertTypeOf } from '../error/assert'
|
|
2
2
|
import type { CommonLogger } from '../log/commonLogger'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
AnyAsyncFunction,
|
|
6
|
-
AnyFunction,
|
|
7
|
-
AnyObject,
|
|
8
|
-
MaybeParameters,
|
|
9
|
-
MISS,
|
|
10
|
-
} from '../types'
|
|
3
|
+
import type { AnyAsyncFunction, AnyFunction, AnyObject, MaybeParameters } from '../types'
|
|
4
|
+
import { _objectAssign, MISS } from '../types'
|
|
11
5
|
import { _getTargetMethodSignature } from './decorator.util'
|
|
12
|
-
import { AsyncMemoCache,
|
|
6
|
+
import type { AsyncMemoCache, MethodDecorator } from './memo.util'
|
|
7
|
+
import { jsonMemoSerializer } from './memo.util'
|
|
13
8
|
|
|
14
9
|
export interface AsyncMemoOptions<FN> {
|
|
15
10
|
/**
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { _assert, _assertTypeOf } from '../error/assert'
|
|
2
2
|
import type { CommonLogger } from '../log/commonLogger'
|
|
3
|
-
import {
|
|
3
|
+
import type { AnyFunction, AnyObject, MaybeParameters } from '../types'
|
|
4
|
+
import { _objectAssign } from '../types'
|
|
4
5
|
import { _getTargetMethodSignature } from './decorator.util'
|
|
5
|
-
import type { MemoCache } from './memo.util'
|
|
6
|
-
import { jsonMemoSerializer, MapMemoCache
|
|
6
|
+
import type { MemoCache, MethodDecorator } from './memo.util'
|
|
7
|
+
import { jsonMemoSerializer, MapMemoCache } from './memo.util'
|
|
7
8
|
|
|
8
9
|
export interface MemoOptions<FN> {
|
|
9
10
|
/**
|
package/src/decorators/memoFn.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyFunction, MaybeParameters } from '../types'
|
|
1
|
+
import type { AnyFunction, MaybeParameters } from '../types'
|
|
2
2
|
import type { MemoOptions } from './memo.decorator'
|
|
3
3
|
import type { MemoCache } from './memo.util'
|
|
4
4
|
import { jsonMemoSerializer, MapMemoCache } from './memo.util'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AnyAsyncFunction, MaybeParameters
|
|
1
|
+
import type { AnyAsyncFunction, MaybeParameters } from '../types'
|
|
2
|
+
import { MISS } from '../types'
|
|
2
3
|
import type { AsyncMemoOptions } from './asyncMemo.decorator'
|
|
3
4
|
import type { AsyncMemoCache } from './memo.util'
|
|
4
5
|
import { jsonMemoSerializer, MapMemoCache } from './memo.util'
|
package/src/env.ts
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* Will return `false` in the Browser.
|
|
6
6
|
*/
|
|
7
7
|
export function isServerSide(): boolean {
|
|
8
|
-
|
|
9
|
-
return typeof window === 'undefined'
|
|
8
|
+
return !isClientSide()
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
/**
|
|
@@ -17,5 +16,5 @@ export function isServerSide(): boolean {
|
|
|
17
16
|
*/
|
|
18
17
|
export function isClientSide(): boolean {
|
|
19
18
|
// eslint-disable-next-line unicorn/prefer-global-this
|
|
20
|
-
return typeof window !== 'undefined'
|
|
19
|
+
return typeof window !== 'undefined' && !!window?.document
|
|
21
20
|
}
|
package/src/error/error.model.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpMethod, HttpStatusCode } from '../http/http.model'
|
|
2
|
-
import { NumberOfMilliseconds } from '../types'
|
|
1
|
+
import type { HttpMethod, HttpStatusCode } from '../http/http.model'
|
|
2
|
+
import type { NumberOfMilliseconds } from '../types'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Extendable payload object to transfer custom additional data with AppError.
|
package/src/http/fetcher.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { isServerSide } from '../env'
|
|
6
6
|
import { _assertErrorClassOrRethrow, _assertIsError } from '../error/assert'
|
|
7
|
-
import { ErrorLike, ErrorObject } from '../error/error.model'
|
|
7
|
+
import type { ErrorLike, ErrorObject } from '../error/error.model'
|
|
8
8
|
import {
|
|
9
9
|
_anyToError,
|
|
10
10
|
_anyToErrorObject,
|
|
@@ -29,8 +29,8 @@ import { pTimeout } from '../promise/pTimeout'
|
|
|
29
29
|
import { _jsonParse, _jsonParseIfPossible } from '../string/json.util'
|
|
30
30
|
import { _stringify } from '../string/stringify'
|
|
31
31
|
import { _ms, _since } from '../time/time.util'
|
|
32
|
-
import { AnyObject, ErrorDataTuple, NumberOfMilliseconds, UnixTimestampMillis } from '../types'
|
|
33
|
-
import {
|
|
32
|
+
import type { AnyObject, ErrorDataTuple, NumberOfMilliseconds, UnixTimestampMillis } from '../types'
|
|
33
|
+
import type {
|
|
34
34
|
FetcherAfterResponseHook,
|
|
35
35
|
FetcherBeforeRequestHook,
|
|
36
36
|
FetcherBeforeRetryHook,
|
package/src/index.ts
CHANGED
|
@@ -96,7 +96,8 @@ export * from './unit/size.util'
|
|
|
96
96
|
export * from './web'
|
|
97
97
|
export * from './zod/zod.shared.schemas'
|
|
98
98
|
export * from './zod/zod.util'
|
|
99
|
-
import {
|
|
99
|
+
import type { ZodIssue } from 'zod'
|
|
100
|
+
import { z, ZodError, ZodSchema } from 'zod'
|
|
100
101
|
|
|
101
102
|
export { z, ZodError, ZodSchema }
|
|
102
103
|
export type { ZodIssue }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Promisable } from '../typeFest'
|
|
2
|
-
import { AbortableAsyncMapper, AbortableAsyncPredicate
|
|
1
|
+
import type { Promisable } from '../typeFest'
|
|
2
|
+
import type { AbortableAsyncMapper, AbortableAsyncPredicate } from '../types'
|
|
3
|
+
import { END, SKIP } from '../types'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Similar to Iterable2, but for AsyncIterable.
|
package/src/iter/iterable2.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AbortableMapper, AbortablePredicate
|
|
1
|
+
import type { AbortableMapper, AbortablePredicate } from '../types'
|
|
2
|
+
import { END, SKIP } from '../types'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Iterable2 is a wrapper around Iterable that implements "Iterator Helpers proposal":
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { _isEmpty, _isObject } from '../is.util'
|
|
2
|
-
import {
|
|
3
|
-
_objectEntries,
|
|
2
|
+
import type {
|
|
4
3
|
AnyObject,
|
|
5
4
|
KeyValueTuple,
|
|
6
5
|
ObjectMapper,
|
|
7
6
|
ObjectPredicate,
|
|
8
7
|
Reviver,
|
|
9
|
-
SKIP,
|
|
10
8
|
ValueOf,
|
|
11
9
|
} from '../types'
|
|
10
|
+
import { _objectEntries, SKIP } from '../types'
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Returns clone of `obj` with only `props` preserved.
|
package/src/promise/abortable.ts
CHANGED
package/src/promise/pDelay.ts
CHANGED
package/src/promise/pTimeout.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ErrorData } from '../error/error.model'
|
|
2
2
|
import { _errorDataAppend, TimeoutError } from '../error/error.util'
|
|
3
|
-
import {
|
|
3
|
+
import type { AnyAsyncFunction, NumberOfMilliseconds } from '../types'
|
|
4
|
+
import { _typeCast } from '../types'
|
|
4
5
|
|
|
5
6
|
export interface PTimeoutOptions {
|
|
6
7
|
/**
|
package/src/semver.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _range } from './array/range'
|
|
2
2
|
import { _assert } from './error/assert'
|
|
3
|
-
import { SortDirection } from './types'
|
|
3
|
+
import type { SortDirection } from './types'
|
|
4
4
|
|
|
5
5
|
export type SemverInput = string | Semver
|
|
6
6
|
export type SemverInputNullable = SemverInput | null | undefined
|
package/src/string/hash.util.ts
CHANGED
package/src/string/json.util.ts
CHANGED
package/src/web.ts
CHANGED