{"id":15138,"library":"md-utils-ts","title":"Markdown Utilities for TypeScript","description":"`md-utils-ts` is a lightweight, TypeScript-first utility library designed for programmatic generation of common Markdown syntax elements. Currently at version 2.0.0, it provides a focused collection of functions to create bold text, italics, strikethroughs, underlines, anchor links, code blocks (inline and multi-line), equations, and headings (H1-H6). The library emphasizes simplicity and type safety, offering both individual named exports for each utility (e.g., `bold`, `h1`) and a bundled `md` object for convenience (e.g., `md.italic`). Unlike comprehensive Markdown parsers or renderers, `md-utils-ts` strictly focuses on outputting valid Markdown strings, making it ideal for scenarios where you need to construct Markdown content dynamically without heavy dependencies. Its release cadence is likely stable, with updates driven by new Markdown syntax needs or minor enhancements.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/TomPenguin/md-utils-ts","tags":["javascript","markdown","utils","typescript"],"install":[{"cmd":"npm install md-utils-ts","lang":"bash","label":"npm"},{"cmd":"yarn add md-utils-ts","lang":"bash","label":"yarn"},{"cmd":"pnpm add md-utils-ts","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"md-utils-ts is an ESM-first, TypeScript library. Named exports like `bold` are individual utility functions.","wrong":"const bold = require('md-utils-ts').bold","symbol":"bold","correct":"import { bold } from 'md-utils-ts'"},{"note":"The `md` object is the default export and contains all utility functions as properties (e.g., `md.italic()`).","wrong":"import { md } from 'md-utils-ts'","symbol":"md","correct":"import md from 'md-utils-ts'"},{"note":"Functions like `codeBlock` are available as direct named exports for granular import control.","wrong":"import codeBlock from 'md-utils-ts'","symbol":"codeBlock","correct":"import { codeBlock } from 'md-utils-ts'"}],"quickstart":{"code":"import md, { bold, h1, anchor, codeBlock, equationBlock } from \"md-utils-ts\";\n\n// Create a main heading\nconst title = h1(\"Welcome to md-utils-ts!\");\n\n// Bold and italic text using individual exports and the 'md' object\nconst importantText = bold(\"This text is important.\") + \" \" + md.italic(\"And this is emphasized.\");\n\n// Create an anchor link\nconst githubLink = anchor(\"md-utils-ts GitHub\", \"https://github.com/TomPenguin/md-utils-ts\");\n\n// Generate a TypeScript code block\nconst tsExample = codeBlock(\"typescript\")(`\nfunction greet(name: string): string {\n  return \\`Hello, \\${name}!\\`;\n}\nconsole.log(greet(\"World\"));\n`);\n\n// Create an equation block\nconst pythagoreanTheorem = equationBlock(\"a^2 + b^2 = c^2\");\n\nconsole.log(title);\nconsole.log(importantText);\nconsole.log(githubLink);\nconsole.log(\"\\n--- TypeScript Example ---\\n\" + tsExample);\nconsole.log(\"\\n--- Math Example ---\\n\" + pythagoreanTheorem);\n","lang":"typescript","description":"Demonstrates importing both the default `md` object and named utility functions to create various Markdown elements like headings, bold text, links, code blocks, and equations."},"warnings":[{"fix":"For generating Markdown tables, integrate a dedicated library such as `markdown-table` from the `@wooorm` ecosystem, as `md-utils-ts` focuses on simpler, atomic Markdown elements.","message":"md-utils-ts explicitly states that it does not support Markdown table generation directly. Attempting to create complex tables will require manual string formatting or integration with another library.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"For parsing or rendering Markdown, integrate with a dedicated Markdown parser/renderer library (e.g., `marked`, `remark`, `markdown-it`). `md-utils-ts`'s role is limited to constructing the Markdown string itself.","message":"This library is strictly for *generating* Markdown strings. It does not provide functionality for *parsing* existing Markdown content or *rendering* Markdown into HTML or other formats.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"When using `code(inline)` or `equation(inline)`, remember to call it twice: first with the `inline` boolean, then with the content. For convenience, use `inlineCode`, `codeBlock`, `inlineEquation`, or `equationBlock` which are pre-configured versions.","message":"The `code` and `equation` functions are higher-order functions that require an initial boolean argument (`inline`) to determine output format, returning another function that takes the `language`/`text`.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure named exports are correctly destructured: `import { bold } from 'md-utils-ts';`. If using CommonJS (not recommended for this ESM-first library), access named exports as properties: `const { bold } = require('md-utils-ts');`.","cause":"Attempting to use a named export (e.g., `bold`) directly from a default import, or incorrect CommonJS `require` syntax.","error":"TypeError: (0 , md_utils_ts__WEBPACK_IMPORTED_MODULE_0__.bold) is not a function"},{"fix":"Import the default export correctly: `import md from 'md-utils-ts';`.","cause":"Attempting to import `md` as a named export when it is the default export of the package.","error":"TS2305: Module '\"md-utils-ts\"' has no exported member 'md'."},{"fix":"Run `npm install md-utils-ts` or `yarn add md-utils-ts` to install the package. Double-check the spelling of the import path.","cause":"The package `md-utils-ts` is not installed in the project's `node_modules` directory or the package name is misspelled in the import statement.","error":"Module not found: Error: Can't resolve 'md-utils-ts'"},{"fix":"If you are using the `md` default import, access its properties correctly, e.g., `md.bold(\"text\")`. If you prefer direct named imports, use `import { bold } from 'md-utils-ts'` and then `bold(\"text\")`.","cause":"Attempting to call a utility function (e.g., `bold`) directly as a property of the `md` default import when it's also available as a named export, leading to confusion or incorrect binding.","error":"TypeError: md.bold is not a function"}],"ecosystem":"npm"}