mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
16 lines
419 B
TypeScript
16 lines
419 B
TypeScript
/**
|
|
* Derives a stable, uppercase, underscore-separated code from a human-readable name.
|
|
*
|
|
* Examples:
|
|
* "Hazard Surcharge" → "HAZARD_SURCHARGE"
|
|
* "20ft Dry Container" → "20FT_DRY_CONTAINER"
|
|
* "Kality Yard (ET)" → "KALITY_YARD_ET"
|
|
*/
|
|
export function generateCode(name: string): string {
|
|
return name
|
|
.trim()
|
|
.toUpperCase()
|
|
.replace(/[^A-Z0-9]+/g, '_')
|
|
.replace(/^_+|_+$/g, '');
|
|
}
|