@naturalcycles/js-lib 15.79.0 → 15.80.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.
@@ -57,6 +57,7 @@ export declare class AdminService {
57
57
  cfg: Required<AdminModeCfg>;
58
58
  adminMode: boolean;
59
59
  private listening;
60
+ private readonly boundKeydownListener;
60
61
  /**
61
62
  * Start listening to keyboard events to toggle AdminMode when detected.
62
63
  */
@@ -28,6 +28,7 @@ export class AdminService {
28
28
  cfg;
29
29
  adminMode = false;
30
30
  listening = false;
31
+ boundKeydownListener = this.keydownListener.bind(this);
31
32
  /**
32
33
  * Start listening to keyboard events to toggle AdminMode when detected.
33
34
  */
@@ -37,13 +38,13 @@ export class AdminService {
37
38
  this.adminMode = !!localStorage.getItem(this.cfg.localStorageKey);
38
39
  if (this.adminMode)
39
40
  this.toggleRedDotVisibility();
40
- document.addEventListener('keydown', this.keydownListener.bind(this), { passive: true });
41
+ document.addEventListener('keydown', this.boundKeydownListener, { passive: true });
41
42
  this.listening = true;
42
43
  }
43
44
  stopListening() {
44
45
  if (isServerSide())
45
46
  return;
46
- document.removeEventListener('keydown', this.keydownListener);
47
+ document.removeEventListener('keydown', this.boundKeydownListener);
47
48
  this.listening = false;
48
49
  }
49
50
  async keydownListener(e) {
@@ -46,7 +46,7 @@ export class LocalDate {
46
46
  return this.set('day', v);
47
47
  }
48
48
  get dayOfWeek() {
49
- return (this.toDate().getDay() || 7);
49
+ return this.toDate().getDay() || 7;
50
50
  }
51
51
  /**
52
52
  * Returns LocalDate for the given DayOfWeek (e.g Monday), that is in the same week as this.
@@ -219,7 +219,7 @@ export class LocalTime {
219
219
  * Based on ISO: 1-7 is Mon-Sun.
220
220
  */
221
221
  get dayOfWeek() {
222
- return (this.$date.getDay() || 7);
222
+ return this.$date.getDay() || 7;
223
223
  }
224
224
  /**
225
225
  * Returns LocalTime for the given DayOfWeek (e.g Monday), that is in the same week as this.
@@ -16,11 +16,13 @@ declare class MemoizedIntl {
16
16
  getTimezone(): IANATimezone;
17
17
  DateTimeFormat(locales: Intl.LocalesArgument, options: Intl.DateTimeFormatOptions): Intl.DateTimeFormat;
18
18
  RelativeTimeFormat(locales: Intl.LocalesArgument, options: Intl.RelativeTimeFormatOptions): Intl.RelativeTimeFormat;
19
+ DurationFormat(locales: Intl.LocalesArgument, options: Intl.DurationFormatOptions): Intl.DurationFormat;
19
20
  NumberFormat(locales: Intl.LocalesArgument, options: Intl.NumberFormatOptions): Intl.NumberFormat;
20
21
  Collator(locales: Intl.LocalesArgument, options: Intl.CollatorOptions): Intl.Collator;
21
22
  PluralRules(locales: Intl.LocalesArgument, options: Intl.PluralRulesOptions): Intl.PluralRules;
22
23
  ListFormat(locales: Intl.LocalesArgument, options: Intl.ListFormatOptions): Intl.ListFormat;
23
24
  DisplayNames(locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames;
25
+ Segmenter(locales: Intl.LocalesArgument, options: Intl.SegmenterOptions): Intl.Segmenter;
24
26
  }
25
27
  export declare const Intl2: MemoizedIntl;
26
28
  export {};
package/dist/intl/intl.js CHANGED
@@ -24,6 +24,9 @@ class MemoizedIntl {
24
24
  RelativeTimeFormat(locales, options) {
25
25
  return new Intl.RelativeTimeFormat(locales, options);
26
26
  }
27
+ DurationFormat(locales, options) {
28
+ return new Intl.DurationFormat(locales, options);
29
+ }
27
30
  NumberFormat(locales, options) {
28
31
  return new Intl.NumberFormat(locales, options);
29
32
  }
@@ -39,6 +42,9 @@ class MemoizedIntl {
39
42
  DisplayNames(locales, options) {
40
43
  return new Intl.DisplayNames(locales, options);
41
44
  }
45
+ Segmenter(locales, options) {
46
+ return new Intl.Segmenter(locales, options);
47
+ }
42
48
  }
43
49
  __decorate([
44
50
  _Memo()
@@ -49,6 +55,9 @@ __decorate([
49
55
  __decorate([
50
56
  _Memo()
51
57
  ], MemoizedIntl.prototype, "RelativeTimeFormat", null);
58
+ __decorate([
59
+ _Memo()
60
+ ], MemoizedIntl.prototype, "DurationFormat", null);
52
61
  __decorate([
53
62
  _Memo()
54
63
  ], MemoizedIntl.prototype, "NumberFormat", null);
@@ -64,4 +73,7 @@ __decorate([
64
73
  __decorate([
65
74
  _Memo()
66
75
  ], MemoizedIntl.prototype, "DisplayNames", null);
76
+ __decorate([
77
+ _Memo()
78
+ ], MemoizedIntl.prototype, "Segmenter", null);
67
79
  export const Intl2 = new MemoizedIntl();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
3
  "type": "module",
4
- "version": "15.79.0",
4
+ "version": "15.80.0",
5
5
  "dependencies": {
6
6
  "tslib": "^2"
7
7
  },
@@ -15,11 +15,11 @@
15
15
  },
16
16
  "devDependencies": {
17
17
  "@types/crypto-js": "^4",
18
- "@types/node": "^25",
18
+ "@types/node": "^26",
19
19
  "@types/semver": "^7",
20
- "@typescript/native-preview": "beta",
21
20
  "crypto-js": "^4",
22
21
  "dayjs": "^1",
22
+ "typescript": "rc",
23
23
  "@naturalcycles/dev-lib": "18.4.2"
24
24
  },
25
25
  "exports": {
@@ -495,7 +495,7 @@ export function _minOrUndefined<T>(array: readonly T[]): NonNullable<T> | undefi
495
495
  for (const item of array) {
496
496
  if (item === undefined || item === null) continue
497
497
  if (min === undefined || item < min) {
498
- min = item as NonNullable<T>
498
+ min = item
499
499
  }
500
500
  }
501
501
  return min
@@ -515,7 +515,7 @@ export function _maxOrUndefined<T>(array: readonly T[]): NonNullable<T> | undefi
515
515
  for (const item of array) {
516
516
  if (item === undefined || item === null) continue
517
517
  if (max === undefined || item > max) {
518
- max = item as NonNullable<T>
518
+ max = item
519
519
  }
520
520
  }
521
521
  return max
@@ -86,6 +86,8 @@ export class AdminService {
86
86
 
87
87
  private listening = false
88
88
 
89
+ private readonly boundKeydownListener = this.keydownListener.bind(this)
90
+
89
91
  /**
90
92
  * Start listening to keyboard events to toggle AdminMode when detected.
91
93
  */
@@ -96,14 +98,14 @@ export class AdminService {
96
98
 
97
99
  if (this.adminMode) this.toggleRedDotVisibility()
98
100
 
99
- document.addEventListener('keydown', this.keydownListener.bind(this), { passive: true })
101
+ document.addEventListener('keydown', this.boundKeydownListener, { passive: true })
100
102
 
101
103
  this.listening = true
102
104
  }
103
105
 
104
106
  stopListening(): void {
105
107
  if (isServerSide()) return
106
- document.removeEventListener('keydown', this.keydownListener)
108
+ document.removeEventListener('keydown', this.boundKeydownListener)
107
109
  this.listening = false
108
110
  }
109
111
 
@@ -70,7 +70,7 @@ export class LocalDate {
70
70
  }
71
71
 
72
72
  get dayOfWeek(): ISODayOfWeek {
73
- return (this.toDate().getDay() || 7) as ISODayOfWeek
73
+ return this.toDate().getDay() || 7
74
74
  }
75
75
 
76
76
  /**
@@ -275,7 +275,7 @@ export class LocalTime {
275
275
  * Based on ISO: 1-7 is Mon-Sun.
276
276
  */
277
277
  get dayOfWeek(): ISODayOfWeek {
278
- return (this.$date.getDay() || 7) as ISODayOfWeek
278
+ return this.$date.getDay() || 7
279
279
  }
280
280
 
281
281
  /**
@@ -15,7 +15,7 @@ export function _blockTimer(name?: string): Disposable {
15
15
  [Symbol.dispose](): void {
16
16
  console.log(`${name ? name + ' ' : ''}took ${_since(started)}`)
17
17
  },
18
- } as any
18
+ }
19
19
  }
20
20
 
21
21
  /**
@@ -62,7 +62,7 @@ export function _debounce<T extends AnyFunction>(
62
62
  }
63
63
 
64
64
  function startTimer(pendingFunc: AnyFunction, wait: number): number {
65
- return setTimeout(pendingFunc, wait) as any
65
+ return setTimeout(pendingFunc, wait)
66
66
  }
67
67
 
68
68
  function cancelTimer(id: number): void {
@@ -619,7 +619,7 @@ export class Fetcher {
619
619
  timeout = Number(retryAfterStr) * 1000
620
620
  } else {
621
621
  const date = new Date(retryAfterStr)
622
- if (!Number.isNaN(date as any)) {
622
+ if (!Number.isNaN(date)) {
623
623
  timeout = Number(date) - Date.now()
624
624
  }
625
625
  }
package/src/intl/intl.ts CHANGED
@@ -38,6 +38,14 @@ class MemoizedIntl {
38
38
  return new Intl.RelativeTimeFormat(locales, options)
39
39
  }
40
40
 
41
+ @_Memo()
42
+ DurationFormat(
43
+ locales: Intl.LocalesArgument,
44
+ options: Intl.DurationFormatOptions,
45
+ ): Intl.DurationFormat {
46
+ return new Intl.DurationFormat(locales, options)
47
+ }
48
+
41
49
  @_Memo()
42
50
  NumberFormat(
43
51
  locales: Intl.LocalesArgument,
@@ -68,6 +76,11 @@ class MemoizedIntl {
68
76
  ): Intl.DisplayNames {
69
77
  return new Intl.DisplayNames(locales, options)
70
78
  }
79
+
80
+ @_Memo()
81
+ Segmenter(locales: Intl.LocalesArgument, options: Intl.SegmenterOptions): Intl.Segmenter {
82
+ return new Intl.Segmenter(locales, options)
83
+ }
71
84
  }
72
85
 
73
86
  export const Intl2 = new MemoizedIntl()
@@ -239,7 +239,7 @@ export function _mapObject<OUT = unknown, IN extends AnyObject = AnyObject>(
239
239
  }
240
240
 
241
241
  export function _findKeyByValue<T extends AnyObject>(obj: T, v: ValueOf<T>): keyof T | undefined {
242
- return Object.entries(obj).find(([_, value]) => value === v)?.[0] as keyof T
242
+ return Object.entries(obj).find(([_, value]) => value === v)?.[0]
243
243
  }
244
244
 
245
245
  /**
@@ -256,7 +256,7 @@ export function _findKeyByValue<T extends AnyObject>(obj: T, v: ValueOf<T>): key
256
256
  */
257
257
  export function _firstKey<T extends AnyObject>(obj: T): keyof T {
258
258
  for (const k in obj) {
259
- if (Object.hasOwn(obj, k)) return k as keyof T
259
+ if (Object.hasOwn(obj, k)) return k
260
260
  }
261
261
  throw new Error('_firstKey called on empty object')
262
262
  }
@@ -267,7 +267,7 @@ export function _firstKey<T extends AnyObject>(obj: T): keyof T {
267
267
  */
268
268
  export function _firstKeyOrUndefined<T extends AnyObject>(obj: T): keyof T | undefined {
269
269
  for (const k in obj) {
270
- if (Object.hasOwn(obj, k)) return k as keyof T
270
+ if (Object.hasOwn(obj, k)) return k
271
271
  }
272
272
  return undefined
273
273
  }
@@ -279,7 +279,7 @@ export function _firstKeyOrUndefined<T extends AnyObject>(obj: T): keyof T | und
279
279
  */
280
280
  export function _firstValue<T extends AnyObject>(obj: T): ValueOf<T> {
281
281
  for (const k in obj) {
282
- if (Object.hasOwn(obj, k)) return obj[k] as ValueOf<T>
282
+ if (Object.hasOwn(obj, k)) return obj[k]
283
283
  }
284
284
  throw new Error('_firstValue called on empty object')
285
285
  }
@@ -290,7 +290,7 @@ export function _firstValue<T extends AnyObject>(obj: T): ValueOf<T> {
290
290
  */
291
291
  export function _firstValueOrUndefined<T extends AnyObject>(obj: T): ValueOf<T> | undefined {
292
292
  for (const k in obj) {
293
- if (Object.hasOwn(obj, k)) return obj[k] as ValueOf<T>
293
+ if (Object.hasOwn(obj, k)) return obj[k]
294
294
  }
295
295
  return undefined
296
296
  }
@@ -302,7 +302,7 @@ export function _firstValueOrUndefined<T extends AnyObject>(obj: T): ValueOf<T>
302
302
  */
303
303
  export function _firstEntry<T extends AnyObject>(obj: T): [keyof T, ValueOf<T>] {
304
304
  for (const k in obj) {
305
- if (Object.hasOwn(obj, k)) return [k as keyof T, obj[k] as ValueOf<T>]
305
+ if (Object.hasOwn(obj, k)) return [k, obj[k]]
306
306
  }
307
307
  throw new Error('_firstEntry called on empty object')
308
308
  }
@@ -315,7 +315,7 @@ export function _firstEntryOrUndefined<T extends AnyObject>(
315
315
  obj: T,
316
316
  ): [keyof T, ValueOf<T>] | undefined {
317
317
  for (const k in obj) {
318
- if (Object.hasOwn(obj, k)) return [k as keyof T, obj[k] as ValueOf<T>]
318
+ if (Object.hasOwn(obj, k)) return [k, obj[k]]
319
319
  }
320
320
  return undefined
321
321
  }
@@ -519,13 +519,13 @@ type PropertyPath = Many<PropertyKey>
519
519
  * Based on: https://stackoverflow.com/a/54733755/4919972
520
520
  */
521
521
  export function _set<T extends AnyObject>(obj: T, path: PropertyPath, value: any): T {
522
- if (!obj || Object(obj) !== obj || !path) return obj as any // When obj is not an object
522
+ if (!obj || Object(obj) !== obj || !path) return obj // When obj is not an object
523
523
 
524
524
  // If not yet an array, get the keys from the string-path
525
525
  if (!Array.isArray(path)) {
526
526
  path = String(path).match(/[^.[\]]+/g) || []
527
527
  } else if (!path.length) {
528
- return obj as any
528
+ return obj
529
529
  }
530
530
 
531
531
  // Prevent prototype pollution