@naturalcycles/js-lib 14.261.0 → 14.262.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.
@@ -51,6 +51,7 @@ const repaint = () => {
51
51
  };
52
52
  const createCanvas = () => {
53
53
  canvas = document.createElement('canvas');
54
+ canvas.ariaHidden = 'true';
54
55
  const style = canvas.style;
55
56
  style.position = 'fixed';
56
57
  style.top = style.left = style.right = style.margin = style.padding = 0;
@@ -21,6 +21,18 @@ export declare class LocalDate {
21
21
  setMonth(v: number): LocalDate;
22
22
  setDay(v: number): LocalDate;
23
23
  get dayOfWeek(): ISODayOfWeek;
24
+ /**
25
+ * Returns LocalDate for the given DayOfWeek (e.g Monday), that is in the same week as this.
26
+ * It may move the time into the future, or the past, depending on how the desired DayOfWeek is in
27
+ * relation to `this`.
28
+ */
29
+ setDayOfWeek(dow: ISODayOfWeek): LocalDate;
30
+ /**
31
+ * Returns LocalDate for the given DayOfWeek (e.g Monday), that is in the future,
32
+ * in relation to this.
33
+ * If this LocalDate is Monday, and desired DoW is also Monday - `this` is returned.
34
+ */
35
+ setNextDayOfWeek(dow: ISODayOfWeek): LocalDate;
24
36
  isSame(d: LocalDateInput): boolean;
25
37
  isBefore(d: LocalDateInput, inclusive?: boolean): boolean;
26
38
  isSameOrBefore(d: LocalDateInput): boolean;
@@ -48,6 +48,28 @@ class LocalDate {
48
48
  get dayOfWeek() {
49
49
  return (this.toDate().getDay() || 7);
50
50
  }
51
+ /**
52
+ * Returns LocalDate for the given DayOfWeek (e.g Monday), that is in the same week as this.
53
+ * It may move the time into the future, or the past, depending on how the desired DayOfWeek is in
54
+ * relation to `this`.
55
+ */
56
+ setDayOfWeek(dow) {
57
+ (0, assert_1._assert)(localTime_1.VALID_DAYS_OF_WEEK.has(dow), `Invalid dayOfWeek: ${dow}`);
58
+ const delta = dow - this.dayOfWeek;
59
+ return this.plus(delta, 'day');
60
+ }
61
+ /**
62
+ * Returns LocalDate for the given DayOfWeek (e.g Monday), that is in the future,
63
+ * in relation to this.
64
+ * If this LocalDate is Monday, and desired DoW is also Monday - `this` is returned.
65
+ */
66
+ setNextDayOfWeek(dow) {
67
+ (0, assert_1._assert)(localTime_1.VALID_DAYS_OF_WEEK.has(dow), `Invalid dayOfWeek: ${dow}`);
68
+ let delta = dow - this.dayOfWeek;
69
+ if (delta < 0)
70
+ delta += 7;
71
+ return this.plus(delta, 'day');
72
+ }
51
73
  isSame(d) {
52
74
  d = exports.localDate.fromInput(d);
53
75
  return this.day === d.day && this.month === d.month && this.year === d.year;
@@ -26,6 +26,7 @@ export interface TimeObject {
26
26
  minute: number;
27
27
  second: number;
28
28
  }
29
+ export declare const VALID_DAYS_OF_WEEK: Set<number>;
29
30
  export declare class LocalTime {
30
31
  $date: Date;
31
32
  constructor($date: Date);
@@ -104,7 +105,18 @@ export declare class LocalTime {
104
105
  * Based on ISO: 1-7 is Mon-Sun.
105
106
  */
106
107
  get dayOfWeek(): ISODayOfWeek;
107
- setDayOfWeek(v: ISODayOfWeek): LocalTime;
108
+ /**
109
+ * Returns LocalTime for the given DayOfWeek (e.g Monday), that is in the same week as this.
110
+ * It may move the time into the future, or the past, depending on how the desired DayOfWeek is in
111
+ * relation to `this`.
112
+ */
113
+ setDayOfWeek(dow: ISODayOfWeek): LocalTime;
114
+ /**
115
+ * Returns LocalTime for the given DayOfWeek (e.g Monday), that is in the future,
116
+ * in relation to this.
117
+ * If this LocalTime is Monday, and desired DoW is also Monday - `this` is returned.
118
+ */
119
+ setNextDayOfWeek(dow: ISODayOfWeek): LocalTime;
108
120
  setComponents(c: Partial<DateTimeObject>, mutate?: boolean): LocalTime;
109
121
  plusSeconds(num: number): LocalTime;
110
122
  plusMinutes(num: number): LocalTime;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.localTime = exports.LocalTime = exports.ISODayOfWeek = void 0;
3
+ exports.localTime = exports.LocalTime = exports.VALID_DAYS_OF_WEEK = exports.ISODayOfWeek = void 0;
4
4
  const assert_1 = require("../error/assert");
5
5
  const time_util_1 = require("../time/time.util");
6
6
  const localDate_1 = require("./localDate");
@@ -20,7 +20,7 @@ const MILLISECONDS_IN_WEEK = 604800000;
20
20
  const SECONDS_IN_DAY = 86400;
21
21
  // const MILLISECONDS_IN_DAY = 86400000
22
22
  // const MILLISECONDS_IN_MINUTE = 60000
23
- const VALID_DAYS_OF_WEEK = new Set([1, 2, 3, 4, 5, 6, 7]);
23
+ exports.VALID_DAYS_OF_WEEK = new Set([1, 2, 3, 4, 5, 6, 7]);
24
24
  /**
25
25
  * It supports 2 forms:
26
26
  * 1. 2023-03-03
@@ -221,10 +221,27 @@ class LocalTime {
221
221
  get dayOfWeek() {
222
222
  return (this.$date.getDay() || 7);
223
223
  }
224
- setDayOfWeek(v) {
225
- (0, assert_1._assert)(VALID_DAYS_OF_WEEK.has(v), `Invalid dayOfWeek: ${v}`);
226
- const dow = this.$date.getDay() || 7;
227
- return this.plus(v - dow, 'day');
224
+ /**
225
+ * Returns LocalTime for the given DayOfWeek (e.g Monday), that is in the same week as this.
226
+ * It may move the time into the future, or the past, depending on how the desired DayOfWeek is in
227
+ * relation to `this`.
228
+ */
229
+ setDayOfWeek(dow) {
230
+ (0, assert_1._assert)(exports.VALID_DAYS_OF_WEEK.has(dow), `Invalid dayOfWeek: ${dow}`);
231
+ const delta = dow - this.dayOfWeek;
232
+ return this.plus(delta, 'day');
233
+ }
234
+ /**
235
+ * Returns LocalTime for the given DayOfWeek (e.g Monday), that is in the future,
236
+ * in relation to this.
237
+ * If this LocalTime is Monday, and desired DoW is also Monday - `this` is returned.
238
+ */
239
+ setNextDayOfWeek(dow) {
240
+ (0, assert_1._assert)(exports.VALID_DAYS_OF_WEEK.has(dow), `Invalid dayOfWeek: ${dow}`);
241
+ let delta = dow - this.dayOfWeek;
242
+ if (delta < 0)
243
+ delta += 7;
244
+ return this.plus(delta, 'day');
228
245
  }
229
246
  setComponents(c, mutate = false) {
230
247
  const d = mutate ? this.$date : new Date(this.$date);
@@ -14,7 +14,7 @@ export declare const jsonSchema: {
14
14
  ref<T = unknown>($ref: string): JsonSchemaAnyBuilder<T, JsonSchemaRef<T>>;
15
15
  enum<T = unknown>(enumValues: T[]): JsonSchemaAnyBuilder<T, JsonSchemaEnum<T>>;
16
16
  boolean(): JsonSchemaAnyBuilder<boolean, JsonSchemaBoolean>;
17
- buffer(): JsonSchemaAnyBuilder<Buffer, JsonSchemaAny<Buffer>>;
17
+ buffer(): JsonSchemaAnyBuilder<Buffer<ArrayBufferLike>, JsonSchemaAny<Buffer<ArrayBufferLike>>>;
18
18
  number(): JsonSchemaNumberBuilder;
19
19
  integer(): JsonSchemaNumberBuilder;
20
20
  unixTimestamp(): JsonSchemaNumberBuilder;
@@ -48,6 +48,7 @@ const repaint = () => {
48
48
  };
49
49
  const createCanvas = () => {
50
50
  canvas = document.createElement('canvas');
51
+ canvas.ariaHidden = 'true';
51
52
  const style = canvas.style;
52
53
  style.position = 'fixed';
53
54
  style.top = style.left = style.right = style.margin = style.padding = 0;
@@ -1,6 +1,6 @@
1
1
  import { _assert } from '../error/assert';
2
2
  import { Iterable2 } from '../iter/iterable2';
3
- import { localTime } from './localTime';
3
+ import { localTime, VALID_DAYS_OF_WEEK } from './localTime';
4
4
  const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
5
5
  /**
6
6
  * Regex is open-ended (no $ at the end) to support e.g Date+Time string to be parsed (time part will be dropped)
@@ -45,6 +45,28 @@ export class LocalDate {
45
45
  get dayOfWeek() {
46
46
  return (this.toDate().getDay() || 7);
47
47
  }
48
+ /**
49
+ * Returns LocalDate for the given DayOfWeek (e.g Monday), that is in the same week as this.
50
+ * It may move the time into the future, or the past, depending on how the desired DayOfWeek is in
51
+ * relation to `this`.
52
+ */
53
+ setDayOfWeek(dow) {
54
+ _assert(VALID_DAYS_OF_WEEK.has(dow), `Invalid dayOfWeek: ${dow}`);
55
+ const delta = dow - this.dayOfWeek;
56
+ return this.plus(delta, 'day');
57
+ }
58
+ /**
59
+ * Returns LocalDate for the given DayOfWeek (e.g Monday), that is in the future,
60
+ * in relation to this.
61
+ * If this LocalDate is Monday, and desired DoW is also Monday - `this` is returned.
62
+ */
63
+ setNextDayOfWeek(dow) {
64
+ _assert(VALID_DAYS_OF_WEEK.has(dow), `Invalid dayOfWeek: ${dow}`);
65
+ let delta = dow - this.dayOfWeek;
66
+ if (delta < 0)
67
+ delta += 7;
68
+ return this.plus(delta, 'day');
69
+ }
48
70
  isSame(d) {
49
71
  d = localDate.fromInput(d);
50
72
  return this.day === d.day && this.month === d.month && this.year === d.year;
@@ -17,7 +17,7 @@ const MILLISECONDS_IN_WEEK = 604800000;
17
17
  const SECONDS_IN_DAY = 86400;
18
18
  // const MILLISECONDS_IN_DAY = 86400000
19
19
  // const MILLISECONDS_IN_MINUTE = 60000
20
- const VALID_DAYS_OF_WEEK = new Set([1, 2, 3, 4, 5, 6, 7]);
20
+ export const VALID_DAYS_OF_WEEK = new Set([1, 2, 3, 4, 5, 6, 7]);
21
21
  /**
22
22
  * It supports 2 forms:
23
23
  * 1. 2023-03-03
@@ -218,10 +218,27 @@ export class LocalTime {
218
218
  get dayOfWeek() {
219
219
  return (this.$date.getDay() || 7);
220
220
  }
221
- setDayOfWeek(v) {
222
- _assert(VALID_DAYS_OF_WEEK.has(v), `Invalid dayOfWeek: ${v}`);
223
- const dow = this.$date.getDay() || 7;
224
- return this.plus(v - dow, 'day');
221
+ /**
222
+ * Returns LocalTime for the given DayOfWeek (e.g Monday), that is in the same week as this.
223
+ * It may move the time into the future, or the past, depending on how the desired DayOfWeek is in
224
+ * relation to `this`.
225
+ */
226
+ setDayOfWeek(dow) {
227
+ _assert(VALID_DAYS_OF_WEEK.has(dow), `Invalid dayOfWeek: ${dow}`);
228
+ const delta = dow - this.dayOfWeek;
229
+ return this.plus(delta, 'day');
230
+ }
231
+ /**
232
+ * Returns LocalTime for the given DayOfWeek (e.g Monday), that is in the future,
233
+ * in relation to this.
234
+ * If this LocalTime is Monday, and desired DoW is also Monday - `this` is returned.
235
+ */
236
+ setNextDayOfWeek(dow) {
237
+ _assert(VALID_DAYS_OF_WEEK.has(dow), `Invalid dayOfWeek: ${dow}`);
238
+ let delta = dow - this.dayOfWeek;
239
+ if (delta < 0)
240
+ delta += 7;
241
+ return this.plus(delta, 'day');
225
242
  }
226
243
  setComponents(c, mutate = false) {
227
244
  const d = mutate ? this.$date : new Date(this.$date);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.261.0",
3
+ "version": "14.262.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build-esm-cjs",
@@ -69,6 +69,7 @@ const repaint = () => {
69
69
  }
70
70
  const createCanvas = () => {
71
71
  canvas = document.createElement('canvas')
72
+ canvas.ariaHidden = 'true'
72
73
  const style = canvas.style
73
74
  style.position = 'fixed'
74
75
  style.top = style.left = style.right = style.margin = style.padding = 0
@@ -9,7 +9,7 @@ import type {
9
9
  UnixTimestamp,
10
10
  UnixTimestampMillis,
11
11
  } from '../types'
12
- import { DateObject, ISODayOfWeek, LocalTime, localTime } from './localTime'
12
+ import { DateObject, ISODayOfWeek, LocalTime, localTime, VALID_DAYS_OF_WEEK } from './localTime'
13
13
 
14
14
  export type LocalDateUnit = LocalDateUnitStrict | 'week'
15
15
  export type LocalDateUnitStrict = 'year' | 'month' | 'day'
@@ -70,6 +70,29 @@ export class LocalDate {
70
70
  return (this.toDate().getDay() || 7) as ISODayOfWeek
71
71
  }
72
72
 
73
+ /**
74
+ * Returns LocalDate for the given DayOfWeek (e.g Monday), that is in the same week as this.
75
+ * It may move the time into the future, or the past, depending on how the desired DayOfWeek is in
76
+ * relation to `this`.
77
+ */
78
+ setDayOfWeek(dow: ISODayOfWeek): LocalDate {
79
+ _assert(VALID_DAYS_OF_WEEK.has(dow), `Invalid dayOfWeek: ${dow}`)
80
+ const delta = dow - this.dayOfWeek
81
+ return this.plus(delta, 'day')
82
+ }
83
+
84
+ /**
85
+ * Returns LocalDate for the given DayOfWeek (e.g Monday), that is in the future,
86
+ * in relation to this.
87
+ * If this LocalDate is Monday, and desired DoW is also Monday - `this` is returned.
88
+ */
89
+ setNextDayOfWeek(dow: ISODayOfWeek): LocalDate {
90
+ _assert(VALID_DAYS_OF_WEEK.has(dow), `Invalid dayOfWeek: ${dow}`)
91
+ let delta = dow - this.dayOfWeek
92
+ if (delta < 0) delta += 7
93
+ return this.plus(delta, 'day')
94
+ }
95
+
73
96
  isSame(d: LocalDateInput): boolean {
74
97
  d = localDate.fromInput(d)
75
98
  return this.day === d.day && this.month === d.month && this.year === d.year
@@ -50,7 +50,7 @@ const MILLISECONDS_IN_WEEK = 604800000
50
50
  const SECONDS_IN_DAY = 86400
51
51
  // const MILLISECONDS_IN_DAY = 86400000
52
52
  // const MILLISECONDS_IN_MINUTE = 60000
53
- const VALID_DAYS_OF_WEEK = new Set([1, 2, 3, 4, 5, 6, 7])
53
+ export const VALID_DAYS_OF_WEEK = new Set([1, 2, 3, 4, 5, 6, 7])
54
54
 
55
55
  /**
56
56
  * It supports 2 forms:
@@ -272,10 +272,27 @@ export class LocalTime {
272
272
  return (this.$date.getDay() || 7) as ISODayOfWeek
273
273
  }
274
274
 
275
- setDayOfWeek(v: ISODayOfWeek): LocalTime {
276
- _assert(VALID_DAYS_OF_WEEK.has(v), `Invalid dayOfWeek: ${v}`)
277
- const dow = this.$date.getDay() || 7
278
- return this.plus(v - dow, 'day')
275
+ /**
276
+ * Returns LocalTime for the given DayOfWeek (e.g Monday), that is in the same week as this.
277
+ * It may move the time into the future, or the past, depending on how the desired DayOfWeek is in
278
+ * relation to `this`.
279
+ */
280
+ setDayOfWeek(dow: ISODayOfWeek): LocalTime {
281
+ _assert(VALID_DAYS_OF_WEEK.has(dow), `Invalid dayOfWeek: ${dow}`)
282
+ const delta = dow - this.dayOfWeek
283
+ return this.plus(delta, 'day')
284
+ }
285
+
286
+ /**
287
+ * Returns LocalTime for the given DayOfWeek (e.g Monday), that is in the future,
288
+ * in relation to this.
289
+ * If this LocalTime is Monday, and desired DoW is also Monday - `this` is returned.
290
+ */
291
+ setNextDayOfWeek(dow: ISODayOfWeek): LocalTime {
292
+ _assert(VALID_DAYS_OF_WEEK.has(dow), `Invalid dayOfWeek: ${dow}`)
293
+ let delta = dow - this.dayOfWeek
294
+ if (delta < 0) delta += 7
295
+ return this.plus(delta, 'day')
279
296
  }
280
297
 
281
298
  setComponents(c: Partial<DateTimeObject>, mutate = false): LocalTime {