add parseType util file

This commit is contained in:
Bowen Tan 2021-09-07 11:15:57 +08:00
parent 4fc48f6570
commit 84748086e6
2 changed files with 16 additions and 18 deletions

View File

@ -1,4 +1,3 @@
import { Version } from '../../core/typings/version';
import { apiService } from './api-service';
export function mountUtilMethods() {
@ -16,20 +15,3 @@ export function mountUtilMethods() {
}
});
}
// parse component Type
export function parseType(v: string) {
const TYPE_REG = /^([a-zA-Z0-9_\d]+\/[a-zA-Z0-9_\d]+)\/([a-zA-Z0-9_\d]+)$/;
function isValidType(v: string): boolean {
return TYPE_REG.test(v);
}
if (!isValidType(v)) {
throw new Error(`Invalid type string: "${v}"`);
}
const [, version, name] = v.match(TYPE_REG)!;
return {
version,
name,
};
}

View File

@ -0,0 +1,16 @@
// parse component Type
export function parseType(v: string) {
const TYPE_REG = /^([a-zA-Z0-9_\d]+\/[a-zA-Z0-9_\d]+)\/([a-zA-Z0-9_\d]+)$/;
function isValidType(v: string): boolean {
return TYPE_REG.test(v);
}
if (!isValidType(v)) {
throw new Error(`Invalid type string: "${v}"`);
}
const [, version, name] = v.match(TYPE_REG)!;
return {
version,
name,
};
}