Comparing version 2.0.1 to 3.0.0
@@ -24,6 +24,12 @@ var Exam; | ||
Exam.prototype.find = function(filters) { | ||
var filter, i, item, len, ref; | ||
Exam.prototype._find = function(callback) { | ||
this.found = []; | ||
this.unfound = []; | ||
callback(); | ||
this.undetect(); | ||
return this; | ||
}; | ||
Exam.prototype.find = function(filters) { | ||
var filter; | ||
this.filters = (function() { | ||
@@ -38,11 +44,43 @@ var i, len, results; | ||
})(); | ||
ref = this.filters; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
item = ref[i]; | ||
if (this.examObject.match(item)) { | ||
this.found.push(item); | ||
return this._find((function(_this) { | ||
return function() { | ||
var i, item, len, ref, results; | ||
ref = _this.filters; | ||
results = []; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
item = ref[i]; | ||
if (_this.examObject.match(item)) { | ||
results.push(_this.found.push(item)); | ||
} | ||
} | ||
return results; | ||
}; | ||
})(this)); | ||
}; | ||
Exam.prototype.strictFind = function(filters) { | ||
var filter; | ||
this.filters = (function() { | ||
var i, len, results; | ||
results = []; | ||
for (i = 0, len = filters.length; i < len; i++) { | ||
filter = filters[i]; | ||
results.push(filter.toLowerCase()); | ||
} | ||
} | ||
this.undetect(); | ||
return this; | ||
return results; | ||
})(); | ||
return this._find((function(_this) { | ||
return function() { | ||
var i, item, len, ref, results; | ||
ref = _this.filters; | ||
results = []; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
item = ref[i]; | ||
if (_this.examObject.match(new RegExp(item + "\\b", 'gi'))) { | ||
results.push(_this.found.push(item)); | ||
} | ||
} | ||
return results; | ||
}; | ||
})(this)); | ||
}; | ||
@@ -52,3 +90,7 @@ | ||
if (this.found.length > 0) { | ||
callback.bind(this)(); | ||
callback({ | ||
found: this.found, | ||
unfound: this.unfound, | ||
filters: this.filters | ||
}); | ||
} | ||
@@ -60,3 +102,7 @@ return this; | ||
if (this.unfound.length > 0) { | ||
callback.bind(this)(); | ||
callback({ | ||
found: this.found, | ||
unfound: this.unfound, | ||
filters: this.filters | ||
}); | ||
} | ||
@@ -67,3 +113,7 @@ return this; | ||
Exam.prototype.any = function(callback) { | ||
callback.bind(this)(); | ||
callback({ | ||
found: this.found, | ||
unfound: this.unfound, | ||
filters: this.filters | ||
}); | ||
return this; | ||
@@ -70,0 +120,0 @@ }; |
@@ -25,6 +25,12 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
Exam.prototype.find = function(filters) { | ||
var filter, i, item, len, ref; | ||
Exam.prototype._find = function(callback) { | ||
this.found = []; | ||
this.unfound = []; | ||
callback(); | ||
this.undetect(); | ||
return this; | ||
}; | ||
Exam.prototype.find = function(filters) { | ||
var filter; | ||
this.filters = (function() { | ||
@@ -39,11 +45,43 @@ var i, len, results; | ||
})(); | ||
ref = this.filters; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
item = ref[i]; | ||
if (this.examObject.match(item)) { | ||
this.found.push(item); | ||
return this._find((function(_this) { | ||
return function() { | ||
var i, item, len, ref, results; | ||
ref = _this.filters; | ||
results = []; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
item = ref[i]; | ||
if (_this.examObject.match(item)) { | ||
results.push(_this.found.push(item)); | ||
} | ||
} | ||
return results; | ||
}; | ||
})(this)); | ||
}; | ||
Exam.prototype.strictFind = function(filters) { | ||
var filter; | ||
this.filters = (function() { | ||
var i, len, results; | ||
results = []; | ||
for (i = 0, len = filters.length; i < len; i++) { | ||
filter = filters[i]; | ||
results.push(filter.toLowerCase()); | ||
} | ||
} | ||
this.undetect(); | ||
return this; | ||
return results; | ||
})(); | ||
return this._find((function(_this) { | ||
return function() { | ||
var i, item, len, ref, results; | ||
ref = _this.filters; | ||
results = []; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
item = ref[i]; | ||
if (_this.examObject.match(new RegExp(item + "\\b", 'gi'))) { | ||
results.push(_this.found.push(item)); | ||
} | ||
} | ||
return results; | ||
}; | ||
})(this)); | ||
}; | ||
@@ -53,3 +91,7 @@ | ||
if (this.found.length > 0) { | ||
callback.bind(this)(); | ||
callback({ | ||
found: this.found, | ||
unfound: this.unfound, | ||
filters: this.filters | ||
}); | ||
} | ||
@@ -61,3 +103,7 @@ return this; | ||
if (this.unfound.length > 0) { | ||
callback.bind(this)(); | ||
callback({ | ||
found: this.found, | ||
unfound: this.unfound, | ||
filters: this.filters | ||
}); | ||
} | ||
@@ -68,3 +114,7 @@ return this; | ||
Exam.prototype.any = function(callback) { | ||
callback.bind(this)(); | ||
callback({ | ||
found: this.found, | ||
unfound: this.unfound, | ||
filters: this.filters | ||
}); | ||
return this; | ||
@@ -71,0 +121,0 @@ }; |
{ | ||
"name": "examjs", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"description": "You can use this library for examing something for something", | ||
@@ -5,0 +5,0 @@ "main": "dist/module/index.js", |
@@ -15,6 +15,7 @@ # Exam.js | ||
- `.find()` Takes the array as argument. Can be reusable. | ||
- within `.yep()`, `.nope()` and `.any()` callbacks you can access (return arrays only) | ||
- `this.filters` return filters you set | ||
- `this.found` return found words | ||
- `this.unfound` return unfound words | ||
- `.strictFind()` is the same as `find()`, but checks everything with regexp | ||
- within `.yep()`, `.nope()` and `.any()` callbacks you will get entire 'result' object with | ||
- `filters` filters you set | ||
- `found` found words | ||
- `unfound` unfound words | ||
@@ -24,31 +25,39 @@ ### Simple use | ||
```js | ||
exam(document.body) | ||
.find(['badword1', 'badword2', 'badword3']) | ||
.yep( => { | ||
// Should use 'yep' only if something out there | ||
exam("Could you find my name here?") | ||
.find(["could"]) | ||
.yep( result => { | ||
// Should use 'yep' only if | ||
// you expect something to be here | ||
console.log(result.found) | ||
}) | ||
.nope( => { | ||
// Should use 'nope' if nothing out there | ||
.nope( result => { | ||
// Should use 'nope' only if | ||
// you expect something not to be here | ||
console.log(result.unfound) | ||
}) | ||
.any( => { | ||
// Should use 'any' if you want just get 'found', 'unfound' and 'filters' | ||
.any( result => { | ||
// Should use 'any' if | ||
// you don't know what to expect | ||
console.log(result) | ||
}) | ||
``` | ||
### Reuse `.find()` method | ||
### Reuse methods | ||
**NB!** Will examine by different filters twice and independently | ||
**NB!** Will examine by different filters twice and independently | ||
```js | ||
exam(document.body) | ||
.find(['badword1', 'badword2', 'badword3']) | ||
.any( => { | ||
exam("How about that, huh?") | ||
.find(["abou"]) | ||
.any( result => { | ||
// we can reuse filters we set | ||
console.log(this.filters) | ||
console.log(result.filters) | ||
// and be ready that these badwords we will find | ||
console.log(this.found) | ||
console.log(result.found) | ||
// also we have all results within any of the callback | ||
console.log(result.unfound) | ||
}) | ||
.find(['copyright']) | ||
.yep( => { | ||
// copyright is out there | ||
.strictFind(["about"]) | ||
.yep( result => { | ||
// word 'about' is fully out there | ||
console.log(this.found) | ||
@@ -55,0 +64,0 @@ }) |
Sorry, the diff of this file is not supported yet
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
13217
9
244
65
1
4