Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 43 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { dehash, joinWithLead } from "./core"; |
||
2 | import { ClassValue } from "./defs"; |
||
3 | import {stringifyClassNamed} from "./utils" |
||
4 | |||
5 | describe(direct.name, () => { |
||
6 | const output = direct({class1: undefined, class2: "hash2"}) |
||
7 | , className = "class1 hash2" |
||
8 | |||
9 | it("has classNames", () => expect( |
||
10 | {...output} |
||
11 | ).toStrictEqual( |
||
12 | {className} |
||
13 | )) |
||
14 | it("stringable", () => expect( |
||
15 | `${output}` |
||
16 | ).toBe( |
||
17 | className |
||
18 | )) |
||
19 | it("called", () => expect({ |
||
20 | ...output({ |
||
21 | class3: undefined, class4: "hash4" |
||
22 | }) |
||
23 | }).toStrictEqual({ |
||
24 | "className": `${className} class3 hash4` |
||
25 | })) |
||
26 | it("called is strigable", () => expect( |
||
27 | `${output({ |
||
28 | class3: undefined, class4: "hash4" |
||
29 | })}` |
||
30 | ).toBe( |
||
31 | `${className} class3 hash4` |
||
32 | )) |
||
33 | }) |
||
34 | |||
35 | function direct<T extends Record<string, ClassValue>>(classes: T, propagate?: string) { |
||
36 | const className = joinWithLead(propagate, dehash(classes)) |
||
37 | , host = (classes: Record<string, ClassValue>) => direct(classes, className) |
||
38 | |||
39 | host["className"] = className |
||
40 | stringifyClassNamed(host) |
||
41 | |||
42 | return host |
||
43 | } |