-
Notifications
You must be signed in to change notification settings - Fork 45
/
parser-util.ts
31 lines (28 loc) · 948 Bytes
/
parser-util.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
/* eslint-disable valid-jsdoc */
/**
* @deprecated Since version 1.25.0 due to major generator refactoring.
*/
export function stripNamespace(name: string): string {
const nameParts = name.split('.');
return nameParts[nameParts.length - 1];
}
const collectionRegExp = /Collection\((?<collectionType>.*)\)/;
/**
* @deprecated Since version 1.25.0 due to major generator refactoring.
*/
export function isCollection(typeName: string): boolean {
return collectionRegExp.test(typeName);
}
/**
* @deprecated Since version 1.25.0 due to major generator refactoring.
*/
export function parseTypeName(typeName: string): string {
return isCollection(typeName) ? parseCollectionTypeName(typeName) : typeName;
}
function parseCollectionTypeName(typeName: string): string {
const name = typeName.match(collectionRegExp)?.groups?.collectionType;
if (!name) {
throw new Error(`Cannot parse type name ${typeName}.`);
}
return name;
}