-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
32 lines (25 loc) · 1 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class TailwindConstant {
// Using `any` here will make sure the type is inherited
// from the actual argument that is passed, since the argument
// might either be a string or a number.
// biome-ignore lint/suspicious/noExplicitAny: As the comment above explains, this is intentional.
value: any;
// Allows for passing a custom suffix that will be compared
// with the Tailwind utility that is passed via `util()`.
suffix?: string;
constructor(value: number | string, suffix?: string) {
this.value = value;
this.suffix = suffix;
}
util(names, conditions?) {
const utils = names.split(' ');
const match = this.suffix || `-${this.value}`;
const validName = utils.find((util) => util.endsWith(match));
const conditionsMet = typeof conditions === 'undefined' ? true : conditions;
if (!validName) {
throw new Error(`Tailwind utilities "${names}" don't include "${match}" match.`);
}
return conditionsMet ? names : null;
}
}
export default TailwindConstant;