1.0.3 • Published 3 years ago

limit-characters v1.0.3

Weekly downloads
179
License
-
Repository
github
Last release
3 years ago

limit-characters

Limits the length of a given text with different options. Types included.

Install

npm

npm i limit-characters

Yarn

yarn add limit-characters

Usage

CommonJS

var limitCharacters = require("limit-characters")

ES6

import limitCharacters from "limit-characters"

Example

import limitCharacters from "limit-characters";

const originalText = "This library helps limit the characters of a given text"

const excerpt = limitCharacters({ text: originalText, length: 20 })
// Returns "This library help..."

const excerpt2 = limitCharacters({ text: originalText, length: 20, breakWord: false })
// Returns "This library..."

const excerpt3 = limitCharacters({ text: originalText, length: 32, breakWord: false, more: "... read more" })
// Returns "This library helps... read more"

Options

OptionTypeRequiredDefaultDescription
textstringRequiredOriginal text to trim
lengthnumberOptional144Max length of characters including ellipsis
breakWordbooleanOptionaltrueBreak the word or keep the whole word that fits the length
morestringOptional...Appended at the end of string if original text exceeded the length
1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago