1
1
import { ClassGroupId , Config , ClassGroup , ClassValidator } from './types'
2
2
3
- interface ClassPartObject {
3
+ export interface ClassPartObject {
4
4
nextPart : Record < string , ClassPartObject >
5
5
validators : ClassValidatorObject [ ]
6
6
classGroupId ?: ClassGroupId
@@ -14,12 +14,7 @@ interface ClassValidatorObject {
14
14
const CLASS_PART_SEPARATOR = '-'
15
15
16
16
export function createClassUtils ( config : Config ) {
17
- const classMap : ClassPartObject = {
18
- nextPart : { } ,
19
- validators : [ ] ,
20
- }
21
-
22
- processClassGroups ( config , classMap )
17
+ const classMap = createClassMap ( config )
23
18
24
19
function getClassGroupId ( className : string ) {
25
20
const classParts = className . split ( CLASS_PART_SEPARATOR )
@@ -69,10 +64,20 @@ function getGroupRecursive(
69
64
return classPartObject . validators . find ( ( { validator } ) => validator ( classRest ) ) ?. classGroupId
70
65
}
71
66
72
- function processClassGroups ( config : Config , classMap : ClassPartObject ) {
67
+ /**
68
+ * Exported for testing only
69
+ */
70
+ export function createClassMap ( config : Config ) {
71
+ const classMap : ClassPartObject = {
72
+ nextPart : { } ,
73
+ validators : [ ] ,
74
+ }
75
+
73
76
Object . entries ( config . classGroups ) . forEach ( ( [ classGroupId , classGroup ] ) => {
74
77
processClassesRecursively ( classGroup , classMap , classGroupId )
75
78
} )
79
+
80
+ return classMap
76
81
}
77
82
78
83
function processClassesRecursively (
0 commit comments