Giter VIP home page Giter VIP logo

truncatise's Introduction

Truncatise

JavaScript module to truncate HTML strings.

Description

Provides the ability to truncate HTML strings down to excerpts based on character length, word length or paragraph length.

Features:

  • Truncate based on number of Characters, Words or Paragraphs.
  • Strip HTML from returned string.
  • Provides a strict flag to specify whether to cut-off mid word or not.
  • Configurable suffix appended to the end of the returned excerpt.

Install

npm install truncatise

Options (with default values)

{
	TruncateBy 		: 'words',  // Options are 'words', 'characters' or 'paragraphs'
	TruncateLength	: 50,    	// The count to be used with TruncatedBy
    StripHTML		: false,    // Whether or not the truncated text should contain HTML tags
    ExemptTags  : undefined // Array of strings defining tags to exempt from HTML stripping
    Strict 			: true,     // If set to false the truncated text finish at the end of the word
    Suffix 			: '...'     // Text to be appended to the end of the truncated text
}

Example Usage

var options = {
		TruncateLength: 4, 
		TruncateBy : "words", 
		Strict : false, 
		StripHTML : true,
    ExemptTags : ["img"],
		Suffix : ' (Read More)'
	};
var excerpt = truncatise("<p>This is a test of Truncatise</p>", options);
console.log(excerpt); // This is a test (Read More)

truncatise's People

Contributors

averagemarcus avatar ntdb avatar

Watchers

Nick Cox avatar Wes  avatar James Cloos avatar Ivan Cruz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.