Files
edr-platform/apps/edr-freight-api/src/common/utils/generate-code.util.ts

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, '');
}