1
|
|
|
import { EMPTY_OBJECT } from "./consts" |
2
|
|
|
import type { ClassNames, ReactRelated, ClassNamesMap } from "./defs" |
3
|
|
|
|
4
|
|
|
type GetClassNames<Source extends string | ReactRelated = string> = "classnames" extends keyof ClassNames<Source> |
5
|
|
|
? ClassNames<Source>["classnames"] |
6
|
|
|
: never |
7
|
|
|
|
8
|
|
|
export default classNamesCheck |
9
|
|
|
|
10
|
|
|
/** Declares class keys |
11
|
|
|
* @example classNamesCheck() // Anything |
12
|
|
|
* @example classNamesCheck<"class1">() // `.class1` |
13
|
|
|
* @example classNamesCheck<typeof Component>() // classKeys of `Component` |
14
|
|
|
*/ |
15
|
|
|
function classNamesCheck< |
16
|
|
|
Source extends string | ReactRelated = string |
17
|
|
|
>(): GetClassNames<Source> |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Propagates argument's shape. |
21
|
|
|
* For checking equality add `typeof css_module` as second generic parameter |
22
|
|
|
*/ |
23
|
|
|
function classNamesCheck<T extends ClassNamesMap<string>>(classnames: T): T |
24
|
|
|
|
25
|
|
|
//TODO On assignment |
26
|
|
|
/** Checks equality |
27
|
|
|
* @example classNamesCheck<typeof App, typeof require("./module.css")>(module?) // Will return notation as array of not used classes |
28
|
|
|
* @todo On parameter: |
29
|
|
|
* @example classNamesCheck<typeof App>(require("./module.css")) |
30
|
|
|
*/ |
31
|
|
|
function classNamesCheck< |
32
|
|
|
K extends string | ReactRelated, |
33
|
|
|
T extends GetClassNames<K> = GetClassNames<K> |
34
|
|
|
>(classnames?: T): string extends keyof T ? GetClassNames<K> |
35
|
|
|
: keyof T extends keyof GetClassNames<K> ? T |
36
|
|
|
// For Verbosing redundant keys |
37
|
|
|
: Exclude<keyof T, keyof GetClassNames<K>>[] |
38
|
|
|
|
39
|
|
|
function classNamesCheck(classnames = EMPTY_OBJECT) { |
40
|
|
|
return classnames |
41
|
|
|
} |
42
|
|
|
|