-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
276 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...gs/tailwindbuddy-performance-mode-off.mjs → ...configs/tailwindbuddy-performance-off.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { describe, expect, test } from "vitest"; | ||
import { processStrings } from "./strings"; | ||
|
||
const variant_complex = { | ||
slots: { | ||
root: ` | ||
1 | ||
${/* Some comment here */ ""} | ||
2 ${/* And some comment here */ ""} | ||
3 | ||
`, | ||
}, | ||
variants: { | ||
size: { | ||
xs: { | ||
root: ` | ||
4 | ||
${/* Some comment here */ ""} | ||
5 | ||
6 ${/* And some comment here */ ""} | ||
8 | ||
`, | ||
}, | ||
md: ` | ||
9 | ||
${/* Some comment here */ ""} | ||
10 | ||
11 ${/* And some comment here */ ""} | ||
12 | ||
`, | ||
}, | ||
test: { | ||
awesome: ` | ||
13 | ||
${/* Some comment here */ ""} | ||
14 | ||
15 ${/* And some comment here */ ""} | ||
16 | ||
`, | ||
}, | ||
}, | ||
defaultVariants: { | ||
size: "md", | ||
test: "awesome", | ||
}, | ||
compoundVariants: [ | ||
{ | ||
conditions: { | ||
size: "xs", | ||
}, | ||
class: ` | ||
17 | ||
${/* Some comment here */ ""} | ||
18 | ||
19 ${/* And some comment here */ ""} | ||
20 | ||
`, | ||
}, | ||
{ | ||
conditions: { | ||
size: "md", | ||
}, | ||
class: { | ||
root: ` | ||
21 | ||
${/* Some comment here */ ""} | ||
22 | ||
23 ${/* And some comment here */ ""} | ||
24 | ||
`, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const expected_complex = { | ||
slots: { | ||
root: "1 2 3", | ||
}, | ||
variants: { | ||
size: { | ||
xs: { | ||
root: "4 5 6 8", | ||
}, | ||
md: "9 10 11 12", | ||
}, | ||
test: { | ||
awesome: "13 14 15 16", | ||
}, | ||
}, | ||
defaultVariants: { | ||
size: "md", | ||
test: "awesome", | ||
}, | ||
compoundVariants: [ | ||
{ | ||
conditions: { | ||
size: "xs", | ||
}, | ||
class: "17 18 19 20", | ||
}, | ||
{ | ||
conditions: { | ||
size: "md", | ||
}, | ||
class: { | ||
root: "21 22 23 24", | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
describe("strings", () => { | ||
test("should clean a string", () => { | ||
// @ts-expect-error | ||
const finalObg = processStrings(variant_complex); | ||
expect(finalObg).toStrictEqual(expected_complex); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Slots } from "@/types/slots"; | ||
import { | ||
Variants, | ||
CompoundVariant, | ||
DefaultVariants, | ||
ResponsiveVariants, | ||
} from "@/types/variants"; | ||
|
||
function cleanString(str: string): string { | ||
// Remove comments | ||
const noComments = str.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, ""); | ||
|
||
// Replace multiple whitespace characters (including newlines) with a single space | ||
const noExtraSpaces = noComments.replace(/\s+/g, " "); | ||
|
||
// Trim the string to remove leading and trailing spaces | ||
return noExtraSpaces.trim(); | ||
} | ||
|
||
export function processStrings< | ||
V extends Variants<S>, | ||
CV extends CompoundVariant<V, S>, | ||
DV extends DefaultVariants<V, S>, | ||
R extends ResponsiveVariants<V>, | ||
S extends Slots | ||
>(obj: { | ||
slots: S; | ||
variants?: V; | ||
compoundVariants?: CV[]; | ||
responsiveVariants?: R; | ||
defaultVariants: DV; | ||
}): { | ||
slots: S; | ||
variants?: V; | ||
compoundVariants?: CV[]; | ||
responsiveVariants?: R; | ||
defaultVariants: DV; | ||
} { | ||
if (typeof obj === "string") { | ||
// @ts-expect-error | ||
return cleanString(obj); | ||
} else if (Array.isArray(obj)) { | ||
// @ts-expect-error | ||
return obj.map(processStrings); | ||
} else if (typeof obj === "object" && obj !== null) { | ||
const processedObj = {}; | ||
for (const key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
// @ts-expect-error | ||
processedObj[key] = processStrings(obj[key]); | ||
} | ||
} | ||
// @ts-expect-error | ||
return processedObj; | ||
} else { | ||
return obj; | ||
} | ||
} |
Oops, something went wrong.