UNPKG

@sheetxl/models

Version:

Models - A Headless javascript spreadsheet library.

120 lines (119 loc) 4.74 kB
/** * A RunCoords represents a discrete set of values in a single dimension. */ export interface RunCoords { min: number; max: number; } /** * A RunCoords with data associated with it. */ export interface Run<T> extends RunCoords { data?: T; } export interface ModifiedRuns<T> { preceding: Run<T>[]; modified: Run<T>[]; trailing: Run<T>[]; } export declare const deepUpdate: (prevValue: any | null, newValue: any | null) => any | null; export declare const deepCull: (data: any, _min: number, _max: number) => boolean; export interface UpdateAndCompactOptions<T> { /** * Returns an updated value. If not specified a deep merge is done. * * IMPORTANT - * both prevValue and newValue should be treated as frozen object and not * mutated. * A new value should always be returned. If you want to augment a value * The deepUpdateMethod is offered * */ onUpdate?: (prevValue: any | null, newValue: any | null, run: Run<T>) => any | null; isEqual?(a: any, b: any): boolean; /** * Used to determine if a entry should removed. If data is null or undefined it will also be removed. * By default an empty object will not be. */ cull?(data: any, min: number, max: number): boolean; } export declare const shiftRuns: (runs: Run<any>[], index: number, amount?: number) => ModifiedRuns<any>; export declare const unshiftRuns: (runs: Run<any>[], index: number, amount?: number) => ModifiedRuns<any>; export declare const unshiftAndMergeRuns: (runs: Run<any>[], index: number, amount?: number, options?: MergeRunOptions) => ModifiedRuns<any>; /** * Will take a list of runs and return the minimum set required. * * @param runs * @param update * @param options @UpdateAndCompactOptions */ export declare const updateAndCompactRuns: (runs: Run<any>[], update: Run<any>, options?: UpdateAndCompactOptions<any>) => ModifiedRuns<any>; export declare function concatModifiedRuns(parts: ModifiedRuns<any>): Run<any>[]; /** * Split/update algo used for formatted text. * This will split and update runs * All runs must be: * ** ordered * ** non-overlapping * Runs do not need to be contiguous. */ export declare const splitAndUpdateRuns: (runs: Run<any>[], update: Run<any>, onUpdate?: (prevValue: any | null, newValue: any | null, run: Run<any>) => any | null) => ModifiedRuns<any>; interface CullRunsOptions { startOffset?: number; endOffset?: number; /** * Used to determine if a value should removed. If data is null or undefined it will also be removed. * By default an empty object will not be. */ cull?(data: any, min: number, max: number): boolean; } export declare const cullRuns: (runs: Run<any>[], options?: CullRunsOptions) => ModifiedRuns<any>; export interface MergeRunOptions { startOffset?: number; endOffset?: number; isEqual?(a: any, b: any): boolean; } /** * Merges runs. Runs must be sorted; see @sortRuns */ export declare const mergeRuns: (runs: Run<any>[], options?: MergeRunOptions) => ModifiedRuns<any>; export declare const sortRuns: (a: Run<any>[]) => Run<any>[]; /** * Sorts twos runs by their min values. */ export declare const sortTwoRuns: (a: Run<any>, b: Run<any>, forward?: boolean) => Run<any>[]; export declare const isContiguousRuns: (a: Run<any>, b: Run<any>) => boolean; /** * Will merge two runs if they are contiguous. */ export declare const mergeTwoRuns: (a: Run<any>, b: Run<any>, forward?: boolean) => Run<any>; export declare const runContainsIndex: (index: number, run: Run<any>) => boolean; export declare const boundaryEdge: (index: number, run: Run<any>, findGreater: boolean) => number; export declare const boundaryNext: (index: number, run: Run<any>, findGreater: boolean) => number; /** * Looks for a run going in a certain direction. If there isn't a run for this it will look for the next * run. If you only want the run if it is found @see {@link findRun}. * @param runs * @param value * @param findGreater * @returns */ export declare const findNextRun: (runs: Run<any>[], value: number, findGreater?: boolean) => Run<any>; export declare const findRun: (runs: Run<any>[], value: number) => Run<any> | null; export declare const indicesToRuns: (indices: number[]) => Run<any>[]; export type RunVisitor = (run: Run<any>) => { break: any; } | void; /** * Scans all of the runs. It will scan each run exactly once. * In additional if there are gaps it will create an empty run. * @param runs * @param visitor * @param start * @param end */ export declare const scanRuns: (runs: Run<any>[], visitor: RunVisitor, start?: number, end?: number) => { break: any; } | void; export {}; //# sourceMappingURL=RunUtils.d.ts.map