mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
clean up typescript initialization
This commit is contained in:
@@ -13,6 +13,22 @@ export function hasError(data: Record<string, unknown>): data is ErrorBase {
|
||||
return 'error' in data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a slug from any input string.
|
||||
*
|
||||
* @param slug Original string.
|
||||
* @param chars Maximum number of characters.
|
||||
* @returns Slugified string.
|
||||
*/
|
||||
export function slugify(slug: string, chars: number): string {
|
||||
return slug
|
||||
.replace(/[^\-\.\w\s]/g, '') // Remove unneeded chars
|
||||
.replace(/^[\s\.]+|[\s\.]+$/g, '') // Trim leading/trailing spaces
|
||||
.replace(/[\-\.\s]+/g, '-') // Convert spaces and decimals to hyphens
|
||||
.toLowerCase() // Convert to lowercase
|
||||
.substring(0, chars); // Trim to first chars chars
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to determine if a value is not null, undefined, or empty.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user