Socket
Socket
Sign inDemoInstall

posthtml-obfuscate

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthtml-obfuscate - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

__tests__/index.spec.js

37

lib/index.js
function obfuscate(data) {
// TODO: Don;t charCodeAt for the first 2 characters, and then random 3,5 single chars.
return data.split('').map((v) => {

@@ -7,18 +8,26 @@ return `&#${v.charCodeAt(0)};`;

module.exports = () => {
module.exports = (config) => {
config = (function (cnf, def) {
if (cnf != void 0) {
for (prop in cnf) {
if (cnf.hasOwnProperty(prop) && def[prop] != void 0) {
def[prop] = cnf[prop];
}
}
}
return def;
})(config, {
includeMailto: false
});
return (tree) => {
tree.match({tag: 'a'}, node => {
if (/^mailto:/.test(node.attrs.href)) {
let ob = ((email) => {
return {
get href() {
return obfuscate(`mailto:${email}`)
},
get content() {
return obfuscate(email);
}
}
})(node.attrs.href.replace(/^mailto:/, ''));
[node.attrs.href, node.content] = [ob.href, ob.content];
[node.attrs.href, node.content] = (email => {
return [
config.includeMailto ? obfuscate(`mailto:${email}`) : `mailto:${obfuscate(email)}`,
obfuscate(email)
];
})(node.attrs.href.replace(/^mailto:/, ''))
}

@@ -29,2 +38,2 @@

}
}
}
{
"name": "posthtml-obfuscate",
"version": "0.1.0",
"version": "0.1.1",
"description": "PostHTML plugin that'll obfuscate emails etc...",
"main": "dist/index.js",
"scripts": {
"test": "jest ./test/index.spec.js --coverage"
"test": "jest --coverage"
},

@@ -9,0 +9,0 @@ "repository": {

@@ -1,4 +0,43 @@

PostHTML
=======
# PostHTML
> wip - please check back soon.
[![NPM version](https://img.shields.io/npm/v/posthtml-obfuscate.svg?style=flat-square)](https://www.npmjs.com/package/posthtml-obfuscate)
Obfuscates emails to make it harder for bots to recognize emails.
### Install
```sh
npm i posthtml-obfuscate -D
```
## Usage
```js
const posthtml = require('posthtml');
const phObfuscate= require('posthtml-obfuscate');
const options = {
includeMailto: false
};
posthtml([phObfuscate(options)])
.process(myHtml)
.then(result => {
console.log(result.html); // The output
});
```
### Output
```html
<!-- Before -->
<a href="mailto:sam@smith.com">
sam@smith.com
</a>
<!-- After -->
<a href="mailto:&#115;&#97;&#109;&#64;&#115;&#109;&#105;&#116;&#104;&#46;&#99;&#111;&#109;">
&#115;&#97;&#109;&#64;&#115;&#109;&#105;&#116;&#104;&#46;&#99;&#111;&#109;
</a>
```
### Options
- includeMailto: Boolean - Includes the `mailto:` prefix in the obfuscation. (Default: false)
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