Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lettersanitizer

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lettersanitizer - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

4

lib/index.js

@@ -154,5 +154,7 @@ "use strict";

sanitizeCssStyle(element.style, allowedSchemas, preserveCssPriority, rewriteExternalResources);
// Add rel="noopener noreferrer" to <a>
if (tagName === 'a') {
// Add rel="noopener noreferrer" to <a>
element.setAttribute('rel', 'noopener noreferrer');
// Add target="_blank" to <a>
element.setAttribute('target', '_blank');
}

@@ -159,0 +161,0 @@ }

{
"name": "lettersanitizer",
"version": "1.0.0",
"version": "1.0.1",
"description": "DOM-based HTML email sanitizer for in-browser email rendering.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -31,17 +31,26 @@ <h1 align="center">lettersanitizer</h1>

```ts
export function sanitize(
html: string,
text?: string,
options?: SanitizerOptions
) {
let contents = html ?? '';
if (contents?.length === 0 && text) {
contents = sanitizeText(text)
.split('\n')
.map(line => '<p>' + line + '</p>')
.join('\n');
}
import { sanitize } from 'lettersanitizer';
return sanitizeHtml(contents, options ?? {});
sanitize('<b>test</b><script>test</script>', '', { id: 'test' });
// <div id="test"><b>test</b></div>
```
### sanitize function
**lettersanitizer** exposes a `sanitize` function that uses DOMParser to sanitize the HTML content of messages and returns HTML text.
`text` is used for fallback text in case of no HTML source being available. Plain text in that case is processed into safe HTML output.
```ts
interface SanitizerOptions {
id?: string;
dropAllHtmlTags?: boolean;
rewriteExternalResources?: (url: string) => string;
rewriteExternalLinks?: (url: string) => string;
allowedSchemas?: string[];
preserveCssPriority?: boolean;
noWrapper?: boolean;
}
function sanitize(html: string, text?: string, options?: SanitizerOptions);
```
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