2021-11-23 00:03:59 +03:00
|
|
|
|
export const 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
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const camelToPascal = (s: string): string =>
|
2022-06-30 16:32:56 +03:00
|
|
|
|
s[0].toUpperCase() + s.substring(1)
|
2022-04-01 22:17:10 +03:00
|
|
|
|
|
|
|
|
|
export function jsComment(s: string): string {
|
|
|
|
|
return (
|
|
|
|
|
'/**' +
|
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:00:02 +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 * ')
|
2022-08-12 17:13:24 +03:00
|
|
|
|
.replace(/{@link(.*)?}/g, '{@link $1}')
|
|
|
|
|
.replace(/<ahref/g, '<a href') +
|
2022-04-01 22:17:10 +03:00
|
|
|
|
'\n */'
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function indent(size: number, s: string): string {
|
|
|
|
|
let prefix = ''
|
|
|
|
|
while (size--) prefix += ' '
|
|
|
|
|
return prefix + s.replace(/\n/g, '\n' + prefix)
|
|
|
|
|
}
|