2022-08-29 14:33:11 +03:00
|
|
|
|
/**
|
|
|
|
|
* Transform snake_case string to camelCase string
|
|
|
|
|
* @param s Snake_case string
|
|
|
|
|
*/
|
2024-08-13 04:53:07 +03:00
|
|
|
|
export function snakeToCamel(s: string): string {
|
|
|
|
|
return s.replace(/(?<!^|_)_[a-z0-9]/gi, ($1) => {
|
2022-06-30 16:32:56 +03:00
|
|
|
|
return $1.substring(1).toUpperCase()
|
2021-11-23 00:03:59 +03:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-29 14:33:11 +03:00
|
|
|
|
/**
|
|
|
|
|
* Transform camelCase string to PascalCase string
|
|
|
|
|
* @param s camelCase string
|
|
|
|
|
*/
|
2023-09-24 01:32:22 +03:00
|
|
|
|
export const camelToPascal = (s: string): string => s[0].toUpperCase() + s.substring(1)
|
2022-04-01 22:17:10 +03:00
|
|
|
|
|
2022-08-29 14:33:11 +03:00
|
|
|
|
/**
|
|
|
|
|
* Format a string as a JS documentation comment
|
|
|
|
|
* @param s Comment to format
|
|
|
|
|
*/
|
2022-04-01 22:17:10 +03:00
|
|
|
|
export function jsComment(s: string): string {
|
|
|
|
|
return (
|
2024-08-13 04:53:07 +03:00
|
|
|
|
`/**${
|
2022-08-12 17:13:24 +03:00
|
|
|
|
// awesome hack not to break up {@link} links and <a href
|
2022-04-01 22:17:10 +03:00
|
|
|
|
s
|
2022-08-12 17:22:40 +03:00
|
|
|
|
.replace(/<br\/?>/g, '\n\n')
|
2024-08-13 04:53:07 +03:00
|
|
|
|
.replace(/\{@link (.*?)\}/g, '{@link$1}')
|
2022-08-12 17:13:24 +03:00
|
|
|
|
.replace(/<a href/g, '<ahref')
|
2022-04-01 22:17:10 +03:00
|
|
|
|
.replace(/(?![^\n]{1,60}$)([^\n]{1,60})\s/g, '$1\n')
|
2022-08-12 17:00:02 +03:00
|
|
|
|
.replace(/\n|^/g, '\n * ')
|
2024-08-13 04:53:07 +03:00
|
|
|
|
.replace(/\{@link(.*)\}/g, '{@link $1}')
|
|
|
|
|
.replace(/<ahref/g, '<a href')
|
|
|
|
|
}\n */`
|
2022-04-01 22:17:10 +03:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-29 14:33:11 +03:00
|
|
|
|
/**
|
|
|
|
|
* Indent the string with the given amount of spaces
|
|
|
|
|
*
|
|
|
|
|
* @param size Number of spaces to indent with
|
|
|
|
|
* @param s String to indent
|
|
|
|
|
*/
|
2022-04-01 22:17:10 +03:00
|
|
|
|
export function indent(size: number, s: string): string {
|
|
|
|
|
let prefix = ''
|
|
|
|
|
while (size--) prefix += ' '
|
2023-06-05 03:30:48 +03:00
|
|
|
|
|
2024-08-13 04:53:07 +03:00
|
|
|
|
return prefix + s.replace(/\n/g, `\n${prefix}`)
|
2022-04-01 22:17:10 +03:00
|
|
|
|
}
|