veffect
Version:
powerful TypeScript validation library built on the robust foundation of Effect combining exceptional type safety, high performance, and developer experience. Taking inspiration from Effect's functional principles, VEffect delivers a balanced approach tha
170 lines • 4.63 kB
TypeScript
/**
* @since 2.0.0
*/
import * as Either from "./Either.js";
import * as Equal from "./Equal.js";
import * as equivalence from "./Equivalence.js";
import { type Inspectable } from "./Inspectable.js";
import { type Pipeable } from "./Pipeable.js";
/**
* @since 2.0.0
* @category symbols
*/
export declare const TypeId: unique symbol;
/**
* @since 2.0.0
* @category symbol
*/
export type TypeId = typeof TypeId;
/**
* @since 2.0.0
* @category models
*/
export interface Cron extends Pipeable, Equal.Equal, Inspectable {
readonly [TypeId]: TypeId;
readonly minutes: ReadonlySet<number>;
readonly hours: ReadonlySet<number>;
readonly days: ReadonlySet<number>;
readonly months: ReadonlySet<number>;
readonly weekdays: ReadonlySet<number>;
}
/**
* Checks if a given value is a `Cron` instance.
*
* @param u - The value to check.
*
* @since 2.0.0
* @category guards
*/
export declare const isCron: (u: unknown) => u is Cron;
/**
* Creates a `Cron` instance from.
*
* @param constraints - The cron constraints.
*
* @since 2.0.0
* @category constructors
*/
export declare const make: ({ days, hours, minutes, months, weekdays }: {
readonly minutes: Iterable<number>;
readonly hours: Iterable<number>;
readonly days: Iterable<number>;
readonly months: Iterable<number>;
readonly weekdays: Iterable<number>;
}) => Cron;
/**
* @since 2.0.0
* @category symbol
*/
export declare const ParseErrorTypeId: unique symbol;
/**
* @since 2.0.0
* @category symbols
*/
export type ParseErrorTypeId = typeof ParseErrorTypeId;
/**
* Represents a checked exception which occurs when decoding fails.
*
* @since 2.0.0
* @category models
*/
export interface ParseError {
readonly _tag: "ParseError";
readonly [ParseErrorTypeId]: ParseErrorTypeId;
readonly message: string;
readonly input?: string;
}
declare const ParseError: (message: string, input?: string) => ParseError;
/**
* Returns `true` if the specified value is an `ParseError`, `false` otherwise.
*
* @param u - The value to check.
*
* @since 2.0.0
* @category guards
*/
export declare const isParseError: (u: unknown) => u is ParseError;
/**
* Parses a cron expression into a `Cron` instance.
*
* @param cron - The cron expression to parse.
*
* @example
* import * as Cron from "effect/Cron"
* import * as Either from "effect/Either"
*
* // At 04:00 on every day-of-month from 8 through 14.
* assert.deepStrictEqual(Cron.parse("0 4 8-14 * *"), Either.right(Cron.make({
* minutes: [0],
* hours: [4],
* days: [8, 9, 10, 11, 12, 13, 14],
* months: [],
* weekdays: []
* })))
*
* @since 2.0.0
* @category constructors
*/
export declare const parse: (cron: string) => Either.Either<Cron, ParseError>;
/**
* Checks if a given `Date` falls within an active `Cron` time window.
*
* @param cron - The `Cron` instance.
* @param date - The `Date` to check against.
*
* @example
* import * as Cron from "effect/Cron"
* import * as Either from "effect/Either"
*
* const cron = Either.getOrThrow(Cron.parse("0 4 8-14 * *"))
* assert.deepStrictEqual(Cron.match(cron, new Date("2021-01-08 04:00:00")), true)
* assert.deepStrictEqual(Cron.match(cron, new Date("2021-01-08 05:00:00")), false)
*
* @since 2.0.0
*/
export declare const match: (cron: Cron, date: Date) => boolean;
/**
* Returns the next run `Date` for the given `Cron` instance.
*
* Uses the current time as a starting point if no value is provided for `now`.
*
* @example
* import * as Cron from "effect/Cron"
* import * as Either from "effect/Either"
*
* const after = new Date("2021-01-01 00:00:00")
* const cron = Either.getOrThrow(Cron.parse("0 4 8-14 * *"))
* assert.deepStrictEqual(Cron.next(cron, after), new Date("2021-01-08 04:00:00"))
*
* @param cron - The `Cron` instance.
* @param now - The `Date` to start searching from.
*
* @since 2.0.0
*/
export declare const next: (cron: Cron, now?: Date) => Date;
/**
* Returns an `IterableIterator` which yields the sequence of `Date`s that match the `Cron` instance.
*
* @param cron - The `Cron` instance.
* @param now - The `Date` to start searching from.
*
* @since 2.0.0
*/
export declare const sequence: (cron: Cron, now?: Date) => IterableIterator<Date>;
/**
* @category instances
* @since 2.0.0
*/
export declare const Equivalence: equivalence.Equivalence<Cron>;
/**
* Checks if two `Cron`s are equal.
*
* @since 2.0.0
* @category predicates
*/
export declare const equals: {
(that: Cron): (self: Cron) => boolean;
(self: Cron, that: Cron): boolean;
};
export {};
//# sourceMappingURL=Cron.d.ts.map