@naturalcycles/js-lib 14.246.0 → 14.246.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.
|
@@ -196,19 +196,12 @@ declare class LocalDateFactory {
|
|
|
196
196
|
* Performs STRICT parsing.
|
|
197
197
|
* Only allows IsoDateString input, nothing else.
|
|
198
198
|
*/
|
|
199
|
-
|
|
199
|
+
fromString(s: IsoDateString): LocalDate;
|
|
200
200
|
/**
|
|
201
201
|
* Parses "compact iso8601 format", e.g `19840621` into LocalDate.
|
|
202
202
|
* Throws if it fails to do so.
|
|
203
203
|
*/
|
|
204
204
|
fromCompactString(s: string): LocalDate;
|
|
205
|
-
/**
|
|
206
|
-
* Performs LOOSE parsing.
|
|
207
|
-
* Tries to coerce imprefect/incorrect string input into IsoDateString.
|
|
208
|
-
* Use with caution.
|
|
209
|
-
* Allows to input IsoDateTimeString, will drop the Time part of it.
|
|
210
|
-
*/
|
|
211
|
-
parse(s: string): LocalDate;
|
|
212
205
|
/**
|
|
213
206
|
* Throws if it fails to parse the input string via Regex and YMD validation.
|
|
214
207
|
*/
|
|
@@ -9,11 +9,7 @@ const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
|
9
9
|
/**
|
|
10
10
|
* Regex is open-ended (no $ at the end) to support e.g Date+Time string to be parsed (time part will be dropped)
|
|
11
11
|
*/
|
|
12
|
-
const
|
|
13
|
-
/**
|
|
14
|
-
* Strict version.
|
|
15
|
-
*/
|
|
16
|
-
const DATE_REGEX_STRICT = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
12
|
+
const DATE_REGEX = /^(\d\d\d\d)-(\d\d)-(\d\d)/;
|
|
17
13
|
const COMPACT_DATE_REGEX = /^(\d\d\d\d)(\d\d)(\d\d)$/;
|
|
18
14
|
/**
|
|
19
15
|
* LocalDate represents a date without time.
|
|
@@ -474,7 +470,7 @@ class LocalDateFactory {
|
|
|
474
470
|
return this.fromDate(input);
|
|
475
471
|
}
|
|
476
472
|
// It means it's a string
|
|
477
|
-
return this.
|
|
473
|
+
return this.fromString(input);
|
|
478
474
|
}
|
|
479
475
|
/**
|
|
480
476
|
* Returns true if input is valid to create LocalDate.
|
|
@@ -492,7 +488,7 @@ class LocalDateFactory {
|
|
|
492
488
|
* Returns true if isoString is a valid iso8601 string like `yyyy-mm-dd`.
|
|
493
489
|
*/
|
|
494
490
|
isValidString(isoString) {
|
|
495
|
-
return !!this.parseToLocalDateOrUndefined(
|
|
491
|
+
return !!this.parseToLocalDateOrUndefined(DATE_REGEX, isoString);
|
|
496
492
|
}
|
|
497
493
|
/**
|
|
498
494
|
* Tries to convert/parse the input into LocalDate.
|
|
@@ -509,14 +505,14 @@ class LocalDateFactory {
|
|
|
509
505
|
return;
|
|
510
506
|
return new LocalDate(input.getFullYear(), input.getMonth() + 1, input.getDate());
|
|
511
507
|
}
|
|
512
|
-
return this.parseToLocalDateOrUndefined(
|
|
508
|
+
return this.parseToLocalDateOrUndefined(DATE_REGEX, input);
|
|
513
509
|
}
|
|
514
510
|
/**
|
|
515
511
|
* Performs STRICT parsing.
|
|
516
512
|
* Only allows IsoDateString input, nothing else.
|
|
517
513
|
*/
|
|
518
|
-
|
|
519
|
-
return this.parseToLocalDate(
|
|
514
|
+
fromString(s) {
|
|
515
|
+
return this.parseToLocalDate(DATE_REGEX, s);
|
|
520
516
|
}
|
|
521
517
|
/**
|
|
522
518
|
* Parses "compact iso8601 format", e.g `19840621` into LocalDate.
|
|
@@ -525,15 +521,6 @@ class LocalDateFactory {
|
|
|
525
521
|
fromCompactString(s) {
|
|
526
522
|
return this.parseToLocalDate(COMPACT_DATE_REGEX, s);
|
|
527
523
|
}
|
|
528
|
-
/**
|
|
529
|
-
* Performs LOOSE parsing.
|
|
530
|
-
* Tries to coerce imprefect/incorrect string input into IsoDateString.
|
|
531
|
-
* Use with caution.
|
|
532
|
-
* Allows to input IsoDateTimeString, will drop the Time part of it.
|
|
533
|
-
*/
|
|
534
|
-
parse(s) {
|
|
535
|
-
return this.parseToLocalDate(DATE_REGEX_LOOSE, String(s));
|
|
536
|
-
}
|
|
537
524
|
/**
|
|
538
525
|
* Throws if it fails to parse the input string via Regex and YMD validation.
|
|
539
526
|
*/
|
|
@@ -6,11 +6,7 @@ const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
|
6
6
|
/**
|
|
7
7
|
* Regex is open-ended (no $ at the end) to support e.g Date+Time string to be parsed (time part will be dropped)
|
|
8
8
|
*/
|
|
9
|
-
const
|
|
10
|
-
/**
|
|
11
|
-
* Strict version.
|
|
12
|
-
*/
|
|
13
|
-
const DATE_REGEX_STRICT = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
9
|
+
const DATE_REGEX = /^(\d\d\d\d)-(\d\d)-(\d\d)/;
|
|
14
10
|
const COMPACT_DATE_REGEX = /^(\d\d\d\d)(\d\d)(\d\d)$/;
|
|
15
11
|
/**
|
|
16
12
|
* LocalDate represents a date without time.
|
|
@@ -470,7 +466,7 @@ class LocalDateFactory {
|
|
|
470
466
|
return this.fromDate(input);
|
|
471
467
|
}
|
|
472
468
|
// It means it's a string
|
|
473
|
-
return this.
|
|
469
|
+
return this.fromString(input);
|
|
474
470
|
}
|
|
475
471
|
/**
|
|
476
472
|
* Returns true if input is valid to create LocalDate.
|
|
@@ -488,7 +484,7 @@ class LocalDateFactory {
|
|
|
488
484
|
* Returns true if isoString is a valid iso8601 string like `yyyy-mm-dd`.
|
|
489
485
|
*/
|
|
490
486
|
isValidString(isoString) {
|
|
491
|
-
return !!this.parseToLocalDateOrUndefined(
|
|
487
|
+
return !!this.parseToLocalDateOrUndefined(DATE_REGEX, isoString);
|
|
492
488
|
}
|
|
493
489
|
/**
|
|
494
490
|
* Tries to convert/parse the input into LocalDate.
|
|
@@ -505,14 +501,14 @@ class LocalDateFactory {
|
|
|
505
501
|
return;
|
|
506
502
|
return new LocalDate(input.getFullYear(), input.getMonth() + 1, input.getDate());
|
|
507
503
|
}
|
|
508
|
-
return this.parseToLocalDateOrUndefined(
|
|
504
|
+
return this.parseToLocalDateOrUndefined(DATE_REGEX, input);
|
|
509
505
|
}
|
|
510
506
|
/**
|
|
511
507
|
* Performs STRICT parsing.
|
|
512
508
|
* Only allows IsoDateString input, nothing else.
|
|
513
509
|
*/
|
|
514
|
-
|
|
515
|
-
return this.parseToLocalDate(
|
|
510
|
+
fromString(s) {
|
|
511
|
+
return this.parseToLocalDate(DATE_REGEX, s);
|
|
516
512
|
}
|
|
517
513
|
/**
|
|
518
514
|
* Parses "compact iso8601 format", e.g `19840621` into LocalDate.
|
|
@@ -521,15 +517,6 @@ class LocalDateFactory {
|
|
|
521
517
|
fromCompactString(s) {
|
|
522
518
|
return this.parseToLocalDate(COMPACT_DATE_REGEX, s);
|
|
523
519
|
}
|
|
524
|
-
/**
|
|
525
|
-
* Performs LOOSE parsing.
|
|
526
|
-
* Tries to coerce imprefect/incorrect string input into IsoDateString.
|
|
527
|
-
* Use with caution.
|
|
528
|
-
* Allows to input IsoDateTimeString, will drop the Time part of it.
|
|
529
|
-
*/
|
|
530
|
-
parse(s) {
|
|
531
|
-
return this.parseToLocalDate(DATE_REGEX_LOOSE, String(s));
|
|
532
|
-
}
|
|
533
520
|
/**
|
|
534
521
|
* Throws if it fails to parse the input string via Regex and YMD validation.
|
|
535
522
|
*/
|
package/package.json
CHANGED
|
@@ -19,11 +19,7 @@ const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
|
19
19
|
/**
|
|
20
20
|
* Regex is open-ended (no $ at the end) to support e.g Date+Time string to be parsed (time part will be dropped)
|
|
21
21
|
*/
|
|
22
|
-
const
|
|
23
|
-
/**
|
|
24
|
-
* Strict version.
|
|
25
|
-
*/
|
|
26
|
-
const DATE_REGEX_STRICT = /^(\d\d\d\d)-(\d\d)-(\d\d)$/
|
|
22
|
+
const DATE_REGEX = /^(\d\d\d\d)-(\d\d)-(\d\d)/
|
|
27
23
|
const COMPACT_DATE_REGEX = /^(\d\d\d\d)(\d\d)(\d\d)$/
|
|
28
24
|
|
|
29
25
|
export type LocalDateInput = LocalDate | Date | IsoDateString
|
|
@@ -540,7 +536,7 @@ class LocalDateFactory {
|
|
|
540
536
|
return this.fromDate(input)
|
|
541
537
|
}
|
|
542
538
|
// It means it's a string
|
|
543
|
-
return this.
|
|
539
|
+
return this.fromString(input)
|
|
544
540
|
}
|
|
545
541
|
|
|
546
542
|
/**
|
|
@@ -557,7 +553,7 @@ class LocalDateFactory {
|
|
|
557
553
|
* Returns true if isoString is a valid iso8601 string like `yyyy-mm-dd`.
|
|
558
554
|
*/
|
|
559
555
|
isValidString(isoString: string | undefined | null): boolean {
|
|
560
|
-
return !!this.parseToLocalDateOrUndefined(
|
|
556
|
+
return !!this.parseToLocalDateOrUndefined(DATE_REGEX, isoString)
|
|
561
557
|
}
|
|
562
558
|
|
|
563
559
|
/**
|
|
@@ -572,15 +568,15 @@ class LocalDateFactory {
|
|
|
572
568
|
if (isNaN(input.getDate())) return
|
|
573
569
|
return new LocalDate(input.getFullYear(), input.getMonth() + 1, input.getDate())
|
|
574
570
|
}
|
|
575
|
-
return this.parseToLocalDateOrUndefined(
|
|
571
|
+
return this.parseToLocalDateOrUndefined(DATE_REGEX, input)
|
|
576
572
|
}
|
|
577
573
|
|
|
578
574
|
/**
|
|
579
575
|
* Performs STRICT parsing.
|
|
580
576
|
* Only allows IsoDateString input, nothing else.
|
|
581
577
|
*/
|
|
582
|
-
|
|
583
|
-
return this.parseToLocalDate(
|
|
578
|
+
fromString(s: IsoDateString): LocalDate {
|
|
579
|
+
return this.parseToLocalDate(DATE_REGEX, s)
|
|
584
580
|
}
|
|
585
581
|
|
|
586
582
|
/**
|
|
@@ -591,16 +587,6 @@ class LocalDateFactory {
|
|
|
591
587
|
return this.parseToLocalDate(COMPACT_DATE_REGEX, s)
|
|
592
588
|
}
|
|
593
589
|
|
|
594
|
-
/**
|
|
595
|
-
* Performs LOOSE parsing.
|
|
596
|
-
* Tries to coerce imprefect/incorrect string input into IsoDateString.
|
|
597
|
-
* Use with caution.
|
|
598
|
-
* Allows to input IsoDateTimeString, will drop the Time part of it.
|
|
599
|
-
*/
|
|
600
|
-
parse(s: string): LocalDate {
|
|
601
|
-
return this.parseToLocalDate(DATE_REGEX_LOOSE, String(s))
|
|
602
|
-
}
|
|
603
|
-
|
|
604
590
|
/**
|
|
605
591
|
* Throws if it fails to parse the input string via Regex and YMD validation.
|
|
606
592
|
*/
|