@@ -51,6 +51,7 @@ interface FlattenUnipikaOptions {
5151 matchedState ?: { } ;
5252 settings ?: UnipikaSettings ;
5353 filter ?: string ;
54+ caseSensitive ?: boolean ;
5455}
5556
5657export interface FlattenUnipikaResult {
@@ -75,6 +76,7 @@ export function flattenUnipika(
7576 flattenUnipikaImpl ( value , 0 , ctx ) ;
7677 const searchIndex = makeSearchIndex ( ctx . dst , options ?. filter , {
7778 settings : options ?. settings ,
79+ caseSensitive : options ?. caseSensitive ,
7880 } ) ;
7981 return { data : ctx . dst , searchIndex} ;
8082}
@@ -438,6 +440,7 @@ function fromUnipikaPrimitive(value: UnipikaPrimitive, level: number): UnipikaFl
438440
439441interface SearchParams {
440442 settings ?: UnipikaSettings ;
443+ caseSensitive ?: boolean ;
441444}
442445
443446export interface SearchInfo {
@@ -463,8 +466,8 @@ export function makeSearchIndex(
463466 const res : SearchIndex = { } ;
464467 for ( let i = 0 ; i < tree . length ; ++ i ) {
465468 const { key, value} = tree [ i ] ;
466- const keyMatch = rowSearchInfo ( key , filter , settings ) ;
467- const valueMatch = rowSearchInfo ( value , filter , settings ) ;
469+ const keyMatch = rowSearchInfo ( key , filter , settings , options ?. caseSensitive ) ;
470+ const valueMatch = rowSearchInfo ( value , filter , settings , options ?. caseSensitive ) ;
468471 if ( keyMatch || valueMatch ) {
469472 res [ i ] = Object . assign ( { } , keyMatch && { keyMatch} , valueMatch && { valueMatch} ) ;
470473 }
@@ -478,6 +481,7 @@ function rowSearchInfo(
478481 v : SearchValue ,
479482 filter : string ,
480483 settings : UnipikaSettings ,
484+ caseSensitive ?: boolean ,
481485) : Array < number > | undefined {
482486 if ( ! v ) {
483487 return undefined ;
@@ -492,12 +496,17 @@ function rowSearchInfo(
492496 tmp = tmp . substring ( 1 , tmp . length - 1 ) ; // skip quotes
493497 }
494498 let from = 0 ;
499+ let normolizedFilter = filter ;
500+ if ( ! caseSensitive ) {
501+ tmp = tmp . toLowerCase ( ) ;
502+ normolizedFilter = filter . toLowerCase ( ) ;
503+ }
495504 while ( from >= 0 && from < tmp . length ) {
496- const index = tmp . indexOf ( filter , from ) ;
505+ const index = tmp . indexOf ( normolizedFilter , from ) ;
497506 if ( - 1 === index ) {
498507 break ;
499508 }
500- from = index + filter . length ;
509+ from = index + normolizedFilter . length ;
501510 res . push ( index ) ;
502511 }
503512 return res . length ? res : undefined ;
0 commit comments