inferred-types 0.51.12 → 0.51.13
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/constants/tsconfig.tsbuildinfo +1 -1
- package/dist/index.cjs +155 -0
- package/dist/index.js +144 -0
- package/dist/inferred-types/tsconfig.tsbuildinfo +1 -1
- package/dist/runtime/datetime/getToday.d.ts +7 -0
- package/dist/runtime/datetime/getToday.d.ts.map +1 -0
- package/dist/runtime/datetime/getToday.js +8 -0
- package/dist/runtime/datetime/getTomorrow.d.ts +8 -0
- package/dist/runtime/datetime/getTomorrow.d.ts.map +1 -0
- package/dist/runtime/datetime/getTomorrow.js +10 -0
- package/dist/runtime/datetime/getYesterday.d.ts +8 -0
- package/dist/runtime/datetime/getYesterday.d.ts.map +1 -0
- package/dist/runtime/datetime/getYesterday.js +10 -0
- package/dist/runtime/datetime/index.d.ts +4 -0
- package/dist/runtime/datetime/index.d.ts.map +1 -0
- package/dist/runtime/datetime/index.js +3 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/tsconfig.tsbuildinfo +1 -1
- package/dist/runtime/type-guards/date-time/index.d.ts +8 -0
- package/dist/runtime/type-guards/date-time/index.d.ts.map +1 -1
- package/dist/runtime/type-guards/date-time/index.js +8 -0
- package/dist/runtime/type-guards/date-time/isDate.d.ts +5 -0
- package/dist/runtime/type-guards/date-time/isDate.d.ts.map +1 -0
- package/dist/runtime/type-guards/date-time/isDate.js +6 -0
- package/dist/runtime/type-guards/date-time/isLuxonDateTime.d.ts +7 -0
- package/dist/runtime/type-guards/date-time/isLuxonDateTime.d.ts.map +1 -0
- package/dist/runtime/type-guards/date-time/isLuxonDateTime.js +25 -0
- package/dist/runtime/type-guards/date-time/isMoment.d.ts +7 -0
- package/dist/runtime/type-guards/date-time/isMoment.d.ts.map +1 -0
- package/dist/runtime/type-guards/date-time/isMoment.js +25 -0
- package/dist/runtime/type-guards/date-time/isThisMonth.d.ts +7 -0
- package/dist/runtime/type-guards/date-time/isThisMonth.d.ts.map +1 -0
- package/dist/runtime/type-guards/date-time/isThisMonth.js +34 -0
- package/dist/runtime/type-guards/date-time/isThisYear.d.ts +7 -0
- package/dist/runtime/type-guards/date-time/isThisYear.d.ts.map +1 -0
- package/dist/runtime/type-guards/date-time/isThisYear.js +34 -0
- package/dist/runtime/type-guards/date-time/isToday.d.ts +13 -0
- package/dist/runtime/type-guards/date-time/isToday.d.ts.map +1 -0
- package/dist/runtime/type-guards/date-time/isToday.js +25 -0
- package/dist/runtime/type-guards/date-time/isTomorrow.d.ts +12 -0
- package/dist/runtime/type-guards/date-time/isTomorrow.d.ts.map +1 -0
- package/dist/runtime/type-guards/date-time/isTomorrow.js +24 -0
- package/dist/runtime/type-guards/date-time/isYesterday.d.ts +12 -0
- package/dist/runtime/type-guards/date-time/isYesterday.d.ts.map +1 -0
- package/dist/runtime/type-guards/date-time/isYesterday.js +24 -0
- package/dist/types/literals/date-time-objects.d.ts +690 -0
- package/dist/types/literals/date-time-objects.d.ts.map +1 -0
- package/dist/types/literals/date-time-objects.js +1 -0
- package/dist/types/literals/index.d.ts +1 -0
- package/dist/types/literals/index.d.ts.map +1 -1
- package/dist/types/literals/index.js +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -1
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
export * from "./isDate";
|
|
1
2
|
export * from "./isDateTime";
|
|
2
3
|
export * from "./isIsoTime";
|
|
3
4
|
export * from "./isIsoDate";
|
|
5
|
+
export * from "./isLuxonDateTime";
|
|
6
|
+
export * from "./isMoment";
|
|
7
|
+
export * from "./isToday";
|
|
8
|
+
export * from "./isTomorrow";
|
|
9
|
+
export * from "./isYesterday";
|
|
10
|
+
export * from "./isThisYear";
|
|
11
|
+
export * from "./isThisMonth";
|
|
4
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/type-guards/date-time/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/type-guards/date-time/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
export * from "./isDate";
|
|
1
2
|
export * from "./isDateTime";
|
|
2
3
|
export * from "./isIsoTime";
|
|
3
4
|
export * from "./isIsoDate";
|
|
5
|
+
export * from "./isLuxonDateTime";
|
|
6
|
+
export * from "./isMoment";
|
|
7
|
+
export * from "./isToday";
|
|
8
|
+
export * from "./isTomorrow";
|
|
9
|
+
export * from "./isYesterday";
|
|
10
|
+
export * from "./isThisYear";
|
|
11
|
+
export * from "./isThisMonth";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isDate.d.ts","sourceRoot":"","sources":["../../../../src/runtime/type-guards/date-time/isDate.ts"],"names":[],"mappings":"AACA;;EAEE;AACF,eAAO,MAAM,MAAM,QAAS,OAAO,KAAG,GAAG,IAAI,IAE5C,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LuxonJs } from "src/types/index";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard which validates that the passed in `val` is a
|
|
4
|
+
* [LuxonJS](https://moment.github.io/luxon/#/?id=luxon) DateTime object.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isLuxonDateTime: (val: unknown) => val is LuxonJs["DateTime"];
|
|
7
|
+
//# sourceMappingURL=isLuxonDateTime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isLuxonDateTime.d.ts","sourceRoot":"","sources":["../../../../src/runtime/type-guards/date-time/isLuxonDateTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAGzC;;;EAGE;AACF,eAAO,MAAM,eAAe,QAAS,OAAO,KAAG,GAAG,IAAI,OAAO,CAAC,UAAU,CAmBvE,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isObject } from "src/runtime/index";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard which validates that the passed in `val` is a
|
|
4
|
+
* [LuxonJS](https://moment.github.io/luxon/#/?id=luxon) DateTime object.
|
|
5
|
+
*/
|
|
6
|
+
export const isLuxonDateTime = (val) => {
|
|
7
|
+
return isObject(val) &&
|
|
8
|
+
typeof val === 'object' &&
|
|
9
|
+
val !== null &&
|
|
10
|
+
"isValid" in val &&
|
|
11
|
+
"invalidReason" in val &&
|
|
12
|
+
"invalidExplanation" in val &&
|
|
13
|
+
"toISO" in val &&
|
|
14
|
+
"toFormat" in val &&
|
|
15
|
+
"toMillis" in val &&
|
|
16
|
+
"year" in val &&
|
|
17
|
+
"month" in val &&
|
|
18
|
+
"day" in val &&
|
|
19
|
+
"hour" in val &&
|
|
20
|
+
"minute" in val &&
|
|
21
|
+
"second" in val &&
|
|
22
|
+
"millisecond" in val &&
|
|
23
|
+
typeof val.isValid === "boolean" &&
|
|
24
|
+
typeof val.toISO === "function";
|
|
25
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MomentJs } from "src/types/index";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard which validates that the passed in `val` is a
|
|
4
|
+
* [MomentJS](https://momentjs.com/docs/) object.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isMoment: (val: unknown) => val is MomentJs;
|
|
7
|
+
//# sourceMappingURL=isMoment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isMoment.d.ts","sourceRoot":"","sources":["../../../../src/runtime/type-guards/date-time/isMoment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAG1C;;;EAGE;AACF,eAAO,MAAM,QAAQ,QAAS,OAAO,KAAG,GAAG,IAAI,QAmB9C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isObject } from "src/runtime/index";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard which validates that the passed in `val` is a
|
|
4
|
+
* [MomentJS](https://momentjs.com/docs/) object.
|
|
5
|
+
*/
|
|
6
|
+
export const isMoment = (val) => {
|
|
7
|
+
if (val instanceof Date) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return isObject(val) &&
|
|
11
|
+
// Check for essential Moment.js methods
|
|
12
|
+
typeof val.format === "function" &&
|
|
13
|
+
typeof val.year === "function" &&
|
|
14
|
+
typeof val.month === "function" &&
|
|
15
|
+
typeof val.date === "function" &&
|
|
16
|
+
// Check for Moment-specific properties
|
|
17
|
+
"_isAMomentObject" in val &&
|
|
18
|
+
"_isValid" in val &&
|
|
19
|
+
// Check for essential Moment.js manipulation methods
|
|
20
|
+
typeof val.add === "function" &&
|
|
21
|
+
typeof val.subtract === "function" &&
|
|
22
|
+
// Additional Moment.js specific methods
|
|
23
|
+
typeof val.toISOString === "function" &&
|
|
24
|
+
typeof val.isValid === "function";
|
|
25
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Iso8601Date, Iso8601DateTime, LuxonJs, MomentJs } from "src/types/index";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard which validates that the passed in `val` is a date or date-time
|
|
4
|
+
* representation and that it's month is the same as the current month year.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isThisMonth: (val: unknown) => val is Date | MomentJs | LuxonJs["DateTime"] | Iso8601DateTime | Iso8601Date;
|
|
7
|
+
//# sourceMappingURL=isThisMonth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isThisMonth.d.ts","sourceRoot":"","sources":["../../../../src/runtime/type-guards/date-time/isThisMonth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIlF;;;EAGE;AACF,eAAO,MAAM,WAAW,QACjB,OAAO,KACX,GAAG,IAAI,IAAI,GAAG,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,eAAe,GAAG,WAgCnE,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isMoment } from "./isMoment";
|
|
2
|
+
import { isLuxonDateTime } from "./isLuxonDateTime";
|
|
3
|
+
/**
|
|
4
|
+
* Type guard which validates that the passed in `val` is a date or date-time
|
|
5
|
+
* representation and that it's month is the same as the current month year.
|
|
6
|
+
*/
|
|
7
|
+
export const isThisMonth = (val) => {
|
|
8
|
+
const now = new Date();
|
|
9
|
+
const currentYear = now.getFullYear();
|
|
10
|
+
const currentMonth = now.getMonth() + 1; // getMonth() returns 0-11, we need 1-12
|
|
11
|
+
// Handle Date object
|
|
12
|
+
if (val instanceof Date) {
|
|
13
|
+
return val.getFullYear() === currentYear &&
|
|
14
|
+
(val.getMonth() + 1) === currentMonth;
|
|
15
|
+
}
|
|
16
|
+
if (isMoment(val)) {
|
|
17
|
+
const monthValue = val.month();
|
|
18
|
+
return val.year() === currentYear &&
|
|
19
|
+
(typeof monthValue === "number" ? monthValue + 1 : monthValue) === currentMonth; // Moment months are 0-11
|
|
20
|
+
}
|
|
21
|
+
if (isLuxonDateTime(val)) {
|
|
22
|
+
return val.year === currentYear &&
|
|
23
|
+
val.month === currentMonth; // Luxon months are 1-12
|
|
24
|
+
}
|
|
25
|
+
if (typeof val === "string") {
|
|
26
|
+
const dateMatch = val.match(/^(\d{4})-(\d{2})/);
|
|
27
|
+
if (dateMatch) {
|
|
28
|
+
const year = parseInt(dateMatch[1], 10);
|
|
29
|
+
const month = parseInt(dateMatch[2], 10);
|
|
30
|
+
return year === currentYear && month === currentMonth;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Iso8601Date, Iso8601DateTime, LuxonJs, MomentJs } from "src/types/index";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard which validates that the passed in `val` is a date or date-time
|
|
4
|
+
* representation and that it's year is the same as the current year.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isThisYear: (val: unknown) => val is Date | MomentJs | LuxonJs["DateTime"] | Iso8601DateTime | Iso8601Date;
|
|
7
|
+
//# sourceMappingURL=isThisYear.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isThisYear.d.ts","sourceRoot":"","sources":["../../../../src/runtime/type-guards/date-time/isThisYear.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIlF;;;EAGE;AACF,eAAO,MAAM,UAAU,QAChB,OAAO,KACX,GAAG,IAAI,IAAI,GAAG,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,eAAe,GAAG,WAkCnE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isMoment } from "./isMoment";
|
|
2
|
+
import { isLuxonDateTime } from "./isLuxonDateTime";
|
|
3
|
+
/**
|
|
4
|
+
* Type guard which validates that the passed in `val` is a date or date-time
|
|
5
|
+
* representation and that it's year is the same as the current year.
|
|
6
|
+
*/
|
|
7
|
+
export const isThisYear = (val) => {
|
|
8
|
+
// Get current year
|
|
9
|
+
const currentYear = new Date().getFullYear();
|
|
10
|
+
if (val instanceof Date) {
|
|
11
|
+
return val.getFullYear() === currentYear;
|
|
12
|
+
}
|
|
13
|
+
if (isMoment(val)) {
|
|
14
|
+
return val.year() === currentYear;
|
|
15
|
+
}
|
|
16
|
+
if (isLuxonDateTime(val)) {
|
|
17
|
+
return val.year === currentYear;
|
|
18
|
+
}
|
|
19
|
+
// Handle ISO 8601 strings
|
|
20
|
+
if (typeof val === "string") {
|
|
21
|
+
// Match for full ISO 8601 date (YYYY-MM-DD) or datetime (YYYY-MM-DDThh:mm:ssZ) format
|
|
22
|
+
const isoDateRegex = /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])(?:T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[-+][01]\d:[0-5]\d))?$/;
|
|
23
|
+
if (!isoDateRegex.test(val)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
// Extract year from valid ISO string
|
|
27
|
+
const yearMatch = val.match(/^(\d{4})/);
|
|
28
|
+
if (yearMatch) {
|
|
29
|
+
const year = parseInt(yearMatch[1], 10);
|
|
30
|
+
return year === currentYear;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Iso8601Date, LuxonJs, MomentJs } from "src/types/index";
|
|
2
|
+
/**
|
|
3
|
+
* **isToday`(val)`**
|
|
4
|
+
*
|
|
5
|
+
* A type guard which validates whether the passed in value _represents_ today's date
|
|
6
|
+
* as either a:
|
|
7
|
+
*
|
|
8
|
+
* - [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date string, or
|
|
9
|
+
* - [Moment.js](https://momentjs.com/docs/#/displaying/) DateTime object, or
|
|
10
|
+
* - [Luxon](https://moment.github.io/luxon/#/?id=luxon) DateTime object
|
|
11
|
+
*/
|
|
12
|
+
export declare const isToday: (test: unknown) => test is Iso8601Date<"explicit"> | LuxonJs["DateTime"] | MomentJs;
|
|
13
|
+
//# sourceMappingURL=isToday.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isToday.d.ts","sourceRoot":"","sources":["../../../../src/runtime/type-guards/date-time/isToday.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGjE;;;;;;;;;EASE;AACF,eAAO,MAAM,OAAO,SACZ,OAAO,KACZ,IAAI,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,QAe1D,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getToday, isDate, isLuxonDateTime } from "src/runtime/index";
|
|
2
|
+
import { isIsoExplicitDate, isMoment, isString, stripAfter } from "src/runtime/index";
|
|
3
|
+
/**
|
|
4
|
+
* **isToday`(val)`**
|
|
5
|
+
*
|
|
6
|
+
* A type guard which validates whether the passed in value _represents_ today's date
|
|
7
|
+
* as either a:
|
|
8
|
+
*
|
|
9
|
+
* - [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date string, or
|
|
10
|
+
* - [Moment.js](https://momentjs.com/docs/#/displaying/) DateTime object, or
|
|
11
|
+
* - [Luxon](https://moment.github.io/luxon/#/?id=luxon) DateTime object
|
|
12
|
+
*/
|
|
13
|
+
export const isToday = (test) => {
|
|
14
|
+
if (isString(test)) {
|
|
15
|
+
const justDate = stripAfter(test, "T");
|
|
16
|
+
return isIsoExplicitDate(justDate) && justDate === getToday();
|
|
17
|
+
}
|
|
18
|
+
else if (isMoment(test) || isDate(test)) {
|
|
19
|
+
return (stripAfter(test.toISOString(), "T") === getToday());
|
|
20
|
+
}
|
|
21
|
+
else if (isLuxonDateTime(test)) {
|
|
22
|
+
return (stripAfter(test.toISO(), "T") === getToday());
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Iso8601Date, LuxonJs, MomentJs } from "src/types/index";
|
|
2
|
+
/**
|
|
3
|
+
* **isTomorrow`(val)`**
|
|
4
|
+
* A type guard which validates whether the passed in value _represents_ tomorrow's date
|
|
5
|
+
* as either a:
|
|
6
|
+
*
|
|
7
|
+
* - [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date string, or
|
|
8
|
+
* - [Moment.js](https://momentjs.com/docs/#/displaying/) DateTime object, or
|
|
9
|
+
* - [Luxon](https://moment.github.io/luxon/#/?id=luxon) DateTime object
|
|
10
|
+
*/
|
|
11
|
+
export declare const isTomorrow: (test: unknown) => test is Iso8601Date<"explicit"> | LuxonJs["DateTime"] | MomentJs;
|
|
12
|
+
//# sourceMappingURL=isTomorrow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isTomorrow.d.ts","sourceRoot":"","sources":["../../../../src/runtime/type-guards/date-time/isTomorrow.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGjE;;;;;;;;EAQE;AACF,eAAO,MAAM,UAAU,SACf,OAAO,KACZ,IAAI,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,QAe1D,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getTomorrow, isDate, isLuxonDateTime } from "src/runtime/index";
|
|
2
|
+
import { isIsoExplicitDate, isMoment, isString, stripAfter } from "src/runtime/index";
|
|
3
|
+
/**
|
|
4
|
+
* **isTomorrow`(val)`**
|
|
5
|
+
* A type guard which validates whether the passed in value _represents_ tomorrow's date
|
|
6
|
+
* as either a:
|
|
7
|
+
*
|
|
8
|
+
* - [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date string, or
|
|
9
|
+
* - [Moment.js](https://momentjs.com/docs/#/displaying/) DateTime object, or
|
|
10
|
+
* - [Luxon](https://moment.github.io/luxon/#/?id=luxon) DateTime object
|
|
11
|
+
*/
|
|
12
|
+
export const isTomorrow = (test) => {
|
|
13
|
+
if (isString(test)) {
|
|
14
|
+
const justDate = stripAfter(test, "T");
|
|
15
|
+
return isIsoExplicitDate(justDate) && justDate === getTomorrow();
|
|
16
|
+
}
|
|
17
|
+
else if (isMoment(test) || isDate(test)) {
|
|
18
|
+
return (stripAfter(test.toISOString(), "T") === getTomorrow());
|
|
19
|
+
}
|
|
20
|
+
else if (isLuxonDateTime(test)) {
|
|
21
|
+
return (stripAfter(test.toISO(), "T") === getTomorrow());
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Iso8601Date, LuxonJs, MomentJs } from "src/types/index";
|
|
2
|
+
/**
|
|
3
|
+
* **isYesterday`(val)`**
|
|
4
|
+
* A type guard which validates whether the passed in value _represents_ yesterday's date
|
|
5
|
+
* as either a:
|
|
6
|
+
*
|
|
7
|
+
* - [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date string, or
|
|
8
|
+
* - [Moment.js](https://momentjs.com/docs/#/displaying/) DateTime object, or
|
|
9
|
+
* - [Luxon](https://moment.github.io/luxon/#/?id=luxon) DateTime object
|
|
10
|
+
*/
|
|
11
|
+
export declare const isYesterday: (test: unknown) => test is Iso8601Date<"explicit"> | LuxonJs["DateTime"] | MomentJs;
|
|
12
|
+
//# sourceMappingURL=isYesterday.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isYesterday.d.ts","sourceRoot":"","sources":["../../../../src/runtime/type-guards/date-time/isYesterday.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGjE;;;;;;;;EAQE;AACF,eAAO,MAAM,WAAW,SAChB,OAAO,KACZ,IAAI,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,QAe1D,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getYesterday, isDate, isLuxonDateTime } from "src/runtime/index";
|
|
2
|
+
import { isIsoExplicitDate, isMoment, isString, stripAfter } from "src/runtime/index";
|
|
3
|
+
/**
|
|
4
|
+
* **isYesterday`(val)`**
|
|
5
|
+
* A type guard which validates whether the passed in value _represents_ yesterday's date
|
|
6
|
+
* as either a:
|
|
7
|
+
*
|
|
8
|
+
* - [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date string, or
|
|
9
|
+
* - [Moment.js](https://momentjs.com/docs/#/displaying/) DateTime object, or
|
|
10
|
+
* - [Luxon](https://moment.github.io/luxon/#/?id=luxon) DateTime object
|
|
11
|
+
*/
|
|
12
|
+
export const isYesterday = (test) => {
|
|
13
|
+
if (isString(test)) {
|
|
14
|
+
const justDate = stripAfter(test, "T");
|
|
15
|
+
return isIsoExplicitDate(justDate) && justDate === getYesterday();
|
|
16
|
+
}
|
|
17
|
+
else if (isMoment(test) || isDate(test)) {
|
|
18
|
+
return (stripAfter(test.toISOString(), "T") === getYesterday());
|
|
19
|
+
}
|
|
20
|
+
else if (isLuxonDateTime(test)) {
|
|
21
|
+
return (stripAfter(test.toISO(), "T") === getYesterday());
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
};
|