mtcute/packages/tl-utils/src/codegen/utils.ts

31 lines
944 B
TypeScript
Raw Normal View History

export const snakeToCamel = (s: string): string => {
return s.replace(/(?<!^|_)(_[a-z0-9])/gi, ($1) => {
return $1.substring(1).toUpperCase()
})
}
export const camelToPascal = (s: string): string =>
s[0].toUpperCase() + s.substring(1)
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
s
2022-08-12 17:22:40 +03:00
.replace(/<br\/?>/g, '\n\n')
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, '<aƒhref')
.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(/<aƒhref/g, '<a href') +
'\n */'
)
}
export function indent(size: number, s: string): string {
let prefix = ''
while (size--) prefix += ' '
return prefix + s.replace(/\n/g, '\n' + prefix)
}