/** * A `[min, max]` tuple to denote one integer range. */ export declare type Range = readonly [min: number, max: number]; /** * An immutable Range array. This is the fundamental data type of this package. * * **Warning**: Most functions of this package work correctly * only when **normalized** MultiIntegerRange's are passed. * If you have a Range array that may not be sorted, use `normalize()` first. */ export declare type MultiIntegerRange = readonly Range[]; export declare type MIR = MultiIntegerRange; export declare type Options = { /** * Parses negative integers enclosed in parentheses. */ readonly parseNegative?: boolean; /** * Parses unbounded ranges like `10-` or `-10`. */ readonly parseUnbounded?: boolean; }; /** * Parses a string and creates a new MultiIntegerRange. * * - `options.parseNegative` (boolean): When set to true, parses negative integers enclosed in parentheses. * - `options.parseUnbounded` (boolean): When set to true, parses unbounded ranges like `10-` or `-10`. * * This is the default parser, but you don't necessary have to use this. * You can create your own parser to suit your needs * as long as it produces a normalized array of `Range`s. * * @param data - The string to parse. * @param options - Options to modify the parsing behavior. * @returns A new normalized MultiIntegerRange. * @example * parse('1-10'); // [[1, 10]] * parse(' 10-, 7', \{ parseUnbounded: true \}); // [[7, 7], [10, Infinity]] */ export declare const parse: (data: string, options?: Options) => MultiIntegerRange; /** * Takes a number or an unsorted array of ranges, * and returns a new normalized MultiIntegerRange. * * Here, "normalized" means the range data is in the smallest possible * representation and is sorted in ascending order. * * This is the only function that can take an unsorted array of Range's. * Unsorted range data MUST be normalized before being passed to * other functions such as `append()` and `length()`. * * @param data - A number or an unsorted array, e.g., `[[7, 5], 1]`. * @returns Normalized array, e.g., `[[1, 1], [5, 7]]`. * @example * normalize(5); // [[5, 5]] * normalize([1, 8]); // [[1, 1], [8, 8]] * normalize([[1, 8]]); // [[1, 8]] * normalize([2, 3, 1, 5, 4, 0, 1, 3]); // [[0, 5]] * normalize([[Infinity, 1]]); // [[1, Infinity]] */ export declare const normalize: (data?: (number | Range)[] | number) => MultiIntegerRange; /** * Takes any supported data and returns a normalized MultiIntegerRange. * Conditionally calls either `parse()` or `normalize()` under the hood. * This is an equivalent of "initializer" constructor of version ≤ 4. * @param data - Anything understood by either `parse()` or `normalize()`. * @param options - Parse options passed to `parse()`. * @returns A new normalized MultiIntegerRange. * @example * initialize(5); // [[5, 5]] * initialize('2-8'); // [[2,8]] */ export declare const initialize: (data?: (number | Range)[] | number | string, options?: Options) => MultiIntegerRange; /** * Appends two MultiIntegerRange's. * @param a - The first value. * @param b - The second value. * @returns A new MultiIntegerRange containing all integers that belong to * **either `a` or `b` (or both)**. * @example * append([[1, 5]], [[3, 8], [10, 15]]); // [[1, 8], [10, 15]] * append([[5, 9]], [[-Infinity, 2]]); // [[-Infinity, 2], [5, 9]] */ export declare const append: (a: MultiIntegerRange, b: MultiIntegerRange) => MultiIntegerRange; /** * Subtracts the second value from the first value. * @param a - The value to be subtracted. * @param b - The value to subtract. * @returns A new MultiIntegerRange containing all integers that belong to * **`a` but not `b`**. * @example * subtract([[1, 7]], [[2, 4]]); // [[1, 1], [5, 7]] * subtract([[-Infinity, Infinity]], [[2, 4]]); // [[-Infinity, 1], [5, Infinity]] */ export declare const subtract: (a: MultiIntegerRange, b: MultiIntegerRange) => MultiIntegerRange; /** * Calculates the intersection (common integers) of the two MultiIntegerRange's. * @param a - The first value. * @param b - The second value. * @returns A new MultiIntegerRange containing all integers * that belong to **both `a` and `b`**. * @example * intersect([[2, 5]], [[4, 9]]); // [[4, 5]] * intersect([[5, 10]], [[-Infinity, Infinity]]); // [[5, 10]] */ export declare const intersect: (a: MultiIntegerRange, b: MultiIntegerRange) => MultiIntegerRange; /** * Checks if `a` contains or is equal to `b` (a ⊇ b). * @param a - The value that possibly contains `b`. * @param b - The value that is possibly contained by `a`. * @returns True if `b` is equal to or a subset of `a`. * @example * has([[0, 100]], [[2, 10]]); // true * has([[5, 7]], [[5, 7]]); // true * has([[2, 10]], [[0, 100]]); // false */ export declare const has: (a: MultiIntegerRange, b: MultiIntegerRange) => boolean; /** * Calculates how many integers are included in the given MultiIntegerRange. * * Note: If you want to know the number of Ranges (segments), just use the * standard `Array#length`. * @param data - The value to calculate the length on. * @returns The number of integers contained in `data`. May be `Infinity`. * @example * length([[1, 3], [8, 10]]); // 6 * length([[1, Infinity]]); // Infinity */ export declare const length: (data: MultiIntegerRange) => number; /** * Checks if the data contains an unbounded (aka inifinite) range. * @param data - The value to check. * @returns True if `data` is unbounded. * @example * isUnbounded([[1, Infinity]]); // true * isUnbounded([[-Infinity, 4]]); // true * isUnbounded([[7, 9]]); // false */ export declare const isUnbounded: (data: MultiIntegerRange) => boolean; /** * Checks if the two values are the same. (Altenatively, you can use any * "deep-equal" utility function.) * @param a - The first value to compare. * @param b - The second value to compare. * @returns True if `a` and `b` have the same range data. * @example * equals([[1, 5], [7, 8]], [[1, 5], [7, 8]]); // true * equals([[1, 5]], [[2, 7]]); // false */ export declare const equals: (a: MultiIntegerRange, b: MultiIntegerRange) => boolean; /** * Returns the minimum integer of the given MultiIntegerRange. * @param data - The value. * @returns The minimum integer. May be `undefined` or `-Infinity`. * @example * min([[2, 5], [8, 10]]); // 2 * min([[-Infinity, 0]]); // -Infinity * min([]); // undefined */ export declare const min: (data: MultiIntegerRange) => number | undefined; /** * Returns the maximum integer of the given MultiIntegerRange. * @param data - The value. * @returns The minimum integer. May be `undefined` or `Infinity`. * @example * max([[2, 5], [8, 10]]); // 10 * max([[3, Infinity]]); // Infinity * max([]); // undefined */ export declare const max: (data: MultiIntegerRange) => number | undefined; /** * Returns all but the minimum integer. * @param data - The value. * @returns A new MultiIntegerRange which is almost the same as `data` but with * its minimum integer removed. * @example * tail([[2, 5], [8, 10]]); // [[3, 5], [8, 10]] */ export declare const tail: (data: MultiIntegerRange) => MultiIntegerRange; /** * Returns all but the maximum integer. * @param data - The value. * @returns A new MultiIntegerRange which is almost the same as `data` but with * its maximum integer removed. * @example * init([[2, 5], [8, 10]]); // [[2, 5], [8, 9]] */ export declare const init: (data: MultiIntegerRange) => MultiIntegerRange; /** * Returns the string respresentation of the given MultiIntegerRange. * @param data - The MultiIntegerRange to stringify. * @returns The string representation of the given data. * @example * stringify([[3, 5], [7, Infinity]]); // '3-5,7-' */ export declare const stringify: (data: MultiIntegerRange) => string; /** * Builds a flattened array of integers. * Note that this may be slow and memory-consuming for large ranges. * Consider using the iterator whenever possible. * @param data - The value to build an array on. * @returns The flattened array of numbers. * @example * flatten([[-1, 1], [7, 9]]); // [-1, 0, 1, 7, 8, 9] */ export declare const flatten: (data: MultiIntegerRange) => number[]; /** * Returns an Iterable with which you can use `for-of` or the spread syntax. * @param data - The normalized MultiIntegerRange to iterate over. * @returns An Iterable object. * @example * Array.from(iterate([[1, 3], [7, 9]])); // [1, 2, 3, 7, 8, 9] * [...iterate([[-1, 1]])]; // [-1, 0, 1] */ export declare const iterate: (data: MultiIntegerRange) => Iterable;