'use strict' ; import type DataEventEmitter from '../DataEventEmitter' ; import type JSON from '../../Core/JSON' ; import DataModifier from './DataModifier.js' ; import DataTable from '../DataTable.js' ; import U from '../../Core/Utilities.js' ; const { merge } = U ; private class RangeModifier extends DataModifier { /**
     * Default options for the range modifier.
     */ public static readonly defaultOptions : RangeModifier . Options = { modifier : 'Range' , strict : false , ranges : [ ] } ; param { RangeModifier . Options } options public constructor ( options ? ) { super ( ) ; this . options = merge ( RangeModifier . defaultOptions , options ) ; } /**
     * Options of the range modifier.
     */ public readonly options : Readonly < RangeModifier . Options > ; param { DataTable } table param { DataEventEmitter . EventDetail } eventDetail return { DataTable } public modifyTable < T extends DataTable > ( table , eventDetail ? ) { const modifier = this ; modifier . emit ( { type : 'modify' , detail : eventDetail , table } ) ; const { ranges , strict } = modifier . options ; if ( ranges . length ) { const columns = table . getColumns ( ) , rows = [ ] , modified = table . modified ; for ( let i = 0 , iEnd = ranges . length , range , rangeColumn ; i < iEnd ; ++ i ) { range = ranges [ i ] ; if ( strict && typeof range . minValue !== typeof range . maxValue ) { continue ; } rangeColumn = ( columns [ range . column ] || [ ] ) ; for ( let j = 0 , jEnd = rangeColumn . length , cell , row ; j < jEnd ; ++ j ) { cell = rangeColumn [ j ] ; switch ( typeof cell ) { default : continue ; case 'boolean' : case 'number' : case 'string' : break ; } if ( strict && typeof cell !== typeof range . minValue ) { continue ; } if ( cell >= range . minValue && cell <= range . maxValue ) { row = table . getRow ( j ) ; if ( row ) { rows . push ( row ) ; } } } } modified . deleteRows ( ) ; modified . setRows ( rows ) ; } modifier . emit ( { type : 'afterModify' , detail : eventDetail , table } ) ; return table ; } } /**
 * Additionally provided types for modifier events and options, and JSON
 * conversion.
 */ namespace RangeModifier { /**
     * Options to configure the modifier.
     */ export interface Options extends DataModifier . Options { /**
         * Value ranges to include in the result.
         */ ranges : Array < RangeOptions > ; /**
         * If set to true, it will also compare the value type.
         */ strict : boolean ; } /**
     * Options to configure a range.
     */ export interface RangeOptions extends JSON . Object { /**
         * Column containing the filtered values. This can be an index or a
         * name.
         */ column : string ; /**
         * Maximum including value (`<=` operator).
         */ maxValue : ( boolean | number | string ) ; /**
         * Minimum including value (`>=` operator).
         */ minValue : ( boolean | number | string ) ; } } DataModifier . addModifier ( RangeModifier ) ; declare module './ModifierType' { interface ModifierTypeRegistry { Range : typeof RangeModifier ; } } export default RangeModifier ;