posthtml-obfuscate
Advanced tools
Comparing version 0.1.0 to 0.1.1
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:sam@smith.com"> | ||
sam@smith.com | ||
</a> | ||
``` | ||
### Options | ||
- includeMailto: Boolean - Includes the `mailto:` prefix in the obfuscation. (Default: false) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3766
58
44