@naturalcycles/js-lib 14.261.1 → 14.263.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.
- package/dist/bot.js +2 -1
- package/dist/datetime/localDate.d.ts +12 -0
- package/dist/datetime/localDate.js +22 -0
- package/dist/datetime/localTime.d.ts +13 -1
- package/dist/datetime/localTime.js +23 -6
- package/dist/json-schema/jsonSchemaBuilder.d.ts +1 -1
- package/dist-esm/bot.js +2 -1
- package/dist-esm/datetime/localDate.js +23 -1
- package/dist-esm/datetime/localTime.js +22 -5
- package/package.json +1 -1
- package/src/bot.ts +4 -1
- package/src/datetime/localDate.ts +24 -1
- package/src/datetime/localTime.ts +22 -5
package/dist/bot.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.BotReason = exports.BotDetectionService = void 0;
|
|
6
6
|
const env_1 = require("./env");
|
|
7
|
+
const botRegex = /bot|spider|crawl|headless|electron|phantom|slimer|proximic|cincraw|snapchat|slurp|MicrosoftPreview/i;
|
|
7
8
|
/**
|
|
8
9
|
* Service to detect bots and CDP (Chrome DevTools Protocol).
|
|
9
10
|
*
|
|
@@ -40,7 +41,7 @@ class BotDetectionService {
|
|
|
40
41
|
const { userAgent } = navigator;
|
|
41
42
|
if (!userAgent)
|
|
42
43
|
return BotReason.NoUserAgent;
|
|
43
|
-
if (
|
|
44
|
+
if (botRegex.test(userAgent)) {
|
|
44
45
|
return BotReason.UserAgent;
|
|
45
46
|
}
|
|
46
47
|
if (navigator.webdriver) {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
|
17
|
+
buffer(): JsonSchemaAnyBuilder<Buffer<ArrayBufferLike>, JsonSchemaAny<Buffer<ArrayBufferLike>>>;
|
|
18
18
|
number(): JsonSchemaNumberBuilder;
|
|
19
19
|
integer(): JsonSchemaNumberBuilder;
|
|
20
20
|
unixTimestamp(): JsonSchemaNumberBuilder;
|
package/dist-esm/bot.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Relevant material:
|
|
2
2
|
// https://deviceandbrowserinfo.com/learning_zone/articles/detecting-headless-chrome-puppeteer-2024
|
|
3
3
|
import { isServerSide } from './env';
|
|
4
|
+
const botRegex = /bot|spider|crawl|headless|electron|phantom|slimer|proximic|cincraw|snapchat|slurp|MicrosoftPreview/i;
|
|
4
5
|
/**
|
|
5
6
|
* Service to detect bots and CDP (Chrome DevTools Protocol).
|
|
6
7
|
*
|
|
@@ -37,7 +38,7 @@ export class BotDetectionService {
|
|
|
37
38
|
const { userAgent } = navigator;
|
|
38
39
|
if (!userAgent)
|
|
39
40
|
return BotReason.NoUserAgent;
|
|
40
|
-
if (
|
|
41
|
+
if (botRegex.test(userAgent)) {
|
|
41
42
|
return BotReason.UserAgent;
|
|
42
43
|
}
|
|
43
44
|
if (navigator.webdriver) {
|
|
@@ -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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
package/src/bot.ts
CHANGED
|
@@ -19,6 +19,9 @@ export interface BotDetectionServiceCfg {
|
|
|
19
19
|
treatCDPAsBotReason?: boolean
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
const botRegex =
|
|
23
|
+
/bot|spider|crawl|headless|electron|phantom|slimer|proximic|cincraw|snapchat|slurp|MicrosoftPreview/i
|
|
24
|
+
|
|
22
25
|
/**
|
|
23
26
|
* Service to detect bots and CDP (Chrome DevTools Protocol).
|
|
24
27
|
*
|
|
@@ -60,7 +63,7 @@ export class BotDetectionService {
|
|
|
60
63
|
const { userAgent } = navigator
|
|
61
64
|
if (!userAgent) return BotReason.NoUserAgent
|
|
62
65
|
|
|
63
|
-
if (
|
|
66
|
+
if (botRegex.test(userAgent)) {
|
|
64
67
|
return BotReason.UserAgent
|
|
65
68
|
}
|
|
66
69
|
|
|
@@ -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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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 {
|