email-scramble
Advanced tools
Comparing version 2.0.1 to 3.0.0
107
index.js
@@ -1,66 +0,51 @@ | ||
(function wrapEmailScramble(root, factory) { | ||
'use strict'; | ||
if (typeof define === 'function' && define.amd) { | ||
define('email-scramble', factory(root)); | ||
} else if (typeof exports === 'object') { | ||
module.exports = factory(root); | ||
} else { | ||
root.emailScramble = factory(root); | ||
} | ||
}(this, function emailScramble(root) { | ||
'use strict'; | ||
// Largely taken from https://github.com/mathiasbynens/rot. | ||
const rot = (charRot, numRot, str) => { | ||
var numbers = "0123456789"; | ||
var lowercase = "abcdefghijklmnopqrstuvwxyz"; | ||
var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
var regexNumber = /[0-9]/; | ||
var regexLowercase = /[a-z]/; | ||
var regexUppercase = /[A-Z]/; | ||
// Largely taken from https://github.com/mathiasbynens/rot. | ||
var rot = function rot(charRot, numRot, str) { | ||
var numbers = '0123456789'; | ||
var lowercase = 'abcdefghijklmnopqrstuvwxyz'; | ||
var uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
var regexNumber = /[0-9]/; | ||
var regexLowercase = /[a-z]/; | ||
var regexUppercase = /[A-Z]/; | ||
str = String(str); | ||
str = String(str); | ||
if (charRot < 0) { | ||
charRot += 26; | ||
if (charRot < 0) { | ||
charRot += 26; | ||
} | ||
if (numRot < 0) { | ||
numRot += 10; | ||
} | ||
var length = str.length; // note: no need to account for astral symbols | ||
var index = -1; | ||
var result = ""; | ||
var character; | ||
var currentPosition; | ||
var shiftedPosition; | ||
while (++index < length) { | ||
character = str.charAt(index); | ||
if (regexNumber.test(character)) { | ||
currentPosition = numbers.indexOf(character); | ||
shiftedPosition = (currentPosition + numRot) % 10; | ||
result += numbers.charAt(shiftedPosition); | ||
} else if (regexLowercase.test(character)) { | ||
currentPosition = lowercase.indexOf(character); | ||
shiftedPosition = (currentPosition + charRot) % 26; | ||
result += lowercase.charAt(shiftedPosition); | ||
} else if (regexUppercase.test(character)) { | ||
currentPosition = uppercase.indexOf(character); | ||
shiftedPosition = (currentPosition + charRot) % 26; | ||
result += uppercase.charAt(shiftedPosition); | ||
} else { | ||
result += character; | ||
} | ||
if (numRot < 0) { | ||
numRot += 10; | ||
} | ||
var length = str.length; // note: no need to account for astral symbols | ||
var index = -1; | ||
var result = ''; | ||
var character; | ||
var currentPosition; | ||
var shiftedPosition; | ||
while (++index < length) { | ||
character = str.charAt(index); | ||
if (regexNumber.test(character)) { | ||
currentPosition = numbers.indexOf(character); | ||
shiftedPosition = (currentPosition + numRot) % 10; | ||
result += numbers.charAt(shiftedPosition); | ||
} else if (regexLowercase.test(character)) { | ||
currentPosition = lowercase.indexOf(character); | ||
shiftedPosition = (currentPosition + charRot) % 26; | ||
result += lowercase.charAt(shiftedPosition); | ||
} else if (regexUppercase.test(character)) { | ||
currentPosition = uppercase.indexOf(character); | ||
shiftedPosition = (currentPosition + charRot) % 26; | ||
result += uppercase.charAt(shiftedPosition); | ||
} else { | ||
result += character; | ||
} | ||
} | ||
return result; | ||
}; | ||
} | ||
return result; | ||
}; | ||
var rot18 = function rot18(str) { | ||
return rot(13, 5, str); | ||
}; | ||
const rot18 = (str) => rot(13, 5, str); | ||
return { | ||
rot: rot, | ||
encode: rot18, | ||
decode: rot18 | ||
}; | ||
})); | ||
module.exports = { | ||
rot, | ||
encode: rot18, | ||
decode: rot18, | ||
}; |
{ | ||
"name": "email-scramble", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"main": "index.js", | ||
"files": [ | ||
"index.js" | ||
], | ||
"description": "Scrambles email addresses and phone numbers with ROT-18 to hide them from bots", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "istanbul cover _mocha -- -R spec", | ||
"linter:js": "jshint", | ||
"lint:js": "npm run linter:js -s -- index.js test/*.js", | ||
"lint": "npm run lint:js -s", | ||
"codeclimate": "CODECLIMATE_REPO_TOKEN=dcfbb93321d8ba7c68bc53c7e230a48e1d6aa6d3891f6a06c5d034b0261c2dfb codeclimate < coverage/lcov.info" | ||
}, | ||
"license": "ISC", | ||
"author": "thibaudcolas", | ||
"homepage": "https://github.com/thibaudcolas/email-scramble", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/ThibWeb/email-scramble" | ||
"url": "git://github.com/thibaudcolas/email-scramble" | ||
}, | ||
"keywords": [ | ||
"email", | ||
"mail", | ||
"address", | ||
"phone", | ||
"telephone", | ||
"cellphone", | ||
"tel", | ||
"scramble", | ||
"obfuscate", | ||
"obfuscation", | ||
"hide", | ||
"hidden", | ||
"mumble", | ||
"cloack", | ||
"rot", | ||
"rot18" | ||
], | ||
"author": "ThibWeb", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/ThibWeb/email-scramble/issues" | ||
"devDependencies": { | ||
"jest": "29.6.4" | ||
}, | ||
"homepage": "https://github.com/ThibWeb/email-scramble", | ||
"devDependencies": { | ||
"chai": "^3.2.0", | ||
"codeclimate-test-reporter": "^0.3.1", | ||
"istanbul": "^0.4.3", | ||
"jshint": "^2.5.11", | ||
"mocha": "^3.0.0" | ||
"scripts": { | ||
"test": "jest" | ||
} | ||
} |
@@ -1,17 +0,13 @@ | ||
email-scramble | ||
============== | ||
# [email-scramble](https://www.npmjs.com/package/email-scramble) | ||
> Universal JavaScript helper to encode/decode email addresses and phone numbers with ROT-18 to hide them from bots. This library can be used server-side with Node or on the front-end (CommonJS, AMD, global variable). | ||
> Encode/decode email addresses and phone numbers with ROT-18 to hide them from bots. Can be used server-side with Node.js or in a browser. | ||
[![npm](https://img.shields.io/npm/v/email-scramble.svg?style=flat-square)](https://www.npmjs.com/package/email-scramble) [![Build Status](https://img.shields.io/travis/ThibWeb/email-scramble.svg?style=flat-square)](https://travis-ci.org/ThibWeb/email-scramble) [![devDependency Status](https://img.shields.io/david/dev/ThibWeb/email-scramble.svg?style=flat-square)](https://david-dm.org/ThibWeb/email-scramble#info=devDependencies) [![Code Climate](https://img.shields.io/codeclimate/github/ThibWeb/email-scramble.svg?style=flat-square)](https://codeclimate.com/github/ThibWeb/email-scramble) [![Test Coverage](https://img.shields.io/codeclimate/coverage/github/ThibWeb/email-scramble.svg?style=flat-square)](https://codeclimate.com/github/ThibWeb/email-scramble) | ||
> If you'd like to know more about obfuscation techniques and their success ratio, [here is a great blog post on the subject](http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/). | ||
> Have a look at [the examples](https://rawgit.com/ThibWeb/email-scramble/master/examples/index.html). | ||
> If you'd like to know more about obfuscation techniques and their success ratio, [here's a great blog post on the subject](http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/). | ||
## Getting Started | ||
email-scramble uses a simple ROT transformation. The default rotation is ROT-18, which means that letters will be rotated by 13 and numbers by 5. | ||
`email-scramble` uses a simple [ROT](https://en.wikipedia.org/wiki/ROT13) transformation. The default rotation is ROT-18: letters will be rotated by 13 and numbers by 5. | ||
```js | ||
var encodedEmail = emailScramble.encode('mail@example.com'); | ||
var encodedEmail = emailScramble.encode("mail@example.com"); | ||
var decodedMail = emailScramble.decode(encodedMail); | ||
@@ -29,7 +25,7 @@ | ||
Here's a real-world example: | ||
Here is a real-world example: | ||
```js | ||
// <a href="znvygb:znvy@rknzcyr.pbz" data-email-scramble>Send me an email!</a> | ||
var links = document.querySelectorAll('[data-email-scramble]'); | ||
var links = document.querySelectorAll("[data-email-scramble]"); | ||
@@ -43,52 +39,12 @@ links.forEach(function decodeLink(link) { | ||
`email-scramble` is available on [npm](https://www.npmjs.com/package/email-scramble), or you can [download a ZIP](https://github.com/ThibWeb/email-scramble/releases) | ||
``` | ||
```sh | ||
npm install --save email-scramble | ||
``` | ||
This library can be used as an ES6 module, Node/Browserify CommonJS-like module, a RequireJS AMD module or a global: | ||
```js | ||
// ES6 | ||
import emailScramble from 'email-scramble'; | ||
// ES6+ | ||
import emailScramble from "email-scramble"; | ||
// The CommonJS way. | ||
var emailScramble = require('email-scramble'); | ||
// Global variable. | ||
var emailScramble = window.emailScramble; | ||
var emailScramble = require("email-scramble"); | ||
``` | ||
## Contributing | ||
```bash | ||
# Install deps | ||
npm install | ||
# Test | ||
npm test | ||
npm run lint | ||
# Install git hooks | ||
./.githooks/deploy | ||
``` | ||
## Built with | ||
- https://github.com/mathiasbynens/rot | ||
- https://github.com/umdjs/umd | ||
## LICENSE (ISC) | ||
Copyright (c) 2016, Thibaud Colas | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1
0
4232
4
47
1
49