parent
9e9b84604f
commit
7575bf8aed
1 changed files with 20 additions and 0 deletions
@ -0,0 +1,20 @@ |
|||||||
|
export const getEntityName = (id: string) => id.replace(/\d*$/, ''); |
||||||
|
|
||||||
|
export const getEntityNumber = (id: string) => |
||||||
|
Number.parseInt(id.replace(/^[^\d]*/, '')); |
||||||
|
|
||||||
|
export const getEntityParts = (id: string) => { |
||||||
|
let name = ''; |
||||||
|
let number = NaN; |
||||||
|
|
||||||
|
const matchResult = id.match(/^([^\d]*)(\d*)$/); |
||||||
|
|
||||||
|
if (matchResult) { |
||||||
|
const parts = matchResult; |
||||||
|
|
||||||
|
name = parts[1]; |
||||||
|
number = Number.parseInt(parts[2]); |
||||||
|
} |
||||||
|
|
||||||
|
return { name, number }; |
||||||
|
}; |
Loading…
Reference in new issue