fix(striker-ui-api): add function to disassemble entity id

main
Tsu-ba-me 2 years ago
parent 9e9b84604f
commit 7575bf8aed
  1. 20
      striker-ui-api/src/lib/disassembleEntityId.ts

@ -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…
Cancel
Save