New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

trunc-html

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trunc-html - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

21

index.js

@@ -17,2 +17,3 @@ 'use strict';

var ignoreTags = (o.ignoreTags || []).reduce(intoHashMap, Object.create(null));
var altBuffer = '';
var plain = '';

@@ -23,4 +24,6 @@ var insaneDefaults = {

};
var html = insane(input, assign(o.sanitizer || {}, insaneDefaults));
return { html: html, text: plain };
var sanitizer = o.sanitizer || {};
var opts = assign({}, sanitizer, insaneDefaults);
var html = insane(input, opts);
return { html: html, text: plain + altBuffer };
function filter (token) {

@@ -30,3 +33,12 @@ if (token.tag in ignoreTags) {

}
return remainder > 0;
if (remainder <= 0) {
return false;
}
if (sanitizer.filter && !sanitizer.filter(token)) {
return false;
}
if (o.imageAltText && token.tag === 'img') {
altBuffer += token.attrs.alt;
}
return true;
}

@@ -43,3 +55,4 @@ function transformText (text) {

}
plain += truncated;
plain += altBuffer + truncated;
altBuffer = '';
return truncated;

@@ -46,0 +59,0 @@ }

2

package.json
{
"name": "trunc-html",
"description": "truncate html by text length",
"version": "1.0.2",
"version": "1.1.0",
"homepage": "https://github.com/bevacqua/trunc-html",

@@ -6,0 +6,0 @@ "author": {

@@ -39,7 +39,11 @@ # trunc-html

If you'd like to supress certain HTML tags from being output you can provide an array of tags to be excluded, e.g `['img']`.
If you'd like to supress certain HTML tags from being output you can provide an array of tags to be excluded, set `ignoreTags` to something like `['strong']`.
## `options.imageAltText`
If you'd like to use the `alt` attribute for the text portion of the result, instead of dropping images entirely in text flavor, set `imageAltText` to `true`.
## `options.sanitizer`
Options passed to [`insane`][1]. Note that these options are overridden by the options provided by `trunc-html`, so you can't use `filter` and `transformText`, which `trunc-html` reserves for itself.
Options passed to [`insane`][1]. Note that these options are overridden by the options provided by `trunc-html`, so you can't use `transformText`, which `trunc-html` reserves for itself.

@@ -46,0 +50,0 @@ # related

@@ -25,1 +25,13 @@ var test = require('ava');

});
test(t => {
t.same(trunc('some sort of tada <img class="tj-emoji" alt="&#x1F389;" src="https://twemoji.maxcdn.com/2/72x72/1f389.png"/>', 30, { imageAltText: true }), {
html: 'some sort of tada <img alt="&#x1F389;" src="https://twemoji.maxcdn.com/2/72x72/1f389.png"/>',
text: 'some sort of tada 🎉'
});
t.same(trunc('some <img class="tj-emoji" alt="&#x1F389;" src="https://twemoji.maxcdn.com/2/72x72/1f389.png"/> sort of tada <img class="tj-emoji" alt="&#x1F389;" src="https://twemoji.maxcdn.com/2/72x72/1f389.png"/>', 30, { imageAltText: true }), {
html: 'some <img alt="&#x1F389;" src="https://twemoji.maxcdn.com/2/72x72/1f389.png"/> sort of tada <img alt="&#x1F389;" src="https://twemoji.maxcdn.com/2/72x72/1f389.png"/>',
text: 'some 🎉 sort of tada 🎉'
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc