@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.
Files changed (66) hide show
  1. package/dist/array/array.util.d.ts +1 -1
  2. package/dist/browser/adminService.d.ts +1 -1
  3. package/dist/browser/i18n/fetchTranslationLoader.d.ts +3 -3
  4. package/dist/browser/i18n/translation.service.d.ts +1 -1
  5. package/dist/datetime/dateInterval.d.ts +2 -2
  6. package/dist/datetime/localDate.d.ts +1 -1
  7. package/dist/datetime/localTime.d.ts +2 -1
  8. package/dist/datetime/localTime.js +3 -0
  9. package/dist/datetime/timeInterval.d.ts +1 -1
  10. package/dist/datetime/wallTime.d.ts +17 -2
  11. package/dist/datetime/wallTime.js +26 -0
  12. package/dist/decorators/asyncMemo.decorator.d.ts +2 -2
  13. package/dist/decorators/memo.decorator.d.ts +2 -3
  14. package/dist/decorators/memoFn.d.ts +1 -1
  15. package/dist/decorators/memoFnAsync.d.ts +1 -1
  16. package/dist/env.js +2 -3
  17. package/dist/error/error.model.d.ts +2 -2
  18. package/dist/http/fetcher.d.ts +2 -2
  19. package/dist/index.d.ts +2 -1
  20. package/dist/iter/asyncIterable2.d.ts +3 -2
  21. package/dist/iter/iterable2.d.ts +2 -1
  22. package/dist/json-schema/jsonSchema.util.d.ts +1 -1
  23. package/dist/object/object.util.d.ts +2 -1
  24. package/dist/promise/abortable.d.ts +1 -1
  25. package/dist/promise/pDelay.d.ts +1 -1
  26. package/dist/promise/pTimeout.d.ts +1 -1
  27. package/dist/semver.d.ts +1 -1
  28. package/dist/string/hash.util.d.ts +1 -1
  29. package/dist/string/json.util.d.ts +1 -1
  30. package/dist/web.d.ts +1 -1
  31. package/dist-esm/array/array.util.js +1 -1
  32. package/dist-esm/datetime/localTime.js +3 -0
  33. package/dist-esm/datetime/wallTime.js +26 -0
  34. package/dist-esm/decorators/asyncMemo.decorator.js +1 -1
  35. package/dist-esm/env.js +2 -3
  36. package/dist-esm/object/object.util.js +1 -1
  37. package/package.json +5 -4
  38. package/src/array/array.util.ts +2 -2
  39. package/src/browser/adminService.ts +1 -1
  40. package/src/browser/i18n/fetchTranslationLoader.ts +3 -3
  41. package/src/browser/i18n/translation.service.ts +1 -1
  42. package/src/datetime/dateInterval.ts +3 -2
  43. package/src/datetime/localDate.ts +2 -1
  44. package/src/datetime/localTime.ts +6 -1
  45. package/src/datetime/timeInterval.ts +2 -1
  46. package/src/datetime/wallTime.ts +33 -2
  47. package/src/decorators/asyncMemo.decorator.ts +4 -9
  48. package/src/decorators/memo.decorator.ts +4 -3
  49. package/src/decorators/memoFn.ts +1 -1
  50. package/src/decorators/memoFnAsync.ts +2 -1
  51. package/src/decorators/swarmSafe.decorator.ts +1 -1
  52. package/src/env.ts +2 -3
  53. package/src/error/error.model.ts +2 -2
  54. package/src/http/fetcher.ts +3 -3
  55. package/src/index.ts +2 -1
  56. package/src/iter/asyncIterable2.ts +3 -2
  57. package/src/iter/iterable2.ts +2 -1
  58. package/src/json-schema/jsonSchema.util.ts +2 -1
  59. package/src/object/object.util.ts +2 -3
  60. package/src/promise/abortable.ts +1 -1
  61. package/src/promise/pDelay.ts +2 -1
  62. package/src/promise/pTimeout.ts +2 -1
  63. package/src/semver.ts +1 -1
  64. package/src/string/hash.util.ts +1 -1
  65. package/src/string/json.util.ts +1 -1
  66. 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,4 +1,4 @@
1
- import { Promisable } from '../typeFest';
1
+ import type { Promisable } from '../typeFest';
2
2
  export interface AdminModeCfg {
3
3
  /**
4
4
  * Function (predicate) to detect if needed keys are pressed.
@@ -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 { DateTimeObject } from './localTime';
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.
@@ -1,4 +1,4 @@
1
- import { AnyFunction } from '../types';
1
+ import type { AnyFunction } from '../types';
2
2
  import type { MemoOptions } from './memo.decorator';
3
3
  import type { MemoCache } from './memo.util';
4
4
  export interface MemoizedFunction {
@@ -1,4 +1,4 @@
1
- import { AnyAsyncFunction } from '../types';
1
+ import type { AnyAsyncFunction } from '../types';
2
2
  import type { AsyncMemoOptions } from './asyncMemo.decorator';
3
3
  import type { AsyncMemoCache } from './memo.util';
4
4
  export interface MemoizedAsyncFunction {
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
- // eslint-disable-next-line unicorn/prefer-global-this
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
  */
@@ -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 { z, ZodError, ZodIssue, ZodSchema } from 'zod';
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, END } from '../types';
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
  *
@@ -1,4 +1,5 @@
1
- import { AbortableMapper, AbortablePredicate, END } from '../types';
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,4 @@
1
- import { AnyObject } from '../index';
1
+ import type { AnyObject } from '../index';
2
2
  import type { JsonSchemaObject } from './jsonSchema.model';
3
3
  /**
4
4
  * Merges s2 into s1 (mutates s1) and returns s1.
@@ -1,4 +1,5 @@
1
- import { AnyObject, KeyValueTuple, ObjectMapper, ObjectPredicate, Reviver, SKIP, ValueOf } from '../types';
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.
@@ -1,4 +1,4 @@
1
- import { AnyFunction } from '../types';
1
+ import type { AnyFunction } from '../types';
2
2
  /**
3
3
  * Similar to AbortController and AbortSignal.
4
4
  * Similar to pDefer and Promise.
@@ -1,5 +1,5 @@
1
1
  import type { NumberOfMilliseconds, PromisableFunction } from '../types';
2
- import { DeferredPromise } from './pDefer';
2
+ import type { DeferredPromise } from './pDefer';
3
3
  /**
4
4
  * Promisified version of setTimeout.
5
5
  *
@@ -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];
@@ -1,4 +1,4 @@
1
- import { Integer } from '../types';
1
+ import type { Integer } from '../types';
2
2
  /**
3
3
  * Returns hashCode as hex (radix 16).
4
4
  *
@@ -1,4 +1,4 @@
1
- import { Reviver } from '../types';
1
+ import type { Reviver } from '../types';
2
2
  /**
3
3
  * Attempts to parse object as JSON.
4
4
  * Returns original object if JSON parse failed (silently).
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, } from '../types';
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, } from '../types';
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
- // eslint-disable-next-line unicorn/prefer-global-this
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
  }
@@ -1,5 +1,5 @@
1
1
  import { _isEmpty, _isObject } from '../is.util';
2
- import { _objectEntries, SKIP, } from '../types';
2
+ import { _objectEntries, SKIP } from '../types';
3
3
  /**
4
4
  * Returns clone of `obj` with only `props` preserved.
5
5
  * Opposite of Omit.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.273.0",
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": "^15",
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
- "jest": "^29",
32
- "prettier": "^3",
32
+ "tsx": "^4.19.3",
33
33
  "vitepress": "^1",
34
+ "vitest": "^3",
34
35
  "vue": "^3"
35
36
  },
36
37
  "files": [
@@ -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,5 @@
1
1
  import { pMap } from '../../promise/pMap'
2
- import { StringMap } from '../../types'
2
+ import type { StringMap } from '../../types'
3
3
 
4
4
  export type MissingTranslationHandler = (key: string, params?: StringMap<any>) => string
5
5
 
@@ -1,5 +1,6 @@
1
- import { Inclusiveness, IsoDate } from '../types'
2
- import { LocalDate, localDate, LocalDateInput, LocalDateUnit } from './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, localTime, VALID_DAYS_OF_WEEK } from './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, localDate } from './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, localTime, LocalTimeInput } from './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
@@ -1,5 +1,7 @@
1
- import { IsoDate } from '../types'
2
- import { DateTimeObject } from './localTime'
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
- _objectAssign,
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, jsonMemoSerializer, MethodDecorator } from './memo.util'
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 { _objectAssign, AnyFunction, AnyObject, MaybeParameters } from '../types'
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, MethodDecorator } from './memo.util'
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
  /**
@@ -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, MISS } from '../types'
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'
@@ -1,4 +1,4 @@
1
- import { AnyObject } from '../types'
1
+ import type { AnyObject } from '../types'
2
2
  import { _getTargetMethodSignature } from './decorator.util'
3
3
 
4
4
  /**
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
- // eslint-disable-next-line unicorn/prefer-global-this
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
  }
@@ -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.
@@ -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 { z, ZodError, ZodIssue, ZodSchema } from 'zod'
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, END, SKIP } from '../types'
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.
@@ -1,4 +1,5 @@
1
- import { AbortableMapper, AbortablePredicate, END, SKIP } from '../types'
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,4 +1,5 @@
1
- import { _uniq, AnyObject } from '../index'
1
+ import type { AnyObject } from '../index'
2
+ import { _uniq } from '../index'
2
3
  import { _filterNullishValues } from '../object/object.util'
3
4
  import type { JsonSchemaObject } from './jsonSchema.model'
4
5
 
@@ -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.
@@ -1,4 +1,4 @@
1
- import { AnyFunction } from '../types'
1
+ import type { AnyFunction } from '../types'
2
2
 
3
3
  /**
4
4
  * Similar to AbortController and AbortSignal.
@@ -1,5 +1,6 @@
1
1
  import type { NumberOfMilliseconds, PromisableFunction } from '../types'
2
- import { DeferredPromise, pDefer } from './pDefer'
2
+ import type { DeferredPromise } from './pDefer'
3
+ import { pDefer } from './pDefer'
3
4
 
4
5
  /**
5
6
  * Promisified version of setTimeout.
@@ -1,6 +1,7 @@
1
1
  import type { ErrorData } from '../error/error.model'
2
2
  import { _errorDataAppend, TimeoutError } from '../error/error.util'
3
- import { _typeCast, AnyAsyncFunction, NumberOfMilliseconds } from '../types'
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
@@ -1,4 +1,4 @@
1
- import { Integer } from '../types'
1
+ import type { Integer } from '../types'
2
2
 
3
3
  const BASE62 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
4
4
  // const BASE64 = BASE62 + '+/'
@@ -1,5 +1,5 @@
1
1
  import { JsonParseError } from '../error/error.util'
2
- import { Reviver } from '../types'
2
+ import type { Reviver } from '../types'
3
3
 
4
4
  // const possibleJsonStartTokens = ['{', '[', '"']
5
5
  const DETECT_JSON = /^\s*[{["\-\d]/
package/src/web.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference lib="es2022" preserve="true" />
2
2
  /// <reference lib="dom" preserve="true" />
3
3
 
4
- import { StringMap } from './types'
4
+ import type { StringMap } from './types'
5
5
 
6
6
  /**
7
7
  * Implements WebStorage API by using in-memory storage.