Skip to content

Commit 3994cc2

Browse files
committed
feat: add dual CommonJS, ESM, and Deno support
1 parent 390ed3a commit 3994cc2

15 files changed

Lines changed: 3136 additions & 224 deletions

.github/workflows/default.yaml

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,91 @@ name: Run tests
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
811

912
jobs:
10-
build:
13+
node:
14+
name: Node ${{ matrix.node-version }}
1115
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
node-version: [18.x, 20.x, 22.x, 24.x, 26.x]
20+
21+
steps:
22+
- uses: actions/checkout@v7
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v7
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
cache: npm
28+
- run: npm ci
29+
- run: npm test
30+
- run: npm run test:modules
31+
- run: npm run test:package
32+
33+
types:
34+
name: TypeScript package contract
35+
runs-on: ubuntu-latest
36+
37+
steps:
38+
- uses: actions/checkout@v7
39+
- uses: actions/setup-node@v7
40+
with:
41+
node-version: 24.x
42+
cache: npm
43+
- run: npm ci
44+
- run: npm run test:types
1245

46+
compatibility:
47+
name: Published-package compatibility
48+
runs-on: ubuntu-latest
49+
50+
steps:
51+
- uses: actions/checkout@v7
52+
- uses: actions/setup-node@v7
53+
with:
54+
node-version: 24.x
55+
cache: npm
56+
- run: npm ci
57+
- run: npm run test:differential
58+
- run: npm run test:bundlers
59+
60+
package-platform:
61+
name: Package smoke (${{ matrix.os }})
62+
runs-on: ${{ matrix.os }}
1363
strategy:
64+
fail-fast: false
1465
matrix:
15-
node-version: [18.x, 20.x, 22.x]
16-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
66+
os: [ubuntu-latest, macos-latest, windows-latest]
67+
68+
steps:
69+
- uses: actions/checkout@v7
70+
- uses: actions/setup-node@v7
71+
with:
72+
node-version: 24.x
73+
cache: npm
74+
- run: npm ci
75+
- run: npm run test:package
76+
77+
deno:
78+
name: Deno 2.x
79+
runs-on: ubuntu-latest
1780

1881
steps:
19-
- uses: actions/checkout@v3
20-
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v3
22-
with:
23-
node-version: ${{ matrix.node-version }}
24-
cache: 'npm'
25-
- run: npm ci
26-
- run: npm run build --if-present
27-
- run: npm test
82+
- uses: actions/checkout@v7
83+
- uses: actions/setup-node@v7
84+
with:
85+
node-version: 24.x
86+
cache: npm
87+
- uses: denoland/setup-deno@v2
88+
with:
89+
deno-version: v2.x
90+
- run: npm ci
91+
- run: npm run test:deno
92+
- run: npm run test:deno:package

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.7.0] - Unreleased
6+
7+
### Added
8+
9+
- Added a native ES module entry point while preserving the existing CommonJS API.
10+
- Added Deno 2.x support through the npm package.
11+
- Added module-specific TypeScript declarations and package-level compatibility tests.
12+
13+
### Changed
14+
15+
- Added conditional package exports for CommonJS, ES modules, and their matching type declarations.
16+
17+
ESM and Deno support was originally proposed in [#116](https://github.com/zuchka/remove-markdown/pull/116) by [@tukkek](https://github.com/tukkek).
18+
519
## [0.6.3] - 2026-01-14
620

721
### Added

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,48 @@
33
[![GitHub Actions Build Status](https://github.com/zuchka/remove-markdown/actions/workflows/default.yaml/badge.svg)](https://github.com/zuchka/remove-markdown/actions/workflows/default.yaml)
44

55
## What is it?
6-
**remove-markdown** is a node.js module that will remove (strip) Markdown formatting from text.
6+
**remove-markdown** is a JavaScript module that removes (strips) Markdown formatting from text. It supports CommonJS and ES modules in Node.js, plus Deno through npm compatibility.
77
*Markdown formatting* means pretty much anything that doesn’t look like regular text, like square brackets, asterisks etc.
88

99
## When do I need it?
1010
The typical use case is to display an excerpt from some Markdown text, without any of the actual Markdown syntax - for example in a list of posts.
1111

1212
## Installation
1313

14-
```
14+
```sh
1515
npm install remove-markdown
1616
```
1717

1818
## Usage
19+
20+
### CommonJS
21+
1922
```js
2023
const removeMd = require('remove-markdown');
2124
const markdown = '# This is a heading\n\nThis is a paragraph with [a link](http://www.disney.com/) in it.';
2225
const plainText = removeMd(markdown); // plainText is now 'This is a heading\n\nThis is a paragraph with a link in it.'
2326
```
2427

28+
### Node.js ES modules
29+
30+
```js
31+
import removeMd from 'remove-markdown';
32+
33+
const markdown = '# This is a heading\n\nThis is a paragraph with [a link](http://www.disney.com/) in it.';
34+
const plainText = removeMd(markdown);
35+
```
36+
37+
### Deno
38+
39+
```js
40+
import removeMd from 'npm:remove-markdown@^0.7.0';
41+
42+
const markdown = '# This is a heading\n\nThis is a paragraph with [a link](http://www.disney.com/) in it.';
43+
const plainText = removeMd(markdown);
44+
```
45+
46+
Deno support is provided through the npm package; there is no separate JSR package. The package exposes one callable default export in every runtime. Named exports and direct imports from raw GitHub URLs are not supported.
47+
2548
You can also supply an options object to the function. Currently, the following options are supported:
2649

2750
```js

index.d.mts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
declare function removeMd(md: string, options?: {
2+
stripListLeaders?: boolean;
3+
listUnicodeChar?: string;
4+
gfm?: boolean;
5+
useImgAltText?: boolean;
6+
abbr?: boolean;
7+
replaceLinksWithURL?: boolean;
8+
separateLinksAndTexts?: string;
9+
htmlTagsToSkip?: string[];
10+
throwError?: boolean;
11+
}): string;
12+
13+
export default removeMd;

index.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import removeMarkdown from './index.js';
2+
3+
export default removeMarkdown;

0 commit comments

Comments
 (0)