Skip to content

Commit 97774b2

Browse files
committed
refactor: add isValidTemplate function
1 parent cd2fe31 commit 97774b2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/create/src/utils/constants.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,16 @@ export function getTemplatesList(projectType: ProjectType) {
9999
return VANILLA_TEMPLATES as VanillaTemplate[];
100100
}
101101

102-
//
102+
/**
103+
* Tests is the template given is a valid template, and returns it as a template if it is
104+
* @param type expected type of the template
105+
* @param maybe_template the template string to test
106+
* @returns the template string if it is valid, undefined if not
107+
*/
108+
export function isValidTemplate(type: "vanilla", maybe_template: string): VanillaTemplate;
109+
export function isValidTemplate(type: "start", maybe_template: string): StartTemplate;
110+
export function isValidTemplate(type: "library", maybe_template: string): LibraryTemplate;
111+
export function isValidTemplate(type: ProjectType, maybe_template: string) {
112+
const templates = getTemplatesList(type);
113+
return templates.find(t => t === maybe_template)
114+
}

0 commit comments

Comments
 (0)