Socket
Book a DemoInstallSign in
Socket

htmlsave

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmlsave

HTML save string utilities

latest
Source
npmnpm
Version
3.0.0
Version published
Weekly downloads
2.2K
12.65%
Maintainers
1
Weekly downloads
 
Created
Source

htmlsave

NPM version Build Status BrowserStack Status Dependency Status Download Coverage Status

HTML save string utilities for JavaScript.

Features

  • Truncate HTML String while preserving HTML tags and whole words.
  • Split HTML String while preserving HTML tags and whole words.
  • It works with all the standard JavaScript loading systems out of the box (CommonJS, AMD, or just as a global)

Downloading htmlsave

If you're using node, you can run npm install htmlsave.

htmlsave is also available via Bower (bower install htmlsave)

Alternatively if you just want to grab the file yourself, you can download either the current stable production version or the development version directly.

Setting it up

htmlsave supports AMD (e.g. RequireJS), CommonJS (e.g. Node.js) and direct usage (e.g. loading globally with a <script> tag) loading methods. You should be able to do nearly anything, and then skip to the next section anyway and have it work. Just in case though, here's some specific examples that definitely do the right thing:

CommonsJS (e.g. Node)

var htmlsave = require('htmlsave');
htmlsave.truncate('<p>lorem ipsum html text</p>', 12, {
  breakword: false,
});

AMD (e.g. RequireJS)

define(['htmlsave'], function(htmlsave) {
  htmlsave.slice('<span>my extra long html text</span>', 10);
});

Directly in your web page:

<script src="htmlsave.min.js"></script>
<script>
  htmlsave.truncate('another too long text', 5);
</script>

API

  • htmlsave.truncate(input, maxlength,<options>) method.
  • htmlsave.slice(input, maxlength,<options>) method.

input

Required Type: string

maxlength

Required Type: int

Max characters allowed. Use 0 for slice to split by word.

options

breakword

Type: boolean Default value: true

Allow script to truncate words. Disable to only allow truncating on whitespace, block-level elements and void elements.

ellipsis

Type: String Default value: ....

End truncated string with ellipsis. This option has no effect on slice.

License

Copyright (c) 2016 Ben Zörb Licensed under the MIT license.

Keywords

javascript

FAQs

Package last updated on 09 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts