@tevari/helpers
Version:
Collection of various small helpers for javascript and typescript based projects
1,279 lines (1,275 loc) • 152 kB
TypeScript
/**
* A function that returns the exact given value.
*
* @param value The value parameter of the function.
* @returns a function that returns the exact given value.
*/
declare const functionIdentity: () => <T>(value: T) => T;
/**
* A function that returns the given value casted to the given type.
*
* @param value The value parameter of the function.
* @returns a function that returns the given value casted to the given type.
*/
declare const functionIdentityAs: () => <T>(value: unknown) => T;
/**
* A function that extracts an attribute from the given value.
*
* @param attributeName The name of the attribute to extract.
* @returns a function that extract the attrobute from the given object.
*/
declare const functionAttribute: <T, U>(attributeName: string) => (value: T) => U | undefined;
/**
* A void function.
*
* @returns a void function.
*/
declare const functionVoid: () => () => void;
declare const FunctionHelpers: {
/**
* A function that returns the exact given value.
*
* @param value The value parameter of the function.
* @returns a function that returns the exact given value.
*/
identity: () => <T>(value: T) => T;
/**
* A function that returns the given value casted to the given type.
*
* @param value The value parameter of the function.
* @returns a function that returns the given value casted to the given type.
*/
identityAs: () => <T_1>(value: unknown) => T_1;
/**
* A function that extracts an attribute from the given value.
*
* @param attributeName The name of the attribute to extract.
* @returns a function that extract the attrobute from the given object.
*/
attribute: <T_2, U>(attributeName: string) => (value: T_2) => U | undefined;
/**
* A void function.
*
* @returns a void function.
*/
void: () => () => void;
};
/**
* A void function that takes no parameter.
*/
type Procedure = () => void;
/**
* A void function that takes one parameter.
*/
type Consumer1<T> = (value: T) => void;
/**
* A void function that takes one parameter. Alias to `Consumer1`.
*/
type Consumer<T> = Consumer1<T>;
/**
* A void function that takes two parameters.
*/
type Consumer2<T, U> = (value1: T, value2: U) => void;
/**
* A void function that takes three parameters.
*/
type Consumer3<T, U, V> = (value1: T, value2: U, value3: V) => void;
/**
* A function that takes one parameter and returns a value.
*/
type Function1<T, U> = (value: T) => U;
/**
* A function that takes one parameter and returns a value. Alias to `Function1`.
*/
type Function<T, U> = Function1<T, U>;
/**
* A function that takes two parameters and returns a value.
*/
type Function2<T, U, V> = (value1: T, value2: U) => V;
/**
* A function that takes three parameters and returns a value.
*/
type Function3<T, U, V, W> = (value1: T, value2: U, value3: V) => W;
/**
* A function that takes no parameter and returns a value.
*/
type Supplier<T> = () => T;
/**
* A boolean function that takes no parameter. Alias to `Supplier<boolean>`;
*/
type Predicate0 = Supplier<boolean>;
/**
* A boolean function that takes one parameter.
*/
type Predicate<T> = (value: T) => boolean;
declare const Functions: {
/**
* Function helper methods.
*/
helper: {
/**
* A function that returns the exact given value.
*
* @param value The value parameter of the function.
* @returns a function that returns the exact given value.
*/
identity: () => <T>(value: T) => T;
/**
* A function that returns the given value casted to the given type.
*
* @param value The value parameter of the function.
* @returns a function that returns the given value casted to the given type.
*/
identityAs: () => <T_1>(value: unknown) => T_1;
/**
* A function that extracts an attribute from the given value.
*
* @param attributeName The name of the attribute to extract.
* @returns a function that extract the attrobute from the given object.
*/
attribute: <T_2, U>(attributeName: string) => (value: T_2) => U | undefined;
/**
* A void function.
*
* @returns a void function.
*/
void: () => () => void;
};
};
/**
* A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value.
* Additional methods that depend on the presence or absence of a contained value are provided, such as orElse() (return a default value if value not present) and ifPresent() (execute a block of code if the value is present).
*
* This is a value-based class; use of identity-sensitive operations (including reference equality (==), identity hash code, or synchronization) on instances of Optional may have unpredictable results and should be avoided.
*/
declare class Optional<T> {
private value?;
private constructor();
/**
* Returns an empty Optional instance.
*/
static empty<T>(): Optional<T>;
/**
* Returns an Optional with the specified present non-null value.
*
* @param value The value to fill the Optional with.
* @returns an Optional with the given value.
*/
static filled<T>(value: T): Optional<T>;
/**
* Returns an Optional with the specified present value if non-null, otherwise returns an empty Optional.
*
* @param value The value to fill the Optional with.
* @returns an Optional with the given value if non-null, an empty Optional otherwise.
*/
static of<T>(value?: T): Optional<T>;
/**
* Indicates whether some other object is "equal to" this Optional.
*
* @param other Object to compare this optional value with.
* @param comparator The predicate used to compare the values.
* @returns `true`if the two values are equal, `false` otherwise.
*/
equals(other: T, comparator?: Function2<T, T, boolean>): boolean;
/**
* Casts this Optional to the given type.
*
* @returns a new optional typed as the given type.
*/
as<U>(): Optional<U>;
/**
* Sets the given value. If a value is already present, this method replaces it.
*
* @param value The value to set.
*/
set(value: T): this;
/**
* If a value is present in this Optional, returns the value, otherwise throws NoSuchElementException.
*
* @returns the value if present, throws NoSuchElementException otherwise.
*/
get(): NonNullable<T>;
/**
* If a value is present, and the value matches the given predicate, return an Optional describing the value, otherwise return an empty Optional.
*
* @param predicate To filter the value with if present.
* @returns a filled Optional if a value is present and it matches the given predicate, and emlpty Optional otherwise.
*/
filter(predicate: Predicate<T>): Optional<T>;
/**
* If a value is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result.
*
* @param mapper The mapper function.
* @returns the result Optional if a value is present, an empty Optional otherwise.
*/
map<U>(mapper: Function1<T, U>): Optional<U>;
/**
* If a value is present, apply the provided Optional-bearing mapping function to it, return that result, otherwise return an empty Optional.
*
* @param mapper The mapper function.
* @returns the result Optional if a value is present, an empty Optional otherwise.
*/
flatMap<U>(mapper: Function1<T, Optional<U>>): Optional<U>;
/**
* Tests whether this optional is empty.
*
* @returns `true` if there is no present value, otherwise `false`.
*/
isEmpty(): boolean;
/**
* Tests whether a value is present.
*
* @returns `true` if there is a value present, otherwise `false`.
*/
isPresent(): boolean;
/**
* If a value is present, invoke the specified consumer with the value, otherwise do nothing.
*
* @param consumer The consumer to invoke if a value is present.
* @returns itself for chaining purposes.
*/
ifPresent(consumer: Consumer<T>): Optional<T>;
/**
* Return the value if present, otherwise return other.
*
* @param other The default value to return if this Optional is empty.
* @returns the value if present, otherwise `other`.
*/
orElse(other: T): T;
/**
* If the optional is empty, invokes the specified supplier, otherwise do nothing.
*
* @param other The default value to return if this Optional is empty.
* @returns itself for chaining purposes.
*/
orElseInvoke(procedure: Procedure): Optional<T>;
/**
* Return the value if present, otherwise return `undefined`.
*
* @returns the value if present, otherwise `undefined`.
*/
orUndefined(): T | undefined;
/**
* Return the value if present, otherwise return `null`.
*
* @returns the value if present, otherwise `null`.
*/
orNull(): T | null;
/**
* Return the value if present, otherwise invoke other and return the result of that invocation.
*
* @param supplier The supplier to invoke when the value is not present.
* @returns either the value if present, the result of the given supplier otherwise.
*/
orElseGet(supplier: Supplier<T>): T;
/**
* Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
*
* @param exceptionSupplier
* @returns
*/
orElseThrow<U extends Error>(exceptionSupplier: Supplier<U>): T;
/**
* If a value is present, apply the provided resolver function to it, and if the result is non-null, return an Optional describing the result.
*
* @param resolver The resolver function.
* @param other The value to return if the Optional is empty.
* @returns the result Optional if a value is present, the given `other` parameter otherwise.
*/
resolve<U>(resolver: Function1<T, U>, other: U): U;
}
/**
* Tests if at least one element of the given array matches the predicate.
*
* @param array The array to test
* @param predicate The predicate used to test each element of the given array
* @returns `true` if at leat one element matches the given predicate, `false` otherwise.
*/
declare const arrayMatchOneOrMore: <T>(array: T[], predicate: Predicate<T>) => boolean;
/**
* Tests if exactly one element of the given array matches the predicate.
*
* @param array The array to test
* @param predicate The predicate used to test each element of the given array
* @returns `true` if one element only matches the given predicate, `false` otherwise.
*/
declare const arrayMatchOneExactly: <T>(array: T[], predicate: Predicate<T>) => boolean;
/**
* Tests if all elements of the given array match the predicate.
*
* @param array The array to test
* @param predicate The predicate used to test each element of the given array
* @returns `true` if all of the elements match the given predicate, `false` otherwise.
*/
declare const arrayMatchAll: <T>(array: T[], predicate: Predicate<T>) => boolean;
/**
* Tests whether the given arrays are exactly the same in length and content.
* If no predicate is given to compare the elements of the arrays, `===` will be used.
*
* @param array1 The first array to test
* @param array2 The second array to test
* @param comparator The predicate used to compare each element of the given arrays.
* @returns `true` if both arrays are equal, `false` otherwise.
*/
declare const arraysAreSame: <T>(array1: T[], array2: T[], comparator?: Function2<T, T, boolean>) => boolean;
/**
* Creates an array of the given length composed of a suite of numbers from `offset` to `offset + (length * step)`.
*
* @param length The length of the array to be created.
* @param offset The starting offset of the suite to be created. `1` is set by default.
* @returns the suite array from `offset` to `offset + (length * step)`.
*/
declare const arrayCreateSuite: (length: number, offset?: number, step?: number) => number[];
declare const EMPTY_ARRAY: never[];
/**
* Strips the given string array of any blank values (either `null`, `undefined` of empty string).
*
* @param array The string array to be cleaned.
* @returns `undefined` if the given array was undefined, the cleaned up array otherwise.
*/
declare const arrayCleanStringArray: (array?: (string | undefined | null)[]) => string[] | undefined;
/**
* Shuffles the elements of the given array to a random order.
*
* @param array The array to shuffle.
* @returns An array with every elements of the given array but in a random order.
*/
declare const arrayShuffle: <T>(array: T[]) => T[];
/**
* Strips the given array of duplicate values.
*
* @param array The array with potential duplicates.
* @returns An array where of elements are uniq.
*/
declare const arrayUniq: <T>(array: T[]) => T[];
/**
* Strips the given array of duplicate property values.
*
* @param array The array with potential duplicates.
* @param property The property to extract for the comparaison.
* @param comparator The predicate used to compare each element of the given arrays.
* @returns An array where of elements are uniq.
*/
declare const arrayUniqObjectsByProperty: <T extends {
[id: string]: any;
}>(array: T[], property: string, comparator?: Function2<T, T, boolean>) => T[];
/**
* Extracts the last element from the given array.
*
* @param array The array to extract the last element from.
* @returns the last element.
*/
declare const arrayLast: <T>(array: T[]) => T | undefined;
/**
* Extracts the last element from the given array as an optional.
*
* @param array The array to extract the last element from.
* @returns the last element as an optional.
*/
declare const arrayLastOptional: <T>(array: T[]) => Optional<T>;
/**
* Extracts the first element from the given array.
*
* @param array The array to extract the first element from.
* @returns the first element.
*/
declare const arrayFirst: <T>(array: T[]) => T | undefined;
/**
* Calculate the sum of the extracted values.
*
* @param array The array.
* @param valueExtractor The extractor used to retrieve values to be sum up.
* @returns the total.
*/
declare const arraySum: <T>(array: T[], valueExtractor?: (item: T) => number) => number;
/**
* Calculate the average of the extracted values.
*
* @param array The array.
* @param valueExtractor The extractor used to retrieve values to be averaged up.
* @returns the average.
*/
declare const arrayAverage: <T>(array: T[], valueExtractor?: (item: T) => number, rounded?: boolean) => number;
/**
* Extracts the first element from the given array as an optional.
*
* @param array The array to extract the first element from.
* @returns the first element as an optional.
*/
declare const arrayFirstOptional: <T>(array: T[]) => Optional<T>;
/**
* Push the given value to the given array only if the value is not already present in the given array.
*
* @param array The array in which to insert the new value.
* @param newValue The new value to insert.
* @param valueComparator The comparator used to compare values from the array.
*/
declare const arrayPushNewValue: <T>(array: T[], newValue: T, valueComparator?: (value1: T, value2: T) => boolean) => void;
/**
* Push the given values to the given array only if the values are not already present in the given array.
* The duplicate values will not be pushed but any other values will be.
*
* @param array The array in which to insert the new value.
* @param newValue The new values to insert.
* @param valueComparator The comparator used to compare values from the array.
*/
declare const arrayPushNewValues: <T>(array: T[], newValues: T[], valueComparator?: (value1: T, value2: T) => boolean) => void;
declare const ArrayHelpers: {
/**
* Tests if all elements of the given array match the predicate.
*
* @param array The array to test
* @param predicate The predicate used to test each element of the given array
* @returns `true` if all of the elements match the given predicate, `false` otherwise.
*/
matchAll: <T>(array: T[], predicate: Predicate<T>) => boolean;
/**
* Tests if exactly one element of the given array matches the predicate.
*
* @param array The array to test
* @param predicate The predicate used to test each element of the given array
* @returns `true` if one element only matches the given predicate, `false` otherwise.
*/
matchOneExactly: <T_1>(array: T_1[], predicate: Predicate<T_1>) => boolean;
/**
* Tests if at least one element of the given array matches the predicate.
*
* @param array The array to test
* @param predicate The predicate used to test each element of the given array
* @returns `true` if at leat one element matches the given predicate, `false` otherwise.
*/
matchOneOrMore: <T_2>(array: T_2[], predicate: Predicate<T_2>) => boolean;
/**
* Tests whether the given arrays are exactly the same in length and content.
* If no predicate is given to compare the elements of the arrays, `===` will be used.
*
* @param array1 The first array to test
* @param array2 The second array to test
* @param comparator The predicate used to compare each element of the given arrays.
* @returns `true` if both arrays are equal, `false` otherwise.
*/
same: <T_3>(array1: T_3[], array2: T_3[], comparator?: Function2<T_3, T_3, boolean> | undefined) => boolean;
/**
* Strips the given string array of any blank values (either `null`, `undefined` of empty string).
*
* @param array The string array to be cleaned.
* @returns `undefined` if the given array was undefined, the cleaned up array otherwise.
*/
cleanStringArray: (array?: (string | undefined | null)[]) => string[] | undefined;
/**
* Creates an array of the given length composed of a suite of numbers from `offset` to `offset + (length * step)`.
*
* @param length The length of the array to be created.
* @param offset The starting offset of the suite to be created. `1` is set by default.
* @returns the suite array from `offset` to `offset + (length * step)`.
*/
createSuite: (length: number, offset?: number, step?: number) => number[];
/**
* Shuffles the elements of the given array to a random order.
*
* @param array The array to shuffle.
* @returns An array with every elements of the given array but in a random order.
*/
shuffle: <T_4>(array: T_4[]) => T_4[];
/**
* Strips the given array of duplicate values.
*
* @param array The array with potential duplicates.
* @returns An array where of elements are uniq.
*/
uniq: <T_5>(array: T_5[]) => T_5[];
/**
* Strips the given array of duplicate property values.
*
* @param array The array with potential duplicates.
* @param property The property to extract for the comparaison.
* @param comparator The predicate used to compare each element of the given arrays.
* @returns An array where of elements are uniq.
*/
uniqObjectsByProperty: <T_6 extends {
[id: string]: any;
}>(array: T_6[], property: string, comparator?: Function2<T_6, T_6, boolean> | undefined) => T_6[];
/**
* Extracts the last element from the given array.
*
* @param array The array to extract the last element from.
* @returns the last element.
*/
last: <T_7>(array: T_7[]) => T_7 | undefined;
/**
* Extracts the last element from the given array as an optional.
*
* @param array The array to extract the last element from.
* @returns the last element as an optional.
*/
lastOptional: <T_8>(array: T_8[]) => Optional<T_8>;
/**
* Extracts the first element from the given array.
*
* @param array The array to extract the first element from.
* @returns the first element.
*/
first: <T_9>(array: T_9[]) => T_9 | undefined;
/**
* Extracts the first element from the given array as an optional.
*
* @param array The array to extract the first element from.
* @returns the first element as an optional.
*/
firstOptional: <T_10>(array: T_10[]) => Optional<T_10>;
/**
* Calculate the sum of the extracted values.
*
* @param array The array.
* @param valueExtractor The extractor used to retrieve values to be sum up.
* @returns the total.
*/
sum: <T_11>(array: T_11[], valueExtractor?: ((item: T_11) => number) | undefined) => number;
/**
* Calculate the average of the extracted values.
*
* @param array The array.
* @param valueExtractor The extractor used to retrieve values to be averaged up.
* @returns the average.
*/
average: <T_12>(array: T_12[], valueExtractor?: ((item: T_12) => number) | undefined, rounded?: boolean) => number;
/**
* Push the given value to the given array only if the value is not already present in the given array.
*
* @param array The array in which to insert the new value.
* @param newValue The new value to insert.
* @param valueComparator The comparator used to compare values from the array.
*/
pushNewValue: <T_13>(array: T_13[], newValue: T_13, valueComparator?: ((value1: T_13, value2: T_13) => boolean) | undefined) => void;
/**
* Push the given values to the given array only if the values are not already present in the given array.
* The duplicate values will not be pushed but any other values will be.
*
* @param array The array in which to insert the new value.
* @param newValue The new values to insert.
* @param valueComparator The comparator used to compare values from the array.
*/
pushNewValues: <T_14>(array: T_14[], newValues: T_14[], valueComparator?: ((value1: T_14, value2: T_14) => boolean) | undefined) => void;
};
declare const ArraySymbols: {
/**
* An empty array.
*/
empty: never[];
};
declare const Arrays: {
/**
* Array helper methods.
*/
helper: {
/**
* Tests if all elements of the given array match the predicate.
*
* @param array The array to test
* @param predicate The predicate used to test each element of the given array
* @returns `true` if all of the elements match the given predicate, `false` otherwise.
*/
matchAll: <T>(array: T[], predicate: Predicate<T>) => boolean;
/**
* Tests if exactly one element of the given array matches the predicate.
*
* @param array The array to test
* @param predicate The predicate used to test each element of the given array
* @returns `true` if one element only matches the given predicate, `false` otherwise.
*/
matchOneExactly: <T_1>(array: T_1[], predicate: Predicate<T_1>) => boolean;
/**
* Tests if at least one element of the given array matches the predicate.
*
* @param array The array to test
* @param predicate The predicate used to test each element of the given array
* @returns `true` if at leat one element matches the given predicate, `false` otherwise.
*/
matchOneOrMore: <T_2>(array: T_2[], predicate: Predicate<T_2>) => boolean;
/**
* Tests whether the given arrays are exactly the same in length and content.
* If no predicate is given to compare the elements of the arrays, `===` will be used.
*
* @param array1 The first array to test
* @param array2 The second array to test
* @param comparator The predicate used to compare each element of the given arrays.
* @returns `true` if both arrays are equal, `false` otherwise.
*/
same: <T_3>(array1: T_3[], array2: T_3[], comparator?: Function2<T_3, T_3, boolean> | undefined) => boolean;
/**
* Strips the given string array of any blank values (either `null`, `undefined` of empty string).
*
* @param array The string array to be cleaned.
* @returns `undefined` if the given array was undefined, the cleaned up array otherwise.
*/
cleanStringArray: (array?: (string | undefined | null)[]) => string[] | undefined;
/**
* Creates an array of the given length composed of a suite of numbers from `offset` to `offset + (length * step)`.
*
* @param length The length of the array to be created.
* @param offset The starting offset of the suite to be created. `1` is set by default.
* @returns the suite array from `offset` to `offset + (length * step)`.
*/
createSuite: (length: number, offset?: number, step?: number) => number[];
/**
* Shuffles the elements of the given array to a random order.
*
* @param array The array to shuffle.
* @returns An array with every elements of the given array but in a random order.
*/
shuffle: <T_4>(array: T_4[]) => T_4[];
/**
* Strips the given array of duplicate values.
*
* @param array The array with potential duplicates.
* @returns An array where of elements are uniq.
*/
uniq: <T_5>(array: T_5[]) => T_5[];
/**
* Strips the given array of duplicate property values.
*
* @param array The array with potential duplicates.
* @param property The property to extract for the comparaison.
* @param comparator The predicate used to compare each element of the given arrays.
* @returns An array where of elements are uniq.
*/
uniqObjectsByProperty: <T_6 extends {
[id: string]: any;
}>(array: T_6[], property: string, comparator?: Function2<T_6, T_6, boolean> | undefined) => T_6[];
/**
* Extracts the last element from the given array.
*
* @param array The array to extract the last element from.
* @returns the last element.
*/
last: <T_7>(array: T_7[]) => T_7 | undefined;
/**
* Extracts the last element from the given array as an optional.
*
* @param array The array to extract the last element from.
* @returns the last element as an optional.
*/
lastOptional: <T_8>(array: T_8[]) => Optional<T_8>;
/**
* Extracts the first element from the given array.
*
* @param array The array to extract the first element from.
* @returns the first element.
*/
first: <T_9>(array: T_9[]) => T_9 | undefined;
/**
* Extracts the first element from the given array as an optional.
*
* @param array The array to extract the first element from.
* @returns the first element as an optional.
*/
firstOptional: <T_10>(array: T_10[]) => Optional<T_10>;
/**
* Calculate the sum of the extracted values.
*
* @param array The array.
* @param valueExtractor The extractor used to retrieve values to be sum up.
* @returns the total.
*/
sum: <T_11>(array: T_11[], valueExtractor?: ((item: T_11) => number) | undefined) => number;
/**
* Calculate the average of the extracted values.
*
* @param array The array.
* @param valueExtractor The extractor used to retrieve values to be averaged up.
* @returns the average.
*/
average: <T_12>(array: T_12[], valueExtractor?: ((item: T_12) => number) | undefined, rounded?: boolean) => number;
/**
* Push the given value to the given array only if the value is not already present in the given array.
*
* @param array The array in which to insert the new value.
* @param newValue The new value to insert.
* @param valueComparator The comparator used to compare values from the array.
*/
pushNewValue: <T_13>(array: T_13[], newValue: T_13, valueComparator?: ((value1: T_13, value2: T_13) => boolean) | undefined) => void;
/**
* Push the given values to the given array only if the values are not already present in the given array.
* The duplicate values will not be pushed but any other values will be.
*
* @param array The array in which to insert the new value.
* @param newValue The new values to insert.
* @param valueComparator The comparator used to compare values from the array.
*/
pushNewValues: <T_14>(array: T_14[], newValues: T_14[], valueComparator?: ((value1: T_14, value2: T_14) => boolean) | undefined) => void;
};
/**
* Array symbols.
*/
symbol: {
/**
* An empty array.
*/
empty: never[];
};
};
/**
* Order type utility for sorting functions.
*/
type Order = "asc" | "desc";
declare const DATE_DEFAULT_SEPARATOR = "/";
declare const TIME_DEFAULT_SEPARATOR = ":";
/**
* Type of handled date formats.
*/
type DateFormat = "short-date-fr" | "short-date-us" | "short-date-time-fr" | "short-date-time-us" | "basic-date" | "basic-date-time" | "reverse" | "time";
/**
* Options for date fomatters.
*/
interface DateFormatOptions {
/**
* The separator between day, month and year.
*/
dateSeparator?: string;
/**
* The separator between hours and minutes.
*/
timeSeparator?: string;
/**
* The separator between day, month and year.
*
* @deprecated Use `dateSeparator` or `timeSeparator` instead.
*/
separator?: string;
/**
* The desired date format.
*/
format?: DateFormat;
}
/**
* Formats a date.
*
* @param date The date to format.
* @param options Options.
* @returns The given date formated accordingly to the given options.
*/
declare const dateFormat: (date?: Date, options?: DateFormatOptions) => string;
/**
* Gets today's date as a string formated in the format specified in the given options parameter
*
* @param options Options.
* @returns today's date as a string.
*/
declare const dateTodayAsString: (options?: DateFormatOptions) => string;
/**
* Gets a date comparator function in the given order.
*
* @param order The order of the result.
* @returns a comparator function in the given order.
*/
declare const dateGetComparator: (order?: Order) => (a: Date, b: Date) => number;
/**
* An ascendent date comparator.
*/
declare const DATE_COMPARATOR_ASC: (a: Date, b: Date) => number;
/**
* An descendent date comparator.
*/
declare const DATE_COMPARATOR_DESC: (a: Date, b: Date) => number;
/**
* Gets a formated date comparator function in the given order.
*
* @param order The order of the result.
* @returns a comparator function in the given order.
*/
declare const dateGetAsStringComparator: (dateFormat: string, order?: Order) => (a: string, b: string) => number;
/**
* An ascendent formated date comparator.
*/
declare const DATE_AS_STRING_COMPARATOR_ASC: (a: string, b: string) => number;
/**
* An descendent formated date comparator.
*/
declare const DATE_AS_STRING_COMPARATOR_DESC: (a: string, b: string) => number;
/**
* Gets a Date corresponding to now.
*
* @returns a `Date` object.
*/
declare const dateNow: () => Date;
/**
* Gets a Date corresponding to the given number of days in the past.
*
* @param nbOfDays The number of days in the past.
* @returns a `Date` object.
*/
declare const dateDaysAgo: (nbOfDays?: number) => Date;
/**
* Gets a Date corresponding to the given number of days in the future.
*
* @param nbOfDays The number of days in the future.
* @returns a `Date` object.
*/
declare const dateInDays: (nbOfDays?: number) => Date;
/**
* Gets a Date corresponding to yesterday.
*
* @returns a `Date` object.
*/
declare const dateYesterday: () => Date;
/**
* Gets a Date corresponding to yesterday.
*
* @returns a `Date` object.
*/
declare const dateTomorrow: () => Date;
/**
* Tests whether the first given date is before the second given date.
*
* @param date The first date to compare.
* @param date The second date to compare.
* @returns `true` if the first given date is before the second given date, `false` otherwise.
*/
declare const dateIsBefore: (date1: Date | number, date2: Date | number) => boolean;
/**
* Tests whether the first given date is after the second given date.
*
* @param date The first date to compare.
* @param date The second date to compare.
* @returns `true` if the first given date is after the second given date, `false` otherwise.
*/
declare const dateIsAfter: (date1: Date | number, date2: Date | number) => boolean;
/**
* Tests whether the first given date is the same as the second given date.
*
* @param date The first date to compare.
* @param date The second date to compare.
* @returns `true` if the first given date is the same as the second given date, `false` otherwise.
*/
declare const dateIsSameDay: (date1: Date, date2: Date) => boolean;
/**
* Tests whether the given date happened before the given number of days in the future relatively to today.
*
* @param date The date to compare.
* @param nbOfDays The number of days in the future.
* @returns `true` if the given date happened before `today + nbOfDays`, `false` otherwise.
*/
declare const dateIsBeforeInDays: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happens after the given number of days in the future relatively to today.
*
* @param date The date to compare.
* @param nbOfDays The number of days in the future.
* @returns `true` if the given date happens after `today + nbOfDays`, `false` otherwise.
*/
declare const dateIsAfterInDays: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happened before the given number of days in the past relatively to today.
*
* @param date The date to compare.
* @param nbOfDays The number of days in the future.
* @returns `true` if the given date happened before `today - nbOfDays`, `false` otherwise.
*/
declare const dateIsBeforeDaysAgo: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happens after the given number of days in the past relatively to today.
*
* @param date The date to compare.
* @param nbOfDays The number of days in the future.
* @returns `true` if the given date happens after `today - nbOfDays`, `false` otherwise.
*/
declare const dateIsAfterDaysAgo: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happens today.
*
* @param date The date to compare.
* @returns `true` if the given date happens today, `false` otherwise.
*/
declare const dateIsToday: (date: Date) => boolean;
/**
* Tests whether the given date happened before today.
*
* @param date The date to compare.
* @returns `true` if the given date happened before today, `false` otherwise.
*/
declare const dateIsPast: (date: Date) => boolean;
/**
* Tests whether the given date happens after today.
*
* @param date The date to compare.
* @returns `true` if the given date happens after today, `false` otherwise.
*/
declare const dateIsFuture: (date: Date) => boolean;
/**
* Tests whether the given date happens tomorrow.
*
* @param date The date to compare.
* @returns `true` if the given date happens tomorrow, `false` otherwise.
*/
declare const dateIsTomorrow: (date: Date) => boolean;
/**
* Tests whether the given date happened yesterday.
*
* @param date The date to compare.
* @returns `true` if the given date happened yesterday, `false` otherwise.
*/
declare const dateIsYesterday: (date: Date) => boolean;
/**
* Tests whether the given date happened the given number of days in the past.
*
* @param date The date to compare.
* @returns `true` if the given date happened `today - nbOfDays`, `false` otherwise.
*/
declare const dateIsDaysAgo: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happens the given number of days in the future.
*
* @param date The date to compare.
* @returns `true` if the given date happens `today + nbOfDays`, `false` otherwise.
*/
declare const dateIsInDays: (date: Date, nbOfDays?: number) => boolean;
declare const DateHelpers: {
/**
* Formats a date.
*
* @param date The date to format.
* @param options Options.
* @returns The given date formated accordingly to the given options.
*/
format: (date?: Date, options?: DateFormatOptions) => string;
/**
* Gets today's date as a string formated in the format specified in the given options parameter.
*
* @param separator The separator between day, month and year.
* @returns today's date as a string.
*/
today: (options?: DateFormatOptions) => string;
/**
* Gets a Date corresponding to now.
*
* @returns a `Date` object.
*/
now: () => Date;
/**
* Gets a Date corresponding to the given number of days in the past.
*
* @param nbOfDays The number of days in the past.
* @returns a `Date` object.
*/
daysAgo: (nbOfDays?: number) => Date;
/**
* Gets a Date corresponding to the given number of days in the future.
*
* @param nbOfDays The number of days in the future.
* @returns a `Date` object.
*/
inDays: (nbOfDays?: number) => Date;
/**
* Gets a Date corresponding to yesterday.
*
* @returns a `Date` object.
*/
yesterday: () => Date;
/**
* Gets a Date corresponding to yesterday.
*
* @returns a `Date` object.
*/
tomorrow: () => Date;
/**
* Tests whether the first given date is before the second given date.
*
* @param date The first date to compare.
* @param date The second date to compare.
* @returns `true` if the first given date is before the second given date, `false` otherwise.
*/
isBefore: (date1: Date | number, date2: Date | number) => boolean;
/**
* Tests whether the first given date is after the second given date.
*
* @param date The first date to compare.
* @param date The second date to compare.
* @returns `true` if the first given date is after the second given date, `false` otherwise.
*/
isAfter: (date1: Date | number, date2: Date | number) => boolean;
/**
* Tests whether the first given date is the same as the second given date.
*
* @param date The first date to compare.
* @param date The second date to compare.
* @returns `true` if the first given date is the same as the second given date, `false` otherwise.
*/
isSameDay: (date1: Date, date2: Date) => boolean;
/**
* Tests whether the given date happened before the given number of days in the future relatively to today.
*
* @param date The date to compare.
* @param nbOfDays The number of days in the future.
* @returns `true` if the given date happened before `today + nbOfDays`, `false` otherwise.
*/
isBeforeInDays: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happens after the given number of days in the future relatively to today.
*
* @param date The date to compare.
* @param nbOfDays The number of days in the future.
* @returns `true` if the given date happens after `today + nbOfDays`, `false` otherwise.
*/
isAfterInDays: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happened before the given number of days in the past relatively to today.
*
* @param date The date to compare.
* @param nbOfDays The number of days in the future.
* @returns `true` if the given date happened before `today - nbOfDays`, `false` otherwise.
*/
isBeforeDaysAgo: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happens after the given number of days in the past relatively to today.
*
* @param date The date to compare.
* @param nbOfDays The number of days in the future.
* @returns `true` if the given date happens after `today - nbOfDays`, `false` otherwise.
*/
isAfterDaysAgo: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happens today.
*
* @param date The date to compare.
* @returns `true` if the given date happens today, `false` otherwise.
*/
isToday: (date: Date) => boolean;
/**
* Tests whether the given date happened before today.
*
* @param date The date to compare.
* @returns `true` if the given date happened before today, `false` otherwise.
*/
isPast: (date: Date) => boolean;
/**
* Tests whether the given date happens after today.
*
* @param date The date to compare.
* @returns `true` if the given date happens after today, `false` otherwise.
*/
isFuture: (date: Date) => boolean;
/**
* Tests whether the given date happens tomorrow.
*
* @param date The date to compare.
* @returns `true` if the given date happens tomorrow, `false` otherwise.
*/
isTomorrow: (date: Date) => boolean;
/**
* Tests whether the given date happened yesterday.
*
* @param date The date to compare.
* @returns `true` if the given date happened yesterday, `false` otherwise.
*/
isYesterday: (date: Date) => boolean;
/**
* Tests whether the given date happened the given number of days in the past.
*
* @param date The date to compare.
* @returns `true` if the given date happened `today - nbOfDays`, `false` otherwise.
*/
isDaysAgo: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happens the given number of days in the future.
*
* @param date The date to compare.
* @returns `true` if the given date happens `today + nbOfDays`, `false` otherwise.
*/
isInDays: (date: Date, nbOfDays?: number) => boolean;
};
declare const DateComparators: {
/**
* An ascendent date comparator.
*/
asc: (a: Date, b: Date) => number;
/**
* An descendent date comparator.
*/
desc: (a: Date, b: Date) => number;
/**
* An ascendent formated date comparator.
*/
asStringAsc: (a: string, b: string) => number;
/**
* An descendent formated date comparator.
*/
asStringDesc: (a: string, b: string) => number;
};
declare const Dates: {
/**
* Date helper methods.
*/
helper: {
/**
* Formats a date.
*
* @param date The date to format.
* @param options Options.
* @returns The given date formated accordingly to the given options.
*/
format: (date?: Date, options?: DateFormatOptions) => string;
/**
* Gets today's date as a string formated in the format specified in the given options parameter.
*
* @param separator The separator between day, month and year.
* @returns today's date as a string.
*/
today: (options?: DateFormatOptions) => string;
/**
* Gets a Date corresponding to now.
*
* @returns a `Date` object.
*/
now: () => Date;
/**
* Gets a Date corresponding to the given number of days in the past.
*
* @param nbOfDays The number of days in the past.
* @returns a `Date` object.
*/
daysAgo: (nbOfDays?: number) => Date;
/**
* Gets a Date corresponding to the given number of days in the future.
*
* @param nbOfDays The number of days in the future.
* @returns a `Date` object.
*/
inDays: (nbOfDays?: number) => Date;
/**
* Gets a Date corresponding to yesterday.
*
* @returns a `Date` object.
*/
yesterday: () => Date;
/**
* Gets a Date corresponding to yesterday.
*
* @returns a `Date` object.
*/
tomorrow: () => Date;
/**
* Tests whether the first given date is before the second given date.
*
* @param date The first date to compare.
* @param date The second date to compare.
* @returns `true` if the first given date is before the second given date, `false` otherwise.
*/
isBefore: (date1: Date | number, date2: Date | number) => boolean;
/**
* Tests whether the first given date is after the second given date.
*
* @param date The first date to compare.
* @param date The second date to compare.
* @returns `true` if the first given date is after the second given date, `false` otherwise.
*/
isAfter: (date1: Date | number, date2: Date | number) => boolean;
/**
* Tests whether the first given date is the same as the second given date.
*
* @param date The first date to compare.
* @param date The second date to compare.
* @returns `true` if the first given date is the same as the second given date, `false` otherwise.
*/
isSameDay: (date1: Date, date2: Date) => boolean;
/**
* Tests whether the given date happened before the given number of days in the future relatively to today.
*
* @param date The date to compare.
* @param nbOfDays The number of days in the future.
* @returns `true` if the given date happened before `today + nbOfDays`, `false` otherwise.
*/
isBeforeInDays: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happens after the given number of days in the future relatively to today.
*
* @param date The date to compare.
* @param nbOfDays The number of days in the future.
* @returns `true` if the given date happens after `today + nbOfDays`, `false` otherwise.
*/
isAfterInDays: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happened before the given number of days in the past relatively to today.
*
* @param date The date to compare.
* @param nbOfDays The number of days in the future.
* @returns `true` if the given date happened before `today - nbOfDays`, `false` otherwise.
*/
isBeforeDaysAgo: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happens after the given number of days in the past relatively to today.
*
* @param date The date to compare.
* @param nbOfDays The number of days in the future.
* @returns `true` if the given date happens after `today - nbOfDays`, `false` otherwise.
*/
isAfterDaysAgo: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happens today.
*
* @param date The date to compare.
* @returns `true` if the given date happens today, `false` otherwise.
*/
isToday: (date: Date) => boolean;
/**
* Tests whether the given date happened before today.
*
* @param date The date to compare.
* @returns `true` if the given date happened before today, `false` otherwise.
*/
isPast: (date: Date) => boolean;
/**
* Tests whether the given date happens after today.
*
* @param date The date to compare.
* @returns `true` if the given date happens after today, `false` otherwise.
*/
isFuture: (date: Date) => boolean;
/**
* Tests whether the given date happens tomorrow.
*
* @param date The date to compare.
* @returns `true` if the given date happens tomorrow, `false` otherwise.
*/
isTomorrow: (date: Date) => boolean;
/**
* Tests whether the given date happened yesterday.
*
* @param date The date to compare.
* @returns `true` if the given date happened yesterday, `false` otherwise.
*/
isYesterday: (date: Date) => boolean;
/**
* Tests whether the given date happened the given number of days in the past.
*
* @param date The date to compare.
* @returns `true` if the given date happened `today - nbOfDays`, `false` otherwise.
*/
isDaysAgo: (date: Date, nbOfDays?: number) => boolean;
/**
* Tests whether the given date happens the given number of days in the future.
*
* @param date The date to compare.
* @returns `true` if the given date happens `today + nbOfDays`, `false` otherwise.
*/
isInDays: (date: Date, nbOfDays?: number) => boolean;
};
/**
* Date comparators.
*/
comparator: {
/**
* An ascendent date comparator.
*/
asc: (a: Date, b: Date) => number;
/**
* An descendent date comparator.
*/
desc: (a: Date, b: Date) => number;
/**
* An ascendent formated date comparator.
*/
asStringAsc: (a: string, b: string) => number;
/**
* An descendent formated date comparator.
*/
asStringDesc