ts-markdown-builder 0.5.0 → 0.7.0

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.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  # TS Markdown Builder
8
8
 
9
- Elegant markdown builder with minimal bundle size.
9
+ Elegant Markdown builder for TypeScript: zero dependencies, tree-shakable, under 1 kB.
10
10
 
11
11
  ## Goal
12
12
 
@@ -59,33 +59,36 @@ It supports:
59
59
 
60
60
  ### Utils
61
61
 
62
- - `joinBlocks(blocks: string[])` - join blocks of text into a single markdown document (string)
62
+ - [`joinBlocks(blocks: string[])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#joinblocks) - join blocks of text into a single markdown document (string)
63
63
 
64
64
  ### Block
65
- - `heading(text: string, options?: { level: number = 1 })`
66
- - `blockquote(text: string | string[])`
67
- - `codeBlock(text: string, options?: { language?: string = '' })`
68
- - `list(items: string[])`
69
- - `orderedList(items: string[])`
70
- - `horizontalRule`
65
+ - [`heading(text: string, options?: { level: number = 1 })`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#heading)
66
+ - [`blockquote(text: string | string[])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#blockquote)
67
+ - [`alert(type: AlertType, content: string | string[])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#alert) - alert (callout); type is `'note' | 'tip' | 'important' | 'warning' | 'caution'` _(GitHub extension)_
68
+ - [`codeBlock(text: string, options?: { language?: string = '' })`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#codeblock)
69
+ - [`list(items: string[])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#list)
70
+ - [`orderedList(items: string[])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#orderedlist)
71
+ - [`taskList(items: (string | TaskListItem)[])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#tasklist) - task list with checkboxes (items can be strings or `{ text: string, done?: boolean }`) _(GFM extension)_
72
+ - [`horizontalRule`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#horizontalrule)
71
73
 
72
74
  ### Inline
73
75
 
74
- - `bold(text: string)`
75
- - `italic(text: string)`
76
- - `code(text: string)`
77
- - `link(url: string, text?: string)` - link or autolink
78
- - `image(url: string, text?: string)`
79
- - `escape(text: string)`
76
+ - [`bold(text: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#bold)
77
+ - [`italic(text: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#italic)
78
+ - [`strikethrough(text: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#strikethrough) _(GFM extension)_
79
+ - [`code(text: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#code)
80
+ - [`link(url: string, text?: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#link) - link
81
+ - [`image(url: string, text?: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#image)
82
+ - [`escape(text: string)`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#escape)
80
83
 
81
84
  ### Table
82
85
 
83
- - `table(headers: string[], rows: string[][])`
86
+ - [`table(headers: string[], rows: string[][])`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#table) _(GFM extension)_
84
87
 
85
88
  ### HTML
86
89
 
87
- - `disclosure(title: string, content: string, options?: { open?: boolean })`
88
- - `lineBreak`
90
+ - [`disclosure(title: string, content: string, options?: { open?: boolean })`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#disclosure)
91
+ - [`lineBreak`](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md#linebreak)
89
92
 
90
93
  ## Contributing
91
94
 
@@ -97,4 +100,4 @@ MIT
97
100
 
98
101
  ## Reference
99
102
 
100
- TODO
103
+ See the full [API Reference](https://github.com/mdjastrzebski/ts-markdown-builder/blob/main/API.md) for detailed documentation, parameter descriptions, and usage examples.
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
 
3
+ exports.alert = alert;
3
4
  exports.blockquote = blockquote;
4
5
  exports.codeBlock = codeBlock;
5
6
  exports.heading = heading;
6
7
  exports.horizontalRule = void 0;
7
8
  exports.list = list;
8
9
  exports.orderedList = orderedList;
10
+ exports.taskList = taskList;
9
11
  var _utils = require("./utils.js");
10
12
  const horizontalRule = exports.horizontalRule = '---';
11
13
  function heading(text, options) {
@@ -15,6 +17,9 @@ function heading(text, options) {
15
17
  function blockquote(content) {
16
18
  return (0, _utils.prefixLines)((0, _utils.joinBlocks)(content), '> ');
17
19
  }
20
+ function alert(type, content) {
21
+ return blockquote(`[!${type.toUpperCase()}]\n${(0, _utils.joinBlocks)(content)}`);
22
+ }
18
23
  function codeBlock(content, options) {
19
24
  const language = options?.language ?? '';
20
25
  const backticks = Math.max((0, _utils.maxBackticks)(content), 2) + 1;
@@ -26,4 +31,13 @@ function list(items) {
26
31
  function orderedList(items) {
27
32
  return items.map((item, index) => `${index + 1}. ${item}`).join('\n');
28
33
  }
34
+ function taskList(items) {
35
+ const result = [];
36
+ for (const item of items) {
37
+ const text = typeof item === 'string' ? item : item.text;
38
+ const done = typeof item === 'string' ? false : item.done;
39
+ result.push(`- [${done ? 'x' : ' '}] ${text}`);
40
+ }
41
+ return result.join('\n');
42
+ }
29
43
  //# sourceMappingURL=block.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"block.js","names":["horizontalRule","exports","heading","text","options","level","repeat","blockquote","content","prefixLines","joinBlocks","codeBlock","language","backticks","Math","max","maxBackticks","list","items","map","item","join","orderedList","index"],"sources":["../../src/block.ts"],"sourcesContent":["import { joinBlocks, maxBackticks, prefixLines } from './utils';\n\n/**\n * Create a horizontal rule block.\n *\n * Markdown: `---`\n */\nexport const horizontalRule = '---';\n\ntype HeadingOptions = {\n level: number;\n};\n\n/**\n * Create a heading block.\n * Markdown: `# Heading`\n *\n * @param text - The text of the heading.\n * @param level - The level of the heading (defaults to 1).\n */\nexport function heading(text: string, options?: HeadingOptions): string {\n const level = options?.level ?? 1;\n return `${'#'.repeat(level)} ${text}`;\n}\n\n/**\n * Create a blockquote block.\n *\n * Markdown:\n * ```\n * > Content\n * > Content\n * ```\n *\n * @param text - The content of the blockquote.\n */\nexport function blockquote(content: string | readonly string[]): string {\n return prefixLines(joinBlocks(content), '> ');\n}\n\ntype CodeBlockOptions = {\n language?: string;\n};\n\n/**\n * Create a code block.\n *\n * Markdown:\n * ```js\n * Content\n * ```\n *\n * @param content - The content of the code block.\n * @param language - The language of the code block.\n */\nexport function codeBlock(content: string, options?: CodeBlockOptions): string {\n const language = options?.language ?? '';\n const backticks = Math.max(maxBackticks(content), 2) + 1;\n return '`'.repeat(backticks) + language + '\\n' + content + '\\n' + '`'.repeat(backticks);\n}\n\n/**\n * Create an unordered list block.\n *\n * Markdown:\n * ```\n * - Item\n * - Item\n * ```\n *\n * @param items - The items of the list.\n */\nexport function list(items: readonly string[]): string {\n return items.map((item) => `- ${item}`).join('\\n');\n}\n\n/**\n * Create an ordered list block.\n *\n * Markdown:\n * ```\n * 1. Item\n * 2. Item\n * ```\n *\n * @param items - The items of the list.\n */\nexport function orderedList(items: readonly string[]): string {\n return items.map((item, index) => `${index + 1}. ${item}`).join('\\n');\n}\n"],"mappings":";;;;;;;;;AAOO,MAAMA,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,KAAK;AAa5B,SAASE,OAAOA,CAACC,IAAY,EAAEC,OAAwB,EAAU;EACtE,MAAMC,KAAK,GAAGD,OAAO,EAAEC,KAAK,IAAI,CAAC;EACjC,OAAO,GAAG,GAAG,CAACC,MAAM,CAACD,KAAK,CAAC,IAAIF,IAAI,EAAE;AACvC;AAaO,SAASI,UAAUA,CAACC,OAAmC,EAAU;EACtE,OAAO,IAAAC,kBAAW,EAAC,IAAAC,iBAAU,EAACF,OAAO,CAAC,EAAE,IAAI,CAAC;AAC/C;AAiBO,SAASG,SAASA,CAACH,OAAe,EAAEJ,OAA0B,EAAU;EAC7E,MAAMQ,QAAQ,GAAGR,OAAO,EAAEQ,QAAQ,IAAI,EAAE;EACxC,MAAMC,SAAS,GAAGC,IAAI,CAACC,GAAG,CAAC,IAAAC,mBAAY,EAACR,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC;EACxD,OAAO,GAAG,CAACF,MAAM,CAACO,SAAS,CAAC,GAAGD,QAAQ,GAAG,IAAI,GAAGJ,OAAO,GAAG,IAAI,GAAG,GAAG,CAACF,MAAM,CAACO,SAAS,CAAC;AACzF;AAaO,SAASI,IAAIA,CAACC,KAAwB,EAAU;EACrD,OAAOA,KAAK,CAACC,GAAG,CAAEC,IAAI,IAAK,KAAKA,IAAI,EAAE,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACpD;AAaO,SAASC,WAAWA,CAACJ,KAAwB,EAAU;EAC5D,OAAOA,KAAK,CAACC,GAAG,CAAC,CAACC,IAAI,EAAEG,KAAK,KAAK,GAAGA,KAAK,GAAG,CAAC,KAAKH,IAAI,EAAE,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACvE","ignoreList":[]}
1
+ {"version":3,"file":"block.js","names":["horizontalRule","exports","heading","text","options","level","repeat","blockquote","content","prefixLines","joinBlocks","alert","type","toUpperCase","codeBlock","language","backticks","Math","max","maxBackticks","list","items","map","item","join","orderedList","index","taskList","result","done","push"],"sources":["../../src/block.ts"],"sourcesContent":["import { joinBlocks, maxBackticks, prefixLines } from './utils';\n\n/**\n * Create a horizontal rule block.\n *\n * Markdown: `---`\n */\nexport const horizontalRule = '---';\n\ntype HeadingOptions = {\n level: number;\n};\n\n/**\n * Create a heading block.\n * Markdown: `# Heading`\n *\n * @param text - The text of the heading.\n * @param level - The level of the heading (defaults to 1).\n */\nexport function heading(text: string, options?: HeadingOptions): string {\n const level = options?.level ?? 1;\n return `${'#'.repeat(level)} ${text}`;\n}\n\n/**\n * Create a blockquote block.\n *\n * Markdown:\n * ```\n * > Content\n * > Content\n * ```\n *\n * @param text - The content of the blockquote.\n */\nexport function blockquote(content: string | readonly string[]): string {\n return prefixLines(joinBlocks(content), '> ');\n}\n\nexport type AlertType = 'note' | 'tip' | 'important' | 'warning' | 'caution';\n\n/**\n * Create a GitHub alert (callout) block.\n *\n * Markdown:\n * ```\n * > [!NOTE]\n * > Content\n * ```\n *\n * @param type - The alert type: `note`, `tip`, `important`, `warning` or `caution`.\n * @param content - The content of the alert.\n */\nexport function alert(type: AlertType, content: string | readonly string[]): string {\n return blockquote(`[!${type.toUpperCase()}]\\n${joinBlocks(content)}`);\n}\n\ntype CodeBlockOptions = {\n language?: string;\n};\n\n/**\n * Create a code block.\n *\n * Markdown:\n * ```js\n * Content\n * ```\n *\n * @param content - The content of the code block.\n * @param language - The language of the code block.\n */\nexport function codeBlock(content: string, options?: CodeBlockOptions): string {\n const language = options?.language ?? '';\n const backticks = Math.max(maxBackticks(content), 2) + 1;\n return '`'.repeat(backticks) + language + '\\n' + content + '\\n' + '`'.repeat(backticks);\n}\n\n/**\n * Create an unordered list block.\n *\n * Markdown:\n * ```\n * - Item\n * - Item\n * ```\n *\n * @param items - The items of the list.\n */\nexport function list(items: readonly string[]): string {\n return items.map((item) => `- ${item}`).join('\\n');\n}\n\n/**\n * Create an ordered list block.\n *\n * Markdown:\n * ```\n * 1. Item\n * 2. Item\n * ```\n *\n * @param items - The items of the list.\n */\nexport function orderedList(items: readonly string[]): string {\n return items.map((item, index) => `${index + 1}. ${item}`).join('\\n');\n}\n\nexport type TaskListItem = {\n text: string;\n done?: boolean;\n};\n\n/**\n * Create a task list block.\n *\n * Markdown:\n * ```\n * - [x] Done item\n * - [ ] Pending item\n * ```\n *\n * @param items - The items of the task list.\n */\nexport function taskList(items: readonly (string | TaskListItem)[]): string {\n const result = [];\n for (const item of items) {\n const text = typeof item === 'string' ? item : item.text;\n const done = typeof item === 'string' ? false : item.done;\n result.push(`- [${done ? 'x' : ' '}] ${text}`);\n }\n\n return result.join('\\n');\n}\n"],"mappings":";;;;;;;;;;;AAOO,MAAMA,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,KAAK;AAa5B,SAASE,OAAOA,CAACC,IAAY,EAAEC,OAAwB,EAAU;EACtE,MAAMC,KAAK,GAAGD,OAAO,EAAEC,KAAK,IAAI,CAAC;EACjC,OAAO,GAAG,GAAG,CAACC,MAAM,CAACD,KAAK,CAAC,IAAIF,IAAI,EAAE;AACvC;AAaO,SAASI,UAAUA,CAACC,OAAmC,EAAU;EACtE,OAAO,IAAAC,kBAAW,EAAC,IAAAC,iBAAU,EAACF,OAAO,CAAC,EAAE,IAAI,CAAC;AAC/C;AAgBO,SAASG,KAAKA,CAACC,IAAe,EAAEJ,OAAmC,EAAU;EAClF,OAAOD,UAAU,CAAC,KAAKK,IAAI,CAACC,WAAW,CAAC,CAAC,MAAM,IAAAH,iBAAU,EAACF,OAAO,CAAC,EAAE,CAAC;AACvE;AAiBO,SAASM,SAASA,CAACN,OAAe,EAAEJ,OAA0B,EAAU;EAC7E,MAAMW,QAAQ,GAAGX,OAAO,EAAEW,QAAQ,IAAI,EAAE;EACxC,MAAMC,SAAS,GAAGC,IAAI,CAACC,GAAG,CAAC,IAAAC,mBAAY,EAACX,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC;EACxD,OAAO,GAAG,CAACF,MAAM,CAACU,SAAS,CAAC,GAAGD,QAAQ,GAAG,IAAI,GAAGP,OAAO,GAAG,IAAI,GAAG,GAAG,CAACF,MAAM,CAACU,SAAS,CAAC;AACzF;AAaO,SAASI,IAAIA,CAACC,KAAwB,EAAU;EACrD,OAAOA,KAAK,CAACC,GAAG,CAAEC,IAAI,IAAK,KAAKA,IAAI,EAAE,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACpD;AAaO,SAASC,WAAWA,CAACJ,KAAwB,EAAU;EAC5D,OAAOA,KAAK,CAACC,GAAG,CAAC,CAACC,IAAI,EAAEG,KAAK,KAAK,GAAGA,KAAK,GAAG,CAAC,KAAKH,IAAI,EAAE,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACvE;AAkBO,SAASG,QAAQA,CAACN,KAAyC,EAAU;EAC1E,MAAMO,MAAM,GAAG,EAAE;EACjB,KAAK,MAAML,IAAI,IAAIF,KAAK,EAAE;IACxB,MAAMlB,IAAI,GAAG,OAAOoB,IAAI,KAAK,QAAQ,GAAGA,IAAI,GAAGA,IAAI,CAACpB,IAAI;IACxD,MAAM0B,IAAI,GAAG,OAAON,IAAI,KAAK,QAAQ,GAAG,KAAK,GAAGA,IAAI,CAACM,IAAI;IACzDD,MAAM,CAACE,IAAI,CAAC,MAAMD,IAAI,GAAG,GAAG,GAAG,GAAG,KAAK1B,IAAI,EAAE,CAAC;EAChD;EAEA,OAAOyB,MAAM,CAACJ,IAAI,CAAC,IAAI,CAAC;AAC1B","ignoreList":[]}
@@ -1,5 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "alert", {
4
+ enumerable: true,
5
+ get: function () {
6
+ return _block.alert;
7
+ }
8
+ });
3
9
  Object.defineProperty(exports, "blockquote", {
4
10
  enumerable: true,
5
11
  get: function () {
@@ -90,12 +96,24 @@ Object.defineProperty(exports, "orderedList", {
90
96
  return _block.orderedList;
91
97
  }
92
98
  });
99
+ Object.defineProperty(exports, "strikethrough", {
100
+ enumerable: true,
101
+ get: function () {
102
+ return _inline.strikethrough;
103
+ }
104
+ });
93
105
  Object.defineProperty(exports, "table", {
94
106
  enumerable: true,
95
107
  get: function () {
96
108
  return _table.table;
97
109
  }
98
110
  });
111
+ Object.defineProperty(exports, "taskList", {
112
+ enumerable: true,
113
+ get: function () {
114
+ return _block.taskList;
115
+ }
116
+ });
99
117
  var _block = require("./block.js");
100
118
  var _inline = require("./inline.js");
101
119
  var _table = require("./table.js");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export { horizontalRule, heading, blockquote, orderedList, list, codeBlock } from './block';\nexport { code, italic, bold, link, image } from './inline';\nexport { table } from './table';\nexport { lineBreak, disclosure } from './html';\nexport { escape, joinBlocks } from './utils';\n\nexport type { TableOptions } from './table';\nexport type { DisclosureOptions } from './html';\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export {\n horizontalRule,\n heading,\n blockquote,\n alert,\n orderedList,\n list,\n codeBlock,\n taskList,\n} from './block';\nexport { code, italic, bold, strikethrough, link, image } from './inline';\nexport { table } from './table';\nexport { lineBreak, disclosure } from './html';\nexport { escape, joinBlocks } from './utils';\n\nexport type { TableOptions } from './table';\nexport type { DisclosureOptions } from './html';\nexport type { AlertType, TaskListItem } from './block';\n"],"mappings":"","ignoreList":[]}
@@ -5,6 +5,7 @@ exports.code = code;
5
5
  exports.image = image;
6
6
  exports.italic = italic;
7
7
  exports.link = link;
8
+ exports.strikethrough = strikethrough;
8
9
  var _utils = require("./utils.js");
9
10
  function italic(text) {
10
11
  return `*${text}*`;
@@ -12,15 +13,18 @@ function italic(text) {
12
13
  function bold(text) {
13
14
  return `**${text}**`;
14
15
  }
16
+ function strikethrough(text) {
17
+ return `~~${text}~~`;
18
+ }
15
19
  function code(text) {
16
20
  const backticksCount = (0, _utils.maxBackticks)(text) + 1;
17
21
  const backticks = '`'.repeat(backticksCount);
18
- const frontPadding = text.startsWith('`') ? ' ' : '';
19
- const backPadding = text.endsWith('`') ? ' ' : '';
20
- return `${backticks}${frontPadding}${text}${backPadding}${backticks}`;
22
+ const needsPadding = text.startsWith('`') || text.endsWith('`') || text.startsWith(' ') && text.endsWith(' ') && /[^ ]/.test(text);
23
+ const padding = needsPadding ? ' ' : '';
24
+ return `${backticks}${padding}${text}${padding}${backticks}`;
21
25
  }
22
26
  function link(url, text) {
23
- return text ? `[${text}](${url})` : `<${url}>`;
27
+ return `[${text || url}](${url})`;
24
28
  }
25
29
  function image(url, text) {
26
30
  return `![${text ?? ''}](${url})`;
@@ -1 +1 @@
1
- {"version":3,"file":"inline.js","names":["italic","text","bold","code","backticksCount","maxBackticks","backticks","repeat","frontPadding","startsWith","backPadding","endsWith","link","url","image"],"sources":["../../src/inline.ts"],"sourcesContent":["import { maxBackticks } from './utils';\n\n/**\n * Create an italic text.\n *\n * Markdown: `*text*`\n *\n * @param text - The text to be italicized.\n */\nexport function italic(text: string): string {\n return `*${text}*`;\n}\n\n/**\n * Create a bold text.\n *\n * Markdown: `**text**`\n *\n * @param text - The text to be bolded.\n */\nexport function bold(text: string): string {\n return `**${text}**`;\n}\n\n/**\n * Create a code text.\n *\n * Markdown: `code`\n *\n * @param text - The text to be marked as code.\n */\nexport function code(text: string): string {\n const backticksCount = maxBackticks(text) + 1;\n const backticks = '`'.repeat(backticksCount);\n const frontPadding = text.startsWith('`') ? ' ' : '';\n const backPadding = text.endsWith('`') ? ' ' : '';\n return `${backticks}${frontPadding}${text}${backPadding}${backticks}`;\n}\n\n/**\n * Create a link or autolink span.\n *\n * Markdown:\n * - `[text](url)` link when `text` is provided\n * - `<url>` autolink when `text` is not provided\n *\n * @param url - The URL to be linked.\n * @param text - The title for the link (optional).\n */\nexport function link(url: string, text?: string): string {\n return text ? `[${text}](${url})` : `<${url}>`;\n}\n\n/**\n * Create an image text.\n *\n * Markdown: `![text](url)`\n *\n * @param url - The URL of the image.\n * @param text - The description for the image (optional).\n */\nexport function image(url: string, text?: string): string {\n return `![${text ?? ''}](${url})`;\n}\n"],"mappings":";;;;;;;;AASO,SAASA,MAAMA,CAACC,IAAY,EAAU;EAC3C,OAAO,IAAIA,IAAI,GAAG;AACpB;AASO,SAASC,IAAIA,CAACD,IAAY,EAAU;EACzC,OAAO,KAAKA,IAAI,IAAI;AACtB;AASO,SAASE,IAAIA,CAACF,IAAY,EAAU;EACzC,MAAMG,cAAc,GAAG,IAAAC,mBAAY,EAACJ,IAAI,CAAC,GAAG,CAAC;EAC7C,MAAMK,SAAS,GAAG,GAAG,CAACC,MAAM,CAACH,cAAc,CAAC;EAC5C,MAAMI,YAAY,GAAGP,IAAI,CAACQ,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,EAAE;EACpD,MAAMC,WAAW,GAAGT,IAAI,CAACU,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,EAAE;EACjD,OAAO,GAAGL,SAAS,GAAGE,YAAY,GAAGP,IAAI,GAAGS,WAAW,GAAGJ,SAAS,EAAE;AACvE;AAYO,SAASM,IAAIA,CAACC,GAAW,EAAEZ,IAAa,EAAU;EACvD,OAAOA,IAAI,GAAG,IAAIA,IAAI,KAAKY,GAAG,GAAG,GAAG,IAAIA,GAAG,GAAG;AAChD;AAUO,SAASC,KAAKA,CAACD,GAAW,EAAEZ,IAAa,EAAU;EACxD,OAAO,KAAKA,IAAI,IAAI,EAAE,KAAKY,GAAG,GAAG;AACnC","ignoreList":[]}
1
+ {"version":3,"file":"inline.js","names":["italic","text","bold","strikethrough","code","backticksCount","maxBackticks","backticks","repeat","needsPadding","startsWith","endsWith","test","padding","link","url","image"],"sources":["../../src/inline.ts"],"sourcesContent":["import { maxBackticks } from './utils';\n\n/**\n * Create an italic text.\n *\n * Markdown: `*text*`\n *\n * @param text - The text to be italicized.\n */\nexport function italic(text: string): string {\n return `*${text}*`;\n}\n\n/**\n * Create a bold text.\n *\n * Markdown: `**text**`\n *\n * @param text - The text to be bolded.\n */\nexport function bold(text: string): string {\n return `**${text}**`;\n}\n\n/**\n * Create a strikethrough text.\n *\n * Markdown: `~~text~~`\n *\n * @param text - The text to be struck through.\n */\nexport function strikethrough(text: string): string {\n return `~~${text}~~`;\n}\n\n/**\n * Create a code text.\n *\n * Markdown: `code`\n *\n * @param text - The text to be marked as code.\n */\nexport function code(text: string): string {\n const backticksCount = maxBackticks(text) + 1;\n const backticks = '`'.repeat(backticksCount);\n const needsPadding =\n text.startsWith('`') ||\n text.endsWith('`') ||\n (text.startsWith(' ') && text.endsWith(' ') && /[^ ]/.test(text));\n const padding = needsPadding ? ' ' : '';\n return `${backticks}${padding}${text}${padding}${backticks}`;\n}\n\n/**\n * Create a link span.\n *\n * Markdown: `[text](url)`, or `[url](url)` when `text` is not provided.\n *\n * @param url - The URL to be linked.\n * @param text - The title for the link (optional, defaults to `url`).\n */\nexport function link(url: string, text?: string): string {\n return `[${text || url}](${url})`;\n}\n\n/**\n * Create an image text.\n *\n * Markdown: `![text](url)`\n *\n * @param url - The URL of the image.\n * @param text - The description for the image (optional).\n */\nexport function image(url: string, text?: string): string {\n return `![${text ?? ''}](${url})`;\n}\n"],"mappings":";;;;;;;;;AASO,SAASA,MAAMA,CAACC,IAAY,EAAU;EAC3C,OAAO,IAAIA,IAAI,GAAG;AACpB;AASO,SAASC,IAAIA,CAACD,IAAY,EAAU;EACzC,OAAO,KAAKA,IAAI,IAAI;AACtB;AASO,SAASE,aAAaA,CAACF,IAAY,EAAU;EAClD,OAAO,KAAKA,IAAI,IAAI;AACtB;AASO,SAASG,IAAIA,CAACH,IAAY,EAAU;EACzC,MAAMI,cAAc,GAAG,IAAAC,mBAAY,EAACL,IAAI,CAAC,GAAG,CAAC;EAC7C,MAAMM,SAAS,GAAG,GAAG,CAACC,MAAM,CAACH,cAAc,CAAC;EAC5C,MAAMI,YAAY,GAChBR,IAAI,CAACS,UAAU,CAAC,GAAG,CAAC,IACpBT,IAAI,CAACU,QAAQ,CAAC,GAAG,CAAC,IACjBV,IAAI,CAACS,UAAU,CAAC,GAAG,CAAC,IAAIT,IAAI,CAACU,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAACC,IAAI,CAACX,IAAI,CAAE;EACnE,MAAMY,OAAO,GAAGJ,YAAY,GAAG,GAAG,GAAG,EAAE;EACvC,OAAO,GAAGF,SAAS,GAAGM,OAAO,GAAGZ,IAAI,GAAGY,OAAO,GAAGN,SAAS,EAAE;AAC9D;AAUO,SAASO,IAAIA,CAACC,GAAW,EAAEd,IAAa,EAAU;EACvD,OAAO,IAAIA,IAAI,IAAIc,GAAG,KAAKA,GAAG,GAAG;AACnC;AAUO,SAASC,KAAKA,CAACD,GAAW,EAAEd,IAAa,EAAU;EACxD,OAAO,KAAKA,IAAI,IAAI,EAAE,KAAKc,GAAG,GAAG;AACnC","ignoreList":[]}
@@ -21,8 +21,8 @@ function escape(text) {
21
21
  function maxBackticks(text) {
22
22
  let max = 0;
23
23
  let current = 0;
24
- for (let i = 0; i < text.length; i++) {
25
- if (text[i] === '`') {
24
+ for (const char of text) {
25
+ if (char === '`') {
26
26
  current++;
27
27
  max = Math.max(max, current);
28
28
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["joinBlocks","blocks","map","trimBlock","filter","Boolean","join","block","replace","prefixLines","text","prefix","lines","split","line","escape","maxBackticks","max","current","i","length","Math"],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * Join blocks of text into a single markdown document (string).\n *\n * @param blocks - The blocks of text to join.\n * @returns Markdown document string.\n */\nexport function joinBlocks(blocks: string | readonly string[]): string {\n blocks = typeof blocks === 'string' ? [blocks] : blocks;\n\n return blocks.map(trimBlock).filter(Boolean).join('\\n\\n');\n}\n\nfunction trimBlock(block: string): string {\n return block.replace(/^\\n+|\\n+$/g, '');\n}\n\nexport function prefixLines(text: string, prefix: string): string {\n const lines = text.split('\\n');\n return lines.map((line) => `${prefix}${line}`).join('\\n');\n}\n\nexport function escape(text: string): string {\n return text.replace(/([\\\\`*_{}[\\]()#+\\-.!|<>])/g, '\\\\$1');\n}\n\nexport function maxBackticks(text: string): number {\n let max = 0;\n let current = 0;\n\n for (let i = 0; i < text.length; i++) {\n if (text[i] === '`') {\n current++;\n max = Math.max(max, current);\n } else {\n current = 0;\n }\n }\n\n return max;\n}\n"],"mappings":";;;;;;AAMO,SAASA,UAAUA,CAACC,MAAkC,EAAU;EACrEA,MAAM,GAAG,OAAOA,MAAM,KAAK,QAAQ,GAAG,CAACA,MAAM,CAAC,GAAGA,MAAM;EAEvD,OAAOA,MAAM,CAACC,GAAG,CAACC,SAAS,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,MAAM,CAAC;AAC3D;AAEA,SAASH,SAASA,CAACI,KAAa,EAAU;EACxC,OAAOA,KAAK,CAACC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;AACxC;AAEO,SAASC,WAAWA,CAACC,IAAY,EAAEC,MAAc,EAAU;EAChE,MAAMC,KAAK,GAAGF,IAAI,CAACG,KAAK,CAAC,IAAI,CAAC;EAC9B,OAAOD,KAAK,CAACV,GAAG,CAAEY,IAAI,IAAK,GAAGH,MAAM,GAAGG,IAAI,EAAE,CAAC,CAACR,IAAI,CAAC,IAAI,CAAC;AAC3D;AAEO,SAASS,MAAMA,CAACL,IAAY,EAAU;EAC3C,OAAOA,IAAI,CAACF,OAAO,CAAC,4BAA4B,EAAE,MAAM,CAAC;AAC3D;AAEO,SAASQ,YAAYA,CAACN,IAAY,EAAU;EACjD,IAAIO,GAAG,GAAG,CAAC;EACX,IAAIC,OAAO,GAAG,CAAC;EAEf,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGT,IAAI,CAACU,MAAM,EAAED,CAAC,EAAE,EAAE;IACpC,IAAIT,IAAI,CAACS,CAAC,CAAC,KAAK,GAAG,EAAE;MACnBD,OAAO,EAAE;MACTD,GAAG,GAAGI,IAAI,CAACJ,GAAG,CAACA,GAAG,EAAEC,OAAO,CAAC;IAC9B,CAAC,MAAM;MACLA,OAAO,GAAG,CAAC;IACb;EACF;EAEA,OAAOD,GAAG;AACZ","ignoreList":[]}
1
+ {"version":3,"file":"utils.js","names":["joinBlocks","blocks","map","trimBlock","filter","Boolean","join","block","replace","prefixLines","text","prefix","lines","split","line","escape","maxBackticks","max","current","char","Math"],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * Join blocks of text into a single markdown document (string).\n *\n * @param blocks - The blocks of text to join.\n * @returns Markdown document string.\n */\nexport function joinBlocks(blocks: string | readonly string[]): string {\n blocks = typeof blocks === 'string' ? [blocks] : blocks;\n\n return blocks.map(trimBlock).filter(Boolean).join('\\n\\n');\n}\n\nfunction trimBlock(block: string): string {\n return block.replace(/^\\n+|\\n+$/g, '');\n}\n\nexport function prefixLines(text: string, prefix: string): string {\n const lines = text.split('\\n');\n return lines.map((line) => `${prefix}${line}`).join('\\n');\n}\n\nexport function escape(text: string): string {\n return text.replace(/([\\\\`*_{}[\\]()#+\\-.!|<>])/g, '\\\\$1');\n}\n\nexport function maxBackticks(text: string): number {\n let max = 0;\n let current = 0;\n\n for (const char of text) {\n if (char === '`') {\n current++;\n max = Math.max(max, current);\n } else {\n current = 0;\n }\n }\n\n return max;\n}\n"],"mappings":";;;;;;AAMO,SAASA,UAAUA,CAACC,MAAkC,EAAU;EACrEA,MAAM,GAAG,OAAOA,MAAM,KAAK,QAAQ,GAAG,CAACA,MAAM,CAAC,GAAGA,MAAM;EAEvD,OAAOA,MAAM,CAACC,GAAG,CAACC,SAAS,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,MAAM,CAAC;AAC3D;AAEA,SAASH,SAASA,CAACI,KAAa,EAAU;EACxC,OAAOA,KAAK,CAACC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;AACxC;AAEO,SAASC,WAAWA,CAACC,IAAY,EAAEC,MAAc,EAAU;EAChE,MAAMC,KAAK,GAAGF,IAAI,CAACG,KAAK,CAAC,IAAI,CAAC;EAC9B,OAAOD,KAAK,CAACV,GAAG,CAAEY,IAAI,IAAK,GAAGH,MAAM,GAAGG,IAAI,EAAE,CAAC,CAACR,IAAI,CAAC,IAAI,CAAC;AAC3D;AAEO,SAASS,MAAMA,CAACL,IAAY,EAAU;EAC3C,OAAOA,IAAI,CAACF,OAAO,CAAC,4BAA4B,EAAE,MAAM,CAAC;AAC3D;AAEO,SAASQ,YAAYA,CAACN,IAAY,EAAU;EACjD,IAAIO,GAAG,GAAG,CAAC;EACX,IAAIC,OAAO,GAAG,CAAC;EAEf,KAAK,MAAMC,IAAI,IAAIT,IAAI,EAAE;IACvB,IAAIS,IAAI,KAAK,GAAG,EAAE;MAChBD,OAAO,EAAE;MACTD,GAAG,GAAGG,IAAI,CAACH,GAAG,CAACA,GAAG,EAAEC,OAAO,CAAC;IAC9B,CAAC,MAAM;MACLA,OAAO,GAAG,CAAC;IACb;EACF;EAEA,OAAOD,GAAG;AACZ","ignoreList":[]}
@@ -7,6 +7,9 @@ export function heading(text, options) {
7
7
  export function blockquote(content) {
8
8
  return prefixLines(joinBlocks(content), '> ');
9
9
  }
10
+ export function alert(type, content) {
11
+ return blockquote(`[!${type.toUpperCase()}]\n${joinBlocks(content)}`);
12
+ }
10
13
  export function codeBlock(content, options) {
11
14
  const language = options?.language ?? '';
12
15
  const backticks = Math.max(maxBackticks(content), 2) + 1;
@@ -18,4 +21,13 @@ export function list(items) {
18
21
  export function orderedList(items) {
19
22
  return items.map((item, index) => `${index + 1}. ${item}`).join('\n');
20
23
  }
24
+ export function taskList(items) {
25
+ const result = [];
26
+ for (const item of items) {
27
+ const text = typeof item === 'string' ? item : item.text;
28
+ const done = typeof item === 'string' ? false : item.done;
29
+ result.push(`- [${done ? 'x' : ' '}] ${text}`);
30
+ }
31
+ return result.join('\n');
32
+ }
21
33
  //# sourceMappingURL=block.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"block.mjs","names":["joinBlocks","maxBackticks","prefixLines","horizontalRule","heading","text","options","level","repeat","blockquote","content","codeBlock","language","backticks","Math","max","list","items","map","item","join","orderedList","index"],"sources":["../../src/block.ts"],"sourcesContent":["import { joinBlocks, maxBackticks, prefixLines } from './utils';\n\n/**\n * Create a horizontal rule block.\n *\n * Markdown: `---`\n */\nexport const horizontalRule = '---';\n\ntype HeadingOptions = {\n level: number;\n};\n\n/**\n * Create a heading block.\n * Markdown: `# Heading`\n *\n * @param text - The text of the heading.\n * @param level - The level of the heading (defaults to 1).\n */\nexport function heading(text: string, options?: HeadingOptions): string {\n const level = options?.level ?? 1;\n return `${'#'.repeat(level)} ${text}`;\n}\n\n/**\n * Create a blockquote block.\n *\n * Markdown:\n * ```\n * > Content\n * > Content\n * ```\n *\n * @param text - The content of the blockquote.\n */\nexport function blockquote(content: string | readonly string[]): string {\n return prefixLines(joinBlocks(content), '> ');\n}\n\ntype CodeBlockOptions = {\n language?: string;\n};\n\n/**\n * Create a code block.\n *\n * Markdown:\n * ```js\n * Content\n * ```\n *\n * @param content - The content of the code block.\n * @param language - The language of the code block.\n */\nexport function codeBlock(content: string, options?: CodeBlockOptions): string {\n const language = options?.language ?? '';\n const backticks = Math.max(maxBackticks(content), 2) + 1;\n return '`'.repeat(backticks) + language + '\\n' + content + '\\n' + '`'.repeat(backticks);\n}\n\n/**\n * Create an unordered list block.\n *\n * Markdown:\n * ```\n * - Item\n * - Item\n * ```\n *\n * @param items - The items of the list.\n */\nexport function list(items: readonly string[]): string {\n return items.map((item) => `- ${item}`).join('\\n');\n}\n\n/**\n * Create an ordered list block.\n *\n * Markdown:\n * ```\n * 1. Item\n * 2. Item\n * ```\n *\n * @param items - The items of the list.\n */\nexport function orderedList(items: readonly string[]): string {\n return items.map((item, index) => `${index + 1}. ${item}`).join('\\n');\n}\n"],"mappings":"SAASA,UAAU,EAAEC,YAAY,EAAEC,WAAW;AAO9C,OAAO,MAAMC,cAAc,GAAG,KAAK;AAanC,OAAO,SAASC,OAAOA,CAACC,IAAY,EAAEC,OAAwB,EAAU;EACtE,MAAMC,KAAK,GAAGD,OAAO,EAAEC,KAAK,IAAI,CAAC;EACjC,OAAO,GAAG,GAAG,CAACC,MAAM,CAACD,KAAK,CAAC,IAAIF,IAAI,EAAE;AACvC;AAaA,OAAO,SAASI,UAAUA,CAACC,OAAmC,EAAU;EACtE,OAAOR,WAAW,CAACF,UAAU,CAACU,OAAO,CAAC,EAAE,IAAI,CAAC;AAC/C;AAiBA,OAAO,SAASC,SAASA,CAACD,OAAe,EAAEJ,OAA0B,EAAU;EAC7E,MAAMM,QAAQ,GAAGN,OAAO,EAAEM,QAAQ,IAAI,EAAE;EACxC,MAAMC,SAAS,GAAGC,IAAI,CAACC,GAAG,CAACd,YAAY,CAACS,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC;EACxD,OAAO,GAAG,CAACF,MAAM,CAACK,SAAS,CAAC,GAAGD,QAAQ,GAAG,IAAI,GAAGF,OAAO,GAAG,IAAI,GAAG,GAAG,CAACF,MAAM,CAACK,SAAS,CAAC;AACzF;AAaA,OAAO,SAASG,IAAIA,CAACC,KAAwB,EAAU;EACrD,OAAOA,KAAK,CAACC,GAAG,CAAEC,IAAI,IAAK,KAAKA,IAAI,EAAE,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACpD;AAaA,OAAO,SAASC,WAAWA,CAACJ,KAAwB,EAAU;EAC5D,OAAOA,KAAK,CAACC,GAAG,CAAC,CAACC,IAAI,EAAEG,KAAK,KAAK,GAAGA,KAAK,GAAG,CAAC,KAAKH,IAAI,EAAE,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACvE","ignoreList":[]}
1
+ {"version":3,"file":"block.mjs","names":["joinBlocks","maxBackticks","prefixLines","horizontalRule","heading","text","options","level","repeat","blockquote","content","alert","type","toUpperCase","codeBlock","language","backticks","Math","max","list","items","map","item","join","orderedList","index","taskList","result","done","push"],"sources":["../../src/block.ts"],"sourcesContent":["import { joinBlocks, maxBackticks, prefixLines } from './utils';\n\n/**\n * Create a horizontal rule block.\n *\n * Markdown: `---`\n */\nexport const horizontalRule = '---';\n\ntype HeadingOptions = {\n level: number;\n};\n\n/**\n * Create a heading block.\n * Markdown: `# Heading`\n *\n * @param text - The text of the heading.\n * @param level - The level of the heading (defaults to 1).\n */\nexport function heading(text: string, options?: HeadingOptions): string {\n const level = options?.level ?? 1;\n return `${'#'.repeat(level)} ${text}`;\n}\n\n/**\n * Create a blockquote block.\n *\n * Markdown:\n * ```\n * > Content\n * > Content\n * ```\n *\n * @param text - The content of the blockquote.\n */\nexport function blockquote(content: string | readonly string[]): string {\n return prefixLines(joinBlocks(content), '> ');\n}\n\nexport type AlertType = 'note' | 'tip' | 'important' | 'warning' | 'caution';\n\n/**\n * Create a GitHub alert (callout) block.\n *\n * Markdown:\n * ```\n * > [!NOTE]\n * > Content\n * ```\n *\n * @param type - The alert type: `note`, `tip`, `important`, `warning` or `caution`.\n * @param content - The content of the alert.\n */\nexport function alert(type: AlertType, content: string | readonly string[]): string {\n return blockquote(`[!${type.toUpperCase()}]\\n${joinBlocks(content)}`);\n}\n\ntype CodeBlockOptions = {\n language?: string;\n};\n\n/**\n * Create a code block.\n *\n * Markdown:\n * ```js\n * Content\n * ```\n *\n * @param content - The content of the code block.\n * @param language - The language of the code block.\n */\nexport function codeBlock(content: string, options?: CodeBlockOptions): string {\n const language = options?.language ?? '';\n const backticks = Math.max(maxBackticks(content), 2) + 1;\n return '`'.repeat(backticks) + language + '\\n' + content + '\\n' + '`'.repeat(backticks);\n}\n\n/**\n * Create an unordered list block.\n *\n * Markdown:\n * ```\n * - Item\n * - Item\n * ```\n *\n * @param items - The items of the list.\n */\nexport function list(items: readonly string[]): string {\n return items.map((item) => `- ${item}`).join('\\n');\n}\n\n/**\n * Create an ordered list block.\n *\n * Markdown:\n * ```\n * 1. Item\n * 2. Item\n * ```\n *\n * @param items - The items of the list.\n */\nexport function orderedList(items: readonly string[]): string {\n return items.map((item, index) => `${index + 1}. ${item}`).join('\\n');\n}\n\nexport type TaskListItem = {\n text: string;\n done?: boolean;\n};\n\n/**\n * Create a task list block.\n *\n * Markdown:\n * ```\n * - [x] Done item\n * - [ ] Pending item\n * ```\n *\n * @param items - The items of the task list.\n */\nexport function taskList(items: readonly (string | TaskListItem)[]): string {\n const result = [];\n for (const item of items) {\n const text = typeof item === 'string' ? item : item.text;\n const done = typeof item === 'string' ? false : item.done;\n result.push(`- [${done ? 'x' : ' '}] ${text}`);\n }\n\n return result.join('\\n');\n}\n"],"mappings":"SAASA,UAAU,EAAEC,YAAY,EAAEC,WAAW;AAO9C,OAAO,MAAMC,cAAc,GAAG,KAAK;AAanC,OAAO,SAASC,OAAOA,CAACC,IAAY,EAAEC,OAAwB,EAAU;EACtE,MAAMC,KAAK,GAAGD,OAAO,EAAEC,KAAK,IAAI,CAAC;EACjC,OAAO,GAAG,GAAG,CAACC,MAAM,CAACD,KAAK,CAAC,IAAIF,IAAI,EAAE;AACvC;AAaA,OAAO,SAASI,UAAUA,CAACC,OAAmC,EAAU;EACtE,OAAOR,WAAW,CAACF,UAAU,CAACU,OAAO,CAAC,EAAE,IAAI,CAAC;AAC/C;AAgBA,OAAO,SAASC,KAAKA,CAACC,IAAe,EAAEF,OAAmC,EAAU;EAClF,OAAOD,UAAU,CAAC,KAAKG,IAAI,CAACC,WAAW,CAAC,CAAC,MAAMb,UAAU,CAACU,OAAO,CAAC,EAAE,CAAC;AACvE;AAiBA,OAAO,SAASI,SAASA,CAACJ,OAAe,EAAEJ,OAA0B,EAAU;EAC7E,MAAMS,QAAQ,GAAGT,OAAO,EAAES,QAAQ,IAAI,EAAE;EACxC,MAAMC,SAAS,GAAGC,IAAI,CAACC,GAAG,CAACjB,YAAY,CAACS,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC;EACxD,OAAO,GAAG,CAACF,MAAM,CAACQ,SAAS,CAAC,GAAGD,QAAQ,GAAG,IAAI,GAAGL,OAAO,GAAG,IAAI,GAAG,GAAG,CAACF,MAAM,CAACQ,SAAS,CAAC;AACzF;AAaA,OAAO,SAASG,IAAIA,CAACC,KAAwB,EAAU;EACrD,OAAOA,KAAK,CAACC,GAAG,CAAEC,IAAI,IAAK,KAAKA,IAAI,EAAE,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACpD;AAaA,OAAO,SAASC,WAAWA,CAACJ,KAAwB,EAAU;EAC5D,OAAOA,KAAK,CAACC,GAAG,CAAC,CAACC,IAAI,EAAEG,KAAK,KAAK,GAAGA,KAAK,GAAG,CAAC,KAAKH,IAAI,EAAE,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;AACvE;AAkBA,OAAO,SAASG,QAAQA,CAACN,KAAyC,EAAU;EAC1E,MAAMO,MAAM,GAAG,EAAE;EACjB,KAAK,MAAML,IAAI,IAAIF,KAAK,EAAE;IACxB,MAAMf,IAAI,GAAG,OAAOiB,IAAI,KAAK,QAAQ,GAAGA,IAAI,GAAGA,IAAI,CAACjB,IAAI;IACxD,MAAMuB,IAAI,GAAG,OAAON,IAAI,KAAK,QAAQ,GAAG,KAAK,GAAGA,IAAI,CAACM,IAAI;IACzDD,MAAM,CAACE,IAAI,CAAC,MAAMD,IAAI,GAAG,GAAG,GAAG,GAAG,KAAKvB,IAAI,EAAE,CAAC;EAChD;EAEA,OAAOsB,MAAM,CAACJ,IAAI,CAAC,IAAI,CAAC;AAC1B","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- export { horizontalRule, heading, blockquote, orderedList, list, codeBlock } from "./block.mjs";
2
- export { code, italic, bold, link, image } from "./inline.mjs";
1
+ export { horizontalRule, heading, blockquote, alert, orderedList, list, codeBlock, taskList } from "./block.mjs";
2
+ export { code, italic, bold, strikethrough, link, image } from "./inline.mjs";
3
3
  export { table } from "./table.mjs";
4
4
  export { lineBreak, disclosure } from "./html.mjs";
5
5
  export { escape, joinBlocks } from "./utils.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["horizontalRule","heading","blockquote","orderedList","list","codeBlock","code","italic","bold","link","image","table","lineBreak","disclosure","escape","joinBlocks"],"sources":["../../src/index.ts"],"sourcesContent":["export { horizontalRule, heading, blockquote, orderedList, list, codeBlock } from './block';\nexport { code, italic, bold, link, image } from './inline';\nexport { table } from './table';\nexport { lineBreak, disclosure } from './html';\nexport { escape, joinBlocks } from './utils';\n\nexport type { TableOptions } from './table';\nexport type { DisclosureOptions } from './html';\n"],"mappings":"SAASA,cAAc,EAAEC,OAAO,EAAEC,UAAU,EAAEC,WAAW,EAAEC,IAAI,EAAEC,SAAS;AAAA,SACjEC,IAAI,EAAEC,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAEC,KAAK;AAAA,SAC/BC,KAAK;AAAA,SACLC,SAAS,EAAEC,UAAU;AAAA,SACrBC,MAAM,EAAEC,UAAU","ignoreList":[]}
1
+ {"version":3,"file":"index.mjs","names":["horizontalRule","heading","blockquote","alert","orderedList","list","codeBlock","taskList","code","italic","bold","strikethrough","link","image","table","lineBreak","disclosure","escape","joinBlocks"],"sources":["../../src/index.ts"],"sourcesContent":["export {\n horizontalRule,\n heading,\n blockquote,\n alert,\n orderedList,\n list,\n codeBlock,\n taskList,\n} from './block';\nexport { code, italic, bold, strikethrough, link, image } from './inline';\nexport { table } from './table';\nexport { lineBreak, disclosure } from './html';\nexport { escape, joinBlocks } from './utils';\n\nexport type { TableOptions } from './table';\nexport type { DisclosureOptions } from './html';\nexport type { AlertType, TaskListItem } from './block';\n"],"mappings":"SACEA,cAAc,EACdC,OAAO,EACPC,UAAU,EACVC,KAAK,EACLC,WAAW,EACXC,IAAI,EACJC,SAAS,EACTC,QAAQ;AAAA,SAEDC,IAAI,EAAEC,MAAM,EAAEC,IAAI,EAAEC,aAAa,EAAEC,IAAI,EAAEC,KAAK;AAAA,SAC9CC,KAAK;AAAA,SACLC,SAAS,EAAEC,UAAU;AAAA,SACrBC,MAAM,EAAEC,UAAU","ignoreList":[]}
@@ -5,15 +5,18 @@ export function italic(text) {
5
5
  export function bold(text) {
6
6
  return `**${text}**`;
7
7
  }
8
+ export function strikethrough(text) {
9
+ return `~~${text}~~`;
10
+ }
8
11
  export function code(text) {
9
12
  const backticksCount = maxBackticks(text) + 1;
10
13
  const backticks = '`'.repeat(backticksCount);
11
- const frontPadding = text.startsWith('`') ? ' ' : '';
12
- const backPadding = text.endsWith('`') ? ' ' : '';
13
- return `${backticks}${frontPadding}${text}${backPadding}${backticks}`;
14
+ const needsPadding = text.startsWith('`') || text.endsWith('`') || text.startsWith(' ') && text.endsWith(' ') && /[^ ]/.test(text);
15
+ const padding = needsPadding ? ' ' : '';
16
+ return `${backticks}${padding}${text}${padding}${backticks}`;
14
17
  }
15
18
  export function link(url, text) {
16
- return text ? `[${text}](${url})` : `<${url}>`;
19
+ return `[${text || url}](${url})`;
17
20
  }
18
21
  export function image(url, text) {
19
22
  return `![${text ?? ''}](${url})`;
@@ -1 +1 @@
1
- {"version":3,"file":"inline.mjs","names":["maxBackticks","italic","text","bold","code","backticksCount","backticks","repeat","frontPadding","startsWith","backPadding","endsWith","link","url","image"],"sources":["../../src/inline.ts"],"sourcesContent":["import { maxBackticks } from './utils';\n\n/**\n * Create an italic text.\n *\n * Markdown: `*text*`\n *\n * @param text - The text to be italicized.\n */\nexport function italic(text: string): string {\n return `*${text}*`;\n}\n\n/**\n * Create a bold text.\n *\n * Markdown: `**text**`\n *\n * @param text - The text to be bolded.\n */\nexport function bold(text: string): string {\n return `**${text}**`;\n}\n\n/**\n * Create a code text.\n *\n * Markdown: `code`\n *\n * @param text - The text to be marked as code.\n */\nexport function code(text: string): string {\n const backticksCount = maxBackticks(text) + 1;\n const backticks = '`'.repeat(backticksCount);\n const frontPadding = text.startsWith('`') ? ' ' : '';\n const backPadding = text.endsWith('`') ? ' ' : '';\n return `${backticks}${frontPadding}${text}${backPadding}${backticks}`;\n}\n\n/**\n * Create a link or autolink span.\n *\n * Markdown:\n * - `[text](url)` link when `text` is provided\n * - `<url>` autolink when `text` is not provided\n *\n * @param url - The URL to be linked.\n * @param text - The title for the link (optional).\n */\nexport function link(url: string, text?: string): string {\n return text ? `[${text}](${url})` : `<${url}>`;\n}\n\n/**\n * Create an image text.\n *\n * Markdown: `![text](url)`\n *\n * @param url - The URL of the image.\n * @param text - The description for the image (optional).\n */\nexport function image(url: string, text?: string): string {\n return `![${text ?? ''}](${url})`;\n}\n"],"mappings":"SAASA,YAAY;AASrB,OAAO,SAASC,MAAMA,CAACC,IAAY,EAAU;EAC3C,OAAO,IAAIA,IAAI,GAAG;AACpB;AASA,OAAO,SAASC,IAAIA,CAACD,IAAY,EAAU;EACzC,OAAO,KAAKA,IAAI,IAAI;AACtB;AASA,OAAO,SAASE,IAAIA,CAACF,IAAY,EAAU;EACzC,MAAMG,cAAc,GAAGL,YAAY,CAACE,IAAI,CAAC,GAAG,CAAC;EAC7C,MAAMI,SAAS,GAAG,GAAG,CAACC,MAAM,CAACF,cAAc,CAAC;EAC5C,MAAMG,YAAY,GAAGN,IAAI,CAACO,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,EAAE;EACpD,MAAMC,WAAW,GAAGR,IAAI,CAACS,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,EAAE;EACjD,OAAO,GAAGL,SAAS,GAAGE,YAAY,GAAGN,IAAI,GAAGQ,WAAW,GAAGJ,SAAS,EAAE;AACvE;AAYA,OAAO,SAASM,IAAIA,CAACC,GAAW,EAAEX,IAAa,EAAU;EACvD,OAAOA,IAAI,GAAG,IAAIA,IAAI,KAAKW,GAAG,GAAG,GAAG,IAAIA,GAAG,GAAG;AAChD;AAUA,OAAO,SAASC,KAAKA,CAACD,GAAW,EAAEX,IAAa,EAAU;EACxD,OAAO,KAAKA,IAAI,IAAI,EAAE,KAAKW,GAAG,GAAG;AACnC","ignoreList":[]}
1
+ {"version":3,"file":"inline.mjs","names":["maxBackticks","italic","text","bold","strikethrough","code","backticksCount","backticks","repeat","needsPadding","startsWith","endsWith","test","padding","link","url","image"],"sources":["../../src/inline.ts"],"sourcesContent":["import { maxBackticks } from './utils';\n\n/**\n * Create an italic text.\n *\n * Markdown: `*text*`\n *\n * @param text - The text to be italicized.\n */\nexport function italic(text: string): string {\n return `*${text}*`;\n}\n\n/**\n * Create a bold text.\n *\n * Markdown: `**text**`\n *\n * @param text - The text to be bolded.\n */\nexport function bold(text: string): string {\n return `**${text}**`;\n}\n\n/**\n * Create a strikethrough text.\n *\n * Markdown: `~~text~~`\n *\n * @param text - The text to be struck through.\n */\nexport function strikethrough(text: string): string {\n return `~~${text}~~`;\n}\n\n/**\n * Create a code text.\n *\n * Markdown: `code`\n *\n * @param text - The text to be marked as code.\n */\nexport function code(text: string): string {\n const backticksCount = maxBackticks(text) + 1;\n const backticks = '`'.repeat(backticksCount);\n const needsPadding =\n text.startsWith('`') ||\n text.endsWith('`') ||\n (text.startsWith(' ') && text.endsWith(' ') && /[^ ]/.test(text));\n const padding = needsPadding ? ' ' : '';\n return `${backticks}${padding}${text}${padding}${backticks}`;\n}\n\n/**\n * Create a link span.\n *\n * Markdown: `[text](url)`, or `[url](url)` when `text` is not provided.\n *\n * @param url - The URL to be linked.\n * @param text - The title for the link (optional, defaults to `url`).\n */\nexport function link(url: string, text?: string): string {\n return `[${text || url}](${url})`;\n}\n\n/**\n * Create an image text.\n *\n * Markdown: `![text](url)`\n *\n * @param url - The URL of the image.\n * @param text - The description for the image (optional).\n */\nexport function image(url: string, text?: string): string {\n return `![${text ?? ''}](${url})`;\n}\n"],"mappings":"SAASA,YAAY;AASrB,OAAO,SAASC,MAAMA,CAACC,IAAY,EAAU;EAC3C,OAAO,IAAIA,IAAI,GAAG;AACpB;AASA,OAAO,SAASC,IAAIA,CAACD,IAAY,EAAU;EACzC,OAAO,KAAKA,IAAI,IAAI;AACtB;AASA,OAAO,SAASE,aAAaA,CAACF,IAAY,EAAU;EAClD,OAAO,KAAKA,IAAI,IAAI;AACtB;AASA,OAAO,SAASG,IAAIA,CAACH,IAAY,EAAU;EACzC,MAAMI,cAAc,GAAGN,YAAY,CAACE,IAAI,CAAC,GAAG,CAAC;EAC7C,MAAMK,SAAS,GAAG,GAAG,CAACC,MAAM,CAACF,cAAc,CAAC;EAC5C,MAAMG,YAAY,GAChBP,IAAI,CAACQ,UAAU,CAAC,GAAG,CAAC,IACpBR,IAAI,CAACS,QAAQ,CAAC,GAAG,CAAC,IACjBT,IAAI,CAACQ,UAAU,CAAC,GAAG,CAAC,IAAIR,IAAI,CAACS,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAACC,IAAI,CAACV,IAAI,CAAE;EACnE,MAAMW,OAAO,GAAGJ,YAAY,GAAG,GAAG,GAAG,EAAE;EACvC,OAAO,GAAGF,SAAS,GAAGM,OAAO,GAAGX,IAAI,GAAGW,OAAO,GAAGN,SAAS,EAAE;AAC9D;AAUA,OAAO,SAASO,IAAIA,CAACC,GAAW,EAAEb,IAAa,EAAU;EACvD,OAAO,IAAIA,IAAI,IAAIa,GAAG,KAAKA,GAAG,GAAG;AACnC;AAUA,OAAO,SAASC,KAAKA,CAACD,GAAW,EAAEb,IAAa,EAAU;EACxD,OAAO,KAAKA,IAAI,IAAI,EAAE,KAAKa,GAAG,GAAG;AACnC","ignoreList":[]}
@@ -15,8 +15,8 @@ export function escape(text) {
15
15
  export function maxBackticks(text) {
16
16
  let max = 0;
17
17
  let current = 0;
18
- for (let i = 0; i < text.length; i++) {
19
- if (text[i] === '`') {
18
+ for (const char of text) {
19
+ if (char === '`') {
20
20
  current++;
21
21
  max = Math.max(max, current);
22
22
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","names":["joinBlocks","blocks","map","trimBlock","filter","Boolean","join","block","replace","prefixLines","text","prefix","lines","split","line","escape","maxBackticks","max","current","i","length","Math"],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * Join blocks of text into a single markdown document (string).\n *\n * @param blocks - The blocks of text to join.\n * @returns Markdown document string.\n */\nexport function joinBlocks(blocks: string | readonly string[]): string {\n blocks = typeof blocks === 'string' ? [blocks] : blocks;\n\n return blocks.map(trimBlock).filter(Boolean).join('\\n\\n');\n}\n\nfunction trimBlock(block: string): string {\n return block.replace(/^\\n+|\\n+$/g, '');\n}\n\nexport function prefixLines(text: string, prefix: string): string {\n const lines = text.split('\\n');\n return lines.map((line) => `${prefix}${line}`).join('\\n');\n}\n\nexport function escape(text: string): string {\n return text.replace(/([\\\\`*_{}[\\]()#+\\-.!|<>])/g, '\\\\$1');\n}\n\nexport function maxBackticks(text: string): number {\n let max = 0;\n let current = 0;\n\n for (let i = 0; i < text.length; i++) {\n if (text[i] === '`') {\n current++;\n max = Math.max(max, current);\n } else {\n current = 0;\n }\n }\n\n return max;\n}\n"],"mappings":"AAMA,OAAO,SAASA,UAAUA,CAACC,MAAkC,EAAU;EACrEA,MAAM,GAAG,OAAOA,MAAM,KAAK,QAAQ,GAAG,CAACA,MAAM,CAAC,GAAGA,MAAM;EAEvD,OAAOA,MAAM,CAACC,GAAG,CAACC,SAAS,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,MAAM,CAAC;AAC3D;AAEA,SAASH,SAASA,CAACI,KAAa,EAAU;EACxC,OAAOA,KAAK,CAACC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;AACxC;AAEA,OAAO,SAASC,WAAWA,CAACC,IAAY,EAAEC,MAAc,EAAU;EAChE,MAAMC,KAAK,GAAGF,IAAI,CAACG,KAAK,CAAC,IAAI,CAAC;EAC9B,OAAOD,KAAK,CAACV,GAAG,CAAEY,IAAI,IAAK,GAAGH,MAAM,GAAGG,IAAI,EAAE,CAAC,CAACR,IAAI,CAAC,IAAI,CAAC;AAC3D;AAEA,OAAO,SAASS,MAAMA,CAACL,IAAY,EAAU;EAC3C,OAAOA,IAAI,CAACF,OAAO,CAAC,4BAA4B,EAAE,MAAM,CAAC;AAC3D;AAEA,OAAO,SAASQ,YAAYA,CAACN,IAAY,EAAU;EACjD,IAAIO,GAAG,GAAG,CAAC;EACX,IAAIC,OAAO,GAAG,CAAC;EAEf,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGT,IAAI,CAACU,MAAM,EAAED,CAAC,EAAE,EAAE;IACpC,IAAIT,IAAI,CAACS,CAAC,CAAC,KAAK,GAAG,EAAE;MACnBD,OAAO,EAAE;MACTD,GAAG,GAAGI,IAAI,CAACJ,GAAG,CAACA,GAAG,EAAEC,OAAO,CAAC;IAC9B,CAAC,MAAM;MACLA,OAAO,GAAG,CAAC;IACb;EACF;EAEA,OAAOD,GAAG;AACZ","ignoreList":[]}
1
+ {"version":3,"file":"utils.mjs","names":["joinBlocks","blocks","map","trimBlock","filter","Boolean","join","block","replace","prefixLines","text","prefix","lines","split","line","escape","maxBackticks","max","current","char","Math"],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * Join blocks of text into a single markdown document (string).\n *\n * @param blocks - The blocks of text to join.\n * @returns Markdown document string.\n */\nexport function joinBlocks(blocks: string | readonly string[]): string {\n blocks = typeof blocks === 'string' ? [blocks] : blocks;\n\n return blocks.map(trimBlock).filter(Boolean).join('\\n\\n');\n}\n\nfunction trimBlock(block: string): string {\n return block.replace(/^\\n+|\\n+$/g, '');\n}\n\nexport function prefixLines(text: string, prefix: string): string {\n const lines = text.split('\\n');\n return lines.map((line) => `${prefix}${line}`).join('\\n');\n}\n\nexport function escape(text: string): string {\n return text.replace(/([\\\\`*_{}[\\]()#+\\-.!|<>])/g, '\\\\$1');\n}\n\nexport function maxBackticks(text: string): number {\n let max = 0;\n let current = 0;\n\n for (const char of text) {\n if (char === '`') {\n current++;\n max = Math.max(max, current);\n } else {\n current = 0;\n }\n }\n\n return max;\n}\n"],"mappings":"AAMA,OAAO,SAASA,UAAUA,CAACC,MAAkC,EAAU;EACrEA,MAAM,GAAG,OAAOA,MAAM,KAAK,QAAQ,GAAG,CAACA,MAAM,CAAC,GAAGA,MAAM;EAEvD,OAAOA,MAAM,CAACC,GAAG,CAACC,SAAS,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,MAAM,CAAC;AAC3D;AAEA,SAASH,SAASA,CAACI,KAAa,EAAU;EACxC,OAAOA,KAAK,CAACC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;AACxC;AAEA,OAAO,SAASC,WAAWA,CAACC,IAAY,EAAEC,MAAc,EAAU;EAChE,MAAMC,KAAK,GAAGF,IAAI,CAACG,KAAK,CAAC,IAAI,CAAC;EAC9B,OAAOD,KAAK,CAACV,GAAG,CAAEY,IAAI,IAAK,GAAGH,MAAM,GAAGG,IAAI,EAAE,CAAC,CAACR,IAAI,CAAC,IAAI,CAAC;AAC3D;AAEA,OAAO,SAASS,MAAMA,CAACL,IAAY,EAAU;EAC3C,OAAOA,IAAI,CAACF,OAAO,CAAC,4BAA4B,EAAE,MAAM,CAAC;AAC3D;AAEA,OAAO,SAASQ,YAAYA,CAACN,IAAY,EAAU;EACjD,IAAIO,GAAG,GAAG,CAAC;EACX,IAAIC,OAAO,GAAG,CAAC;EAEf,KAAK,MAAMC,IAAI,IAAIT,IAAI,EAAE;IACvB,IAAIS,IAAI,KAAK,GAAG,EAAE;MAChBD,OAAO,EAAE;MACTD,GAAG,GAAGG,IAAI,CAACH,GAAG,CAACA,GAAG,EAAEC,OAAO,CAAC;IAC9B,CAAC,MAAM;MACLA,OAAO,GAAG,CAAC;IACb;EACF;EAEA,OAAOD,GAAG;AACZ","ignoreList":[]}
@@ -27,6 +27,20 @@ export declare function heading(text: string, options?: HeadingOptions): string;
27
27
  * @param text - The content of the blockquote.
28
28
  */
29
29
  export declare function blockquote(content: string | readonly string[]): string;
30
+ export type AlertType = 'note' | 'tip' | 'important' | 'warning' | 'caution';
31
+ /**
32
+ * Create a GitHub alert (callout) block.
33
+ *
34
+ * Markdown:
35
+ * ```
36
+ * > [!NOTE]
37
+ * > Content
38
+ * ```
39
+ *
40
+ * @param type - The alert type: `note`, `tip`, `important`, `warning` or `caution`.
41
+ * @param content - The content of the alert.
42
+ */
43
+ export declare function alert(type: AlertType, content: string | readonly string[]): string;
30
44
  type CodeBlockOptions = {
31
45
  language?: string;
32
46
  };
@@ -66,4 +80,20 @@ export declare function list(items: readonly string[]): string;
66
80
  * @param items - The items of the list.
67
81
  */
68
82
  export declare function orderedList(items: readonly string[]): string;
83
+ export type TaskListItem = {
84
+ text: string;
85
+ done?: boolean;
86
+ };
87
+ /**
88
+ * Create a task list block.
89
+ *
90
+ * Markdown:
91
+ * ```
92
+ * - [x] Done item
93
+ * - [ ] Pending item
94
+ * ```
95
+ *
96
+ * @param items - The items of the task list.
97
+ */
98
+ export declare function taskList(items: readonly (string | TaskListItem)[]): string;
69
99
  export {};
@@ -1,7 +1,8 @@
1
- export { horizontalRule, heading, blockquote, orderedList, list, codeBlock } from './block';
2
- export { code, italic, bold, link, image } from './inline';
1
+ export { horizontalRule, heading, blockquote, alert, orderedList, list, codeBlock, taskList, } from './block';
2
+ export { code, italic, bold, strikethrough, link, image } from './inline';
3
3
  export { table } from './table';
4
4
  export { lineBreak, disclosure } from './html';
5
5
  export { escape, joinBlocks } from './utils';
6
6
  export type { TableOptions } from './table';
7
7
  export type { DisclosureOptions } from './html';
8
+ export type { AlertType, TaskListItem } from './block';
@@ -14,6 +14,14 @@ export declare function italic(text: string): string;
14
14
  * @param text - The text to be bolded.
15
15
  */
16
16
  export declare function bold(text: string): string;
17
+ /**
18
+ * Create a strikethrough text.
19
+ *
20
+ * Markdown: `~~text~~`
21
+ *
22
+ * @param text - The text to be struck through.
23
+ */
24
+ export declare function strikethrough(text: string): string;
17
25
  /**
18
26
  * Create a code text.
19
27
  *
@@ -23,14 +31,12 @@ export declare function bold(text: string): string;
23
31
  */
24
32
  export declare function code(text: string): string;
25
33
  /**
26
- * Create a link or autolink span.
34
+ * Create a link span.
27
35
  *
28
- * Markdown:
29
- * - `[text](url)` link when `text` is provided
30
- * - `<url>` autolink when `text` is not provided
36
+ * Markdown: `[text](url)`, or `[url](url)` when `text` is not provided.
31
37
  *
32
38
  * @param url - The URL to be linked.
33
- * @param text - The title for the link (optional).
39
+ * @param text - The title for the link (optional, defaults to `url`).
34
40
  */
35
41
  export declare function link(url: string, text?: string): string;
36
42
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ts-markdown-builder",
3
- "version": "0.5.0",
4
- "description": "Elegant markdown builder with minimal bundle size.",
3
+ "version": "0.7.0",
4
+ "description": "Elegant Markdown builder for TypeScript: zero dependencies, tree-shakable, under 1 kB.",
5
5
  "main": "dist/commonjs/index.js",
6
6
  "module": "dist/esm/index.mjs",
7
7
  "types": "dist/types/index.d.ts",
@@ -22,15 +22,18 @@
22
22
  "scripts": {
23
23
  "test": "jest",
24
24
  "typecheck": "tsc --noEmit",
25
- "lint": "eslint \"**/*.{js,ts,tsx}\"",
25
+ "lint": "oxlint",
26
26
  "clean": "del-cli dist",
27
- "build": "yarn clean && yarn build:commonjs && yarn build:esm && yarn build:types",
27
+ "build": "pnpm clean && pnpm build:commonjs && pnpm build:esm && pnpm build:types",
28
28
  "build:commonjs": "BABEL_ENV=cjs babel src --out-dir \"dist/commonjs\" --extensions .js,.ts --out-file-extension .js --source-maps --no-comments",
29
29
  "build:esm": "BABEL_ENV=esm babel src --out-dir \"dist/esm\" --extensions .js,.ts --out-file-extension .mjs --source-maps --no-comments",
30
30
  "build:types": "tsc --project tsconfig.release.json --outDir \"dist/types\"",
31
+ "format": "oxfmt",
32
+ "format:check": "oxfmt --check",
33
+ "validate": "pnpm typecheck && pnpm lint && pnpm test && pnpm format:check",
34
+ "validate:fix": "pnpm format && pnpm lint --fix && pnpm typecheck && pnpm test && pnpm build",
31
35
  "release": "release-it",
32
- "release:beta": "release-it --preRelease=beta",
33
- "validate": "yarn typecheck && yarn lint && yarn test"
36
+ "release:beta": "release-it --preRelease=beta"
34
37
  },
35
38
  "keywords": [
36
39
  "markdown",
@@ -47,36 +50,28 @@
47
50
  "registry": "https://registry.npmjs.org/"
48
51
  },
49
52
  "devDependencies": {
50
- "@babel/cli": "^7.28.3",
51
- "@babel/core": "^7.28.3",
52
- "@babel/plugin-syntax-flow": "^7.27.1",
53
- "@babel/plugin-transform-react-jsx": "^7.27.1",
54
- "@babel/preset-env": "^7.28.3",
55
- "@babel/preset-typescript": "^7.27.1",
56
- "@callstack/eslint-config": "^15.0.0",
57
- "@release-it/conventional-changelog": "^10.0.1",
58
- "@size-limit/preset-small-lib": "^11.2.0",
53
+ "@babel/cli": "^7.29.7",
54
+ "@babel/core": "^7.29.13",
55
+ "@babel/plugin-transform-modules-commonjs": "^7.29.14",
56
+ "@babel/preset-env": "^7.29.14",
57
+ "@babel/preset-typescript": "^7.29.7",
58
+ "@release-it/conventional-changelog": "^12.0.2",
59
+ "@size-limit/preset-small-lib": "^14.3.0",
59
60
  "@types/jest": "^30.0.0",
60
61
  "babel-plugin-add-import-extension": "^1.6.0",
61
- "del-cli": "^6.0.0",
62
- "eslint": "^8.57.1",
63
- "eslint-config-prettier": "^10.1.8",
64
- "eslint-plugin-flowtype": "^8.0.3",
65
- "eslint-plugin-import": "^2.32.0",
66
- "eslint-plugin-prettier": "^5.5.4",
67
- "jest": "^30.1.2",
68
- "prettier": "^3.6.2",
69
- "release-it": "^19.0.4",
70
- "typescript": "^5.9.2"
62
+ "del-cli": "^8.0.1",
63
+ "jest": "^30.5.2",
64
+ "oxfmt": "^0.78.0",
65
+ "oxlint": "^1.93.0",
66
+ "release-it": "^21.1.2",
67
+ "size-limit": "^14.3.0",
68
+ "typescript": "^5.9.3"
71
69
  },
72
- "packageManager": "yarn@4.9.4+sha512.7b1cb0b62abba6a537b3a2ce00811a843bea02bcf53138581a6ae5b1bf563f734872bd47de49ce32a9ca9dcaff995aa789577ffb16811da7c603dcf69e73750b",
70
+ "packageManager": "pnpm@12.18.0",
73
71
  "engines": {
74
72
  "node": ">= 18.0.0"
75
73
  },
76
74
  "jest": {
77
- "setupFilesAfterEnv": [
78
- "<rootDir>/jest-setup.ts"
79
- ],
80
75
  "collectCoverageFrom": [
81
76
  "src/**/*.{js,jsx,ts,tsx}"
82
77
  ],
@@ -87,11 +82,11 @@
87
82
  "release-it": {
88
83
  "hooks": {
89
84
  "before:init": [
90
- "yarn typecheck",
91
- "yarn test",
92
- "yarn lint"
85
+ "pnpm typecheck",
86
+ "pnpm test",
87
+ "pnpm lint"
93
88
  ],
94
- "after:bump": "yarn build",
89
+ "after:bump": "pnpm build",
95
90
  "after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
96
91
  },
97
92
  "git": {
@@ -135,49 +130,6 @@
135
130
  }
136
131
  }
137
132
  },
138
- "eslintConfig": {
139
- "root": true,
140
- "extends": [
141
- "@callstack/eslint-config/node",
142
- "prettier"
143
- ],
144
- "plugins": [
145
- "import"
146
- ],
147
- "rules": {
148
- "prettier/prettier": [
149
- "error",
150
- {
151
- "quoteProps": "consistent",
152
- "singleQuote": true,
153
- "tabWidth": 2,
154
- "trailingComma": "all",
155
- "useTabs": false
156
- }
157
- ],
158
- "sort-imports": [
159
- "error",
160
- {
161
- "ignoreCase": true,
162
- "ignoreDeclarationSort": true
163
- }
164
- ],
165
- "import/order": "error"
166
- }
167
- },
168
- "eslintIgnore": [
169
- "node_modules/",
170
- "dist/",
171
- "coverage/",
172
- "website/"
173
- ],
174
- "prettier": {
175
- "quoteProps": "consistent",
176
- "singleQuote": true,
177
- "tabWidth": 2,
178
- "trailingComma": "all",
179
- "useTabs": false
180
- },
181
133
  "size-limit": [
182
134
  {
183
135
  "path": "./dist/esm/index.mjs",