@heliosgraphics/utils 6.0.0-alpha.12 → 6.0.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/classnames.ts +35 -12
- package/package.json +1 -1
package/classnames.ts
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
export const getClasses = (...args: Array<unknown>): string => {
|
|
2
|
-
|
|
2
|
+
if (args.length === 1) {
|
|
3
|
+
const arg: unknown = args[0]
|
|
4
|
+
if (typeof arg === "string" && arg.length > 0) {
|
|
5
|
+
return arg
|
|
6
|
+
}
|
|
7
|
+
}
|
|
3
8
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const isValidString: boolean = itemType === "string" && (item as string).length > 0
|
|
7
|
-
const isValidObject: boolean = itemType === "object" && item !== null
|
|
9
|
+
let result: string = ""
|
|
10
|
+
let seen: Record<string, boolean> | null = null
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
for (let i: number = 0; i < args.length; i++) {
|
|
13
|
+
const item: unknown = args[i]
|
|
14
|
+
const itemType: string = typeof item
|
|
12
15
|
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
if (itemType === "string") {
|
|
17
|
+
const str: string = item as string
|
|
18
|
+
if (str.length > 0) {
|
|
19
|
+
if (seen === null) {
|
|
20
|
+
seen = { [str]: true }
|
|
21
|
+
result = str
|
|
22
|
+
} else if (!seen[str]) {
|
|
23
|
+
seen[str] = true
|
|
24
|
+
result = result.length > 0 ? result + " " + str : str
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
} else if (itemType === "object" && item !== null) {
|
|
28
|
+
const obj: Record<string, unknown> = item as Record<string, unknown>
|
|
29
|
+
for (const key in obj) {
|
|
30
|
+
if (obj[key]) {
|
|
31
|
+
if (seen === null) {
|
|
32
|
+
seen = { [key]: true }
|
|
33
|
+
result = key
|
|
34
|
+
} else if (!seen[key]) {
|
|
35
|
+
seen[key] = true
|
|
36
|
+
result = result.length > 0 ? result + " " + key : key
|
|
37
|
+
}
|
|
38
|
+
}
|
|
16
39
|
}
|
|
17
40
|
}
|
|
18
41
|
}
|
|
19
42
|
|
|
20
|
-
return
|
|
43
|
+
return result
|
|
21
44
|
}
|