Skip to content

Commit

Permalink
Merge pull request #3 from mileszim/es6
Browse files Browse the repository at this point in the history
ES6 + Tests
  • Loading branch information
mileszim committed Jul 24, 2015
2 parents 015a7c2 + df80eaa commit 693929d
Show file tree
Hide file tree
Showing 10 changed files with 991 additions and 471 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
test.js
test.js
node_modules
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: node_js
node_js:
- "0.12"
- "0.11"
- "iojs"
before_install: npm install -g grunt-cli
install: npm install
before_script: grunt build
notifications:
email: false
sudo: false
40 changes: 40 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = function(grunt) {

// Configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

// ES5 Compatibility
babel: {
options: {
comments: false,
optional: ['runtime']
},
dist: {
files: {
'dist/webpurify.js': 'src/webpurify.js'
}
}
},

// Tests
mochaTest: {
test: {
options: {
reporter: 'spec',
},
src: ['test/**/*.js']
}
}
});

// Load plugins
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-mocha-test');

// Tasks
grunt.registerTask('test', ['mochaTest']);
grunt.registerTask('build', ['babel']);
grunt.registerTask('default', ['build', 'test']);

};
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
The MIT License (MIT)

Webpurify NPM Module Copyright (c) 2015 Miles Zimmerman
WebPurify Copyright (c) 2015 WebFurther, LLC.

Shakespeare Programming Language Copyright (c) 2001 Kalle Hasselström, Jon Åslund

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
55 changes: 34 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ To initialize:
var WebPurify = require('webpurify');

var wp = new WebPurify({
api_key: 'my_api_key'
api_key: ENV['WEBPURIFY_API_KEY']
//, endpoint: 'us' // Optional, available choices: 'eu', 'ap'. Default: 'us'.
//, enterprise: false // Optional, set to true if you are using the enterprise API, allows SSL
});
Expand All @@ -48,8 +48,9 @@ Commands
Check a string of text for profanity. Returns true if profanity found, false if none.

```js
wp.check('some profane text', function(err, profanity) {
if (profanity===true) {
wp.check('some profane text')
.then(profanity) {
if (profanity) {
console.log('A bunch of sailors in here!');
} else {
console.log('This is a pure string');
Expand All @@ -63,7 +64,8 @@ wp.check('some profane text', function(err, profanity) {
Check a string of text for profanity. Returns number of words if profanity found, 0 if none.

```js
wp.checkCount('some profane text', function(err, profanity) {
wp.checkCount('some profane text')
.then(function(profanity) {
if (profanity > 0) {
console.log(profanity.toString() + ' sailors in here!');
} else {
Expand All @@ -77,7 +79,8 @@ wp.checkCount('some profane text', function(err, profanity) {
Check a string of text for profanity. Replaces any found profanity with a provided symbol, and returns the formatted string.

```js
wp.replace('some profane text', '*', function(err, purified_text) {
wp.replace('some profane text', '*')
.then(function(purified_text) {
console.log(purified_text);
});
```
Expand All @@ -87,7 +90,8 @@ wp.replace('some profane text', '*', function(err, purified_text) {
Check a string of text for profanity. If any found, returns an array of profane words. Else, returns empty array.

```js
wp.return('some profane text', function(err, profanity) {
wp.return('some profane text')
.then(function(profanity) {
for (word in profanity) {
console.log(profanity[word]);
}
Expand All @@ -106,7 +110,8 @@ var optional = {
slink: 1 // treat urls like profanity
};

wp.check('some profane text', optional, function(error, profanity) {
wp.check('some profane text', optional)
.then(function(profanity) {
console.log(profanity);
});
```
Expand All @@ -116,8 +121,9 @@ wp.check('some profane text', optional, function(error, profanity) {
Add a word to the blacklist.

```js
wp.addToBlacklist('my_word', function(err, success) {
if (success===true) console.log('success!');
wp.addToBlacklist('my_word')
.then(function(success) {
if (success) console.log('success!');
});
```

Expand All @@ -126,7 +132,7 @@ Can also be called without callback:
```js
wp.addToBlacklist('my_word');
```

For Deep search, add optional parameter 1 after word:

```js
Expand All @@ -139,11 +145,12 @@ wp.addToBlacklist('my_word', 1);
Remove a word from the blacklist.

```js
wp.removeFromBlacklist('my_word', function(err, success) {
if (success===true) console.log('success!');
wp.removeFromBlacklist('my_word')
.then(function(success) {
if (success) console.log('success!');
});
```

Can also be called without callback:

```js
Expand All @@ -155,7 +162,8 @@ wp.removeFromBlacklist('my_word');
Get the blacklist as an array of words.

```js
wp.getBlacklist(function(err, blacklist) {
wp.getBlacklist()
.then(function(blacklist) {
for (word in blacklist) {
console.log(blacklist[word]);
}
Expand All @@ -168,8 +176,9 @@ wp.getBlacklist(function(err, blacklist) {
Add a word to the whitelist.

```js
wp.addToWhitelist('my_word', function(err, success) {
if (success===true) console.log('success!');
wp.addToWhitelist('my_word')
.then(function(success) {
if (success) console.log('success!');
});
```

Expand All @@ -185,11 +194,12 @@ wp.addToWhitelist('my_word');
Remove a word from the whitelist.

```js
wp.removeFromWhitelist('my_word', function(err, success) {
if (success===true) console.log('success!');
wp.removeFromWhitelist('my_word')
.then(function(success) {
if (success) console.log('success!');
});
```

Can also be called without callback:

```js
Expand All @@ -201,7 +211,8 @@ wp.removeFromWhitelist('my_word');
Get the whitelist as an array of words.

```js
wp.getWhitelist(function(err, whitelist) {
wp.getWhitelist()
.then(function(whitelist) {
for (word in whitelist) {
console.log(whitelist[word]);
}
Expand All @@ -211,5 +222,7 @@ wp.getWhitelist(function(err, whitelist) {

Status
------
v1.0.0

So far it mimics the WebPurify API as closely as possible. If you find bugs or want to contribute, please do, that would be amazing.
- The WebPurify module is now written in ES6, using babel + babel-runtim to convert into ES5.
- Now uses promises
Loading

0 comments on commit 693929d

Please sign in to comment.