@@ -31,11 +31,7 @@ interface SemrushColumnDef {
3131 labels : string [ ]
3232}
3333
34- function column (
35- key : string ,
36- type : SemrushValueType ,
37- ...labels : string [ ]
38- ) : Omit < SemrushColumnDef , 'labels' > & { labels : string [ ] } {
34+ function column ( key : string , type : SemrushValueType , ...labels : string [ ] ) : SemrushColumnDef {
3935 return { key, type, labels : labels . map ( ( label ) => label . toLowerCase ( ) ) }
4036}
4137
@@ -254,18 +250,17 @@ function resolveHeader(
254250
255251 for ( const [ index , cell ] of headerCells . entries ( ) ) {
256252 const label = normalizeLabel ( cell )
257- const code = columnCodes . find (
258- ( candidate , position ) =>
259- position >= cursor &&
260- ( candidate . toLowerCase ( ) === label || COLUMN_DEFS [ candidate ] . labels . includes ( label ) )
261- )
253+ let matched : SemrushColumnDef | null = null
262254
263- if ( code ) {
264- cursor = columnCodes . indexOf ( code , cursor ) + 1
265- resolved . push ( COLUMN_DEFS [ code ] )
266- } else {
267- resolved . push ( sameLength ? defs [ index ] : null )
255+ for ( let position = cursor ; position < defs . length ; position ++ ) {
256+ const code = columnCodes [ position ]
257+ if ( code . toLowerCase ( ) === label || defs [ position ] . labels . includes ( label ) ) {
258+ matched = defs [ position ]
259+ cursor = position + 1
260+ break
261+ }
268262 }
263+ resolved . push ( matched ?? ( sameLength ? defs [ index ] : null ) )
269264 }
270265 return resolved
271266}
0 commit comments