File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change 1
1
import type { StrTemplate , TupleM2N , ToCamelCase } from '@tool-pack/types' ;
2
+ import { forEachObj } from './object' ;
2
3
3
4
/**
4
5
* 数字千位分隔
@@ -488,16 +489,17 @@ export function hideString(
488
489
export function getClassNames (
489
490
...classes : Array < string | Record < string , boolean | null | undefined | number > >
490
491
) : string {
491
- const handleObjClasses = ( obj : Record < string , boolean | null | undefined | number > ) : string [ ] => {
492
- return Object . entries ( obj ) . reduce < string [ ] > ( ( res , [ k , v ] ) => {
493
- if ( v ) res . push ( k ) ;
494
- return res ;
495
- } , [ ] ) ;
492
+ const classNames : Record < string , boolean > = { } ;
493
+
494
+ const handleObjClasses = ( obj : Record < string , boolean | null | undefined | number > ) : void => {
495
+ forEachObj ( obj , ( v , k ) : void => {
496
+ if ( v ) classNames [ k ] = true ;
497
+ } ) ;
496
498
} ;
497
499
498
- const list : Array < string | string [ ] > = classes . map ( ( item ) =>
499
- typeof item === 'object ' ? handleObjClasses ( item as any ) : item ,
500
+ classes . forEach ( ( item ) =>
501
+ typeof item === 'string ' ? ( classNames [ item ] = true ) : handleObjClasses ( item ) ,
500
502
) ;
501
503
502
- return [ ... new Set ( list . flat ( ) ) ] . join ( ' ' ) . trim ( ) . replace ( / \s + / g, ' ' ) ;
504
+ return Object . keys ( classNames ) . join ( ' ' ) . trim ( ) . replace ( / \s + / g, ' ' ) ;
503
505
}
You can’t perform that action at this time.
0 commit comments