| |
| |
| |
| const pascalCaseExceptions = ['OAuth2', 'URL', 'API', 'UI', 'ID'] |
|
|
| |
| |
| |
| |
| |
| export function isPascalCaseNoAcronyms(value) { |
| if (value === undefined || value === null || value === '') { |
| return true |
| } |
|
|
| return new RegExp( |
| `^(?:[A-Z][a-z0-9]+|${pascalCaseExceptions.join('|')})+[A-Z]?$|^[A-Z]+$`, |
| ).test(value) |
| } |
|
|
| |
| |
| |
| |
| |
| export function isCamelCaseNoAcronyms(value) { |
| if (value === undefined || value === null || value === '') { |
| return true |
| } |
|
|
| return /^[^a-zA-Z0-9]?[a-z][a-z0-9]*([A-Z][a-z0-9]+)*[A-Z]?$/.test(value) |
| } |
|
|
| |
| |
| |
| |
| |
| export function isSnakeCase(value) { |
| if (value === undefined || value === null || value === '') { |
| return true |
| } |
|
|
| return /^([a-z0-9]+_)*[a-z0-9]+$/.test(value) |
| } |
|
|
| |
| |
| |
| |
| |
| export function isKebabCase(value) { |
| if (value === undefined || value === null || value === '') { |
| return true |
| } |
|
|
| return /^([a-z0-9]+(-[a-z0-9]+)*)$/.test(value) |
| } |
|
|
| |
| |
| |
| |
| |
| export function detectNewline(source) { |
| return source.includes('\r\n') ? '\r\n' : '\n' |
| } |
|
|
| |
| |
| |
| |
| |
| export function getIndentBefore(source, position) { |
| const lineStart = source.lastIndexOf('\n', position - 1) + 1 |
| const between = source.slice(lineStart, position) |
| const match = between.match(/^[ \t]*/) |
| return match ? match[0] : '' |
| } |
|
|
| |
| |
| |
| |
| |
| export function extractMarkdownFromDocComment(raw) { |
| let body = raw |
| if (body.startsWith('/**')) body = body.slice(3) |
| if (body.endsWith('*/')) body = body.slice(0, -2) |
|
|
| const lines = body.split(/\r?\n/).map((line) => { |
| |
| return line.replace(/^[ \t]*\*[ \t]?/, '').replace(/[ \t]+$/, '') |
| }) |
|
|
| let start = 0 |
| let end = lines.length |
| while (start < end && lines[start].trim() === '') start++ |
| while (end > start && lines[end - 1].trim() === '') end-- |
| return lines.slice(start, end).join('\n') |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function wrapMarkdownAsDocComment(markdown, indent, newline) { |
| const trimmed = markdown.replace(/\n+$/, '') |
| if (trimmed === '') { |
| return `/**${newline}${indent} */` |
| } |
| const lines = trimmed.split('\n') |
| const out = [ |
| '/**', |
| ...lines.map((line) => |
| line.length === 0 ? `${indent} *` : `${indent} * ${line}`, |
| ), |
| `${indent} */`, |
| ] |
| return out.join(newline) |
| } |
|
|