28 lines
731 B
TypeScript
28 lines
731 B
TypeScript
|
|
export const typeDimMap = new Map<string, { type: string; dim: number }>()
|
||
|
|
export class PortModel {
|
||
|
|
name: string
|
||
|
|
type?: string
|
||
|
|
constructor(name:string, type?:string){
|
||
|
|
this.name = name
|
||
|
|
this.type = type
|
||
|
|
}
|
||
|
|
|
||
|
|
getTypeInfo(): {type: string; dim: number } {
|
||
|
|
const type = this.type
|
||
|
|
if (!type) return {type: '', dim: 0 }
|
||
|
|
const str = String(type).trim()
|
||
|
|
if (typeDimMap.has(str)) return typeDimMap.get(str)!
|
||
|
|
let dim = 0
|
||
|
|
let base = str
|
||
|
|
let match: RegExpMatchArray | null
|
||
|
|
const regex = /^(List|Array)\s*<(.+)>$/
|
||
|
|
while ((match = base.match(regex))) {
|
||
|
|
dim++
|
||
|
|
base = match[2].trim()
|
||
|
|
}
|
||
|
|
const result = {type: base, dim }
|
||
|
|
typeDimMap.set(str, result)
|
||
|
|
return result
|
||
|
|
}
|
||
|
|
}
|