1.1.0 • Published 1 year ago

markdown-truncate v1.1.0

Weekly downloads
19
License
ISC
Repository
github
Last release
1 year ago

Markdown Truncate

npm version

A zero-dependency, vanilla JavaScript utility to truncate markdown text.

It's like substring but with superpowers, since it respects your input text's markdown emphasis markers.

Check the demo

Installation

npm install markdown-truncate

or

yarn add markdown-truncate

Usage

Import the truncate function from markdown-truncate; this is its signature:

function truncateMarkdown (inputText: string, options: object)

Options

These are the option flags you can provide to markdown-truncate:

FlagDescriptionDefault valueRequired
limitThe max number of characters the output string should have-Yes
ellipsisSpecifies whether to append ellipsis ... to the truncated textfalseNo

Example

import truncateMarkdown from 'markdown-truncate'

truncateMarkdown('markdown *is* __properly__ truncated', {
  limit: 15,
  ellipsis: true
}) // returns 'markdown *is* __pro__...'

Demo

Check out the live demo here.

1.1.0

1 year ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago