@amritk/helpers 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -68,11 +68,21 @@ const isObjectLikeSchema = (schema) => {
68
68
  const getBooleanSubSchemaType = (schema) => {
69
69
  return schema ? 'unknown' : 'never';
70
70
  };
71
+ /**
72
+ * Renders a possibly multi-line description as JSDoc body lines, prefixing each
73
+ * line with `${indent}* `. Blank lines become a bare `${indent}*` so we never
74
+ * emit trailing whitespace. Without this, embedded newlines would leave
75
+ * continuation lines unprefixed and break the comment block.
76
+ */
77
+ const renderJsDocBody = (description, indent) => description
78
+ .split('\n')
79
+ .map((line) => (line.length > 0 ? `${indent}* ${line}\n` : `${indent}*\n`))
80
+ .join('');
71
81
  const buildJsDocBlock = (title, description, commentUrl) => {
72
82
  let block = `/**\n`;
73
83
  block += `* ${title}\n`;
74
84
  block += `*\n`;
75
- block += `* ${description}\n`;
85
+ block += renderJsDocBody(description, '');
76
86
  if (commentUrl?.startsWith('http')) {
77
87
  block += `* \n`;
78
88
  block += `* @see {@link ${commentUrl}}\n`;
@@ -80,6 +90,19 @@ const buildJsDocBlock = (title, description, commentUrl) => {
80
90
  block += `*/\n`;
81
91
  return block;
82
92
  };
93
+ /**
94
+ * Builds the inline JSDoc comment that precedes a generated property. A
95
+ * single-line description stays compact (` /** text *\/`); a multi-line
96
+ * description expands into an asterisk-prefixed block so every line is
97
+ * commented. The returned string always ends with a newline, ready for the
98
+ * property declaration to follow.
99
+ */
100
+ const buildInlinePropertyComment = (description) => {
101
+ if (!description.includes('\n')) {
102
+ return ` /** ${description} */\n`;
103
+ }
104
+ return ` /**\n${renderJsDocBody(description, ' ')} */\n`;
105
+ };
83
106
  /**
84
107
  * Converts a JSON Schema type to its TypeScript equivalent, applying any
85
108
  * `x-mjst` brand. Branding is type-level only, so we compute the underlying
@@ -299,9 +322,8 @@ const getUnbrandedType = (schema, options = {}) => {
299
322
  first = false;
300
323
  if (inlineDescription) {
301
324
  properties +=
302
- ' /** ' +
303
- inlineDescription +
304
- ' */\n ' +
325
+ buildInlinePropertyComment(inlineDescription) +
326
+ ' ' +
305
327
  readonlyPrefix +
306
328
  safeKey(key) +
307
329
  optional +
@@ -444,7 +466,8 @@ export const generateTypeDefinition = (schema, typeName, options = {}) => {
444
466
  ? propSchema.$comment
445
467
  : undefined;
446
468
  if (inlineDescription) {
447
- properties += ' /** ' + inlineDescription + ' */\n ' + quotedKey + optional + ': ' + propType + ';';
469
+ properties +=
470
+ buildInlinePropertyComment(inlineDescription) + ' ' + quotedKey + optional + ': ' + propType + ';';
448
471
  }
449
472
  else {
450
473
  properties += ' ' + quotedKey + optional + ': ' + propType + ';';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amritk/helpers",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Shared utilities for the mjst code generation ecosystem.",
5
5
  "type": "module",
6
6
  "license": "MIT",