Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

examjs

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

examjs - npm Package Compare versions

Comparing version 3.0.1 to 4.1.0

test/index.js

158

dist/module/Exam.js

@@ -1,119 +0,79 @@

var Exam;
var Exam, includes, isArray;
isArray = require('lodash.isarray');
includes = require('lodash.includes');
module.exports = Exam = (function() {
function Exam(examObject) {
if (typeof examObject === 'string') {
this.examObject = examObject.toLowerCase();
function Exam(examing) {
if (typeof examing === 'string') {
this.examing = examing.toLowerCase();
this.examingArr = this.examing.split(" ");
} else {
this.examObject = examObject.textContent.toLowerCase();
throw new Error("Examing target must be a String");
}
}
Exam.prototype.undetect = function() {
var filter, foundString, i, len, ref;
foundString = this.found.join('');
ref = this.filters;
for (i = 0, len = ref.length; i < len; i++) {
filter = ref[i];
if (!foundString.match(filter)) {
this.unfound.push(filter);
Exam.prototype.different = function(filter) {
if (this.softMode) {
if (this.examing.match(filter)) {
return false;
}
} else {
if (includes(this.examingArr, filter)) {
return false;
}
}
return true;
};
Exam.prototype._find = function(callback) {
this.found = [];
this.unfound = [];
callback();
this.undetect();
return this;
Exam.prototype.atLeast = function(filters, callback) {
return this.exact(filters, callback, true);
};
Exam.prototype.find = 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());
Exam.prototype.exact = function(filters, callback, softMode) {
var filter, i, len, ref;
this.found = [];
this.notfound = [];
this.softMode = softMode || false;
this.filters = isArray(filters) ? filters : [filters];
ref = this.filters;
for (i = 0, len = ref.length; i < len; i++) {
filter = ref[i];
if (!this.different(filter)) {
this.found.push(filter);
} else {
this.notfound.push(filter);
}
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(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());
}
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));
};
Exam.prototype.yep = function(callback) {
if (this.found.length > 0) {
callback({
found: this.found,
unfound: this.unfound,
filters: this.filters
});
}
return this;
};
Exam.prototype.nope = function(callback) {
if (this.unfound.length > 0) {
callback({
found: this.found,
unfound: this.unfound,
filters: this.filters
});
this.result = {
found: this.found.length > 0 ? this.found : null,
notfound: this.notfound.length > 0 ? this.notfound : null,
filters: this.filters,
examing: this.examing,
mode: softMode ? "soft" : "strict"
};
if (this.found.length > 0 && this.notfound.length === 0) {
this.result.only = {};
this.result.only.yep = true;
}
return this;
if (this.notfound.length > 0 && this.found.length === 0) {
this.result.only = {};
this.result.only.nope = true;
}
if (callback != null) {
callback(this.result);
return this;
}
if (typeof Promise !== "undefined" && Promise !== null) {
return new Promise((function(_this) {
return function(resolve, reject) {
return resolve(_this.result);
};
})(this));
}
};
Exam.prototype.any = function(callback) {
callback({
found: this.found,
unfound: this.unfound,
filters: this.filters
});
return this;
};
return Exam;
})();
(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){
var Exam;
/**
* lodash 4.1.2 (Custom Build) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/
var keys = require('lodash.keys');
module.exports = Exam = (function() {
function Exam(examObject) {
if (typeof examObject === 'string') {
this.examObject = examObject.toLowerCase();
} else {
this.examObject = examObject.textContent.toLowerCase();
/** Used as references for various `Number` constants. */
var INFINITY = 1 / 0,
MAX_SAFE_INTEGER = 9007199254740991,
MAX_INTEGER = 1.7976931348623157e+308,
NAN = 0 / 0;
/** `Object#toString` result references. */
var funcTag = '[object Function]',
genTag = '[object GeneratorFunction]',
stringTag = '[object String]',
symbolTag = '[object Symbol]';
/** Used to match leading and trailing whitespace. */
var reTrim = /^\s+|\s+$/g;
/** Used to detect bad signed hexadecimal string values. */
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
/** Used to detect binary string values. */
var reIsBinary = /^0b[01]+$/i;
/** Used to detect octal string values. */
var reIsOctal = /^0o[0-7]+$/i;
/** Built-in method references without a dependency on `root`. */
var freeParseInt = parseInt;
/**
* A specialized version of `_.map` for arrays without support for iteratee
* shorthands.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
*/
function arrayMap(array, iteratee) {
var index = -1,
length = array.length,
result = Array(length);
while (++index < length) {
result[index] = iteratee(array[index], index, array);
}
return result;
}
/**
* The base implementation of `_.indexOf` without `fromIndex` bounds checks.
*
* @private
* @param {Array} array The array to search.
* @param {*} value The value to search for.
* @param {number} fromIndex The index to search from.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function baseIndexOf(array, value, fromIndex) {
if (value !== value) {
return indexOfNaN(array, fromIndex);
}
var index = fromIndex - 1,
length = array.length;
while (++index < length) {
if (array[index] === value) {
return index;
}
}
return -1;
}
Exam.prototype.undetect = function() {
var filter, foundString, i, len, ref;
foundString = this.found.join('');
ref = this.filters;
for (i = 0, len = ref.length; i < len; i++) {
filter = ref[i];
if (!foundString.match(filter)) {
this.unfound.push(filter);
}
/**
* The base implementation of `_.values` and `_.valuesIn` which creates an
* array of `object` property values corresponding to the property names
* of `props`.
*
* @private
* @param {Object} object The object to query.
* @param {Array} props The property names to get values for.
* @returns {Object} Returns the array of property values.
*/
function baseValues(object, props) {
return arrayMap(props, function(key) {
return object[key];
});
}
/**
* Gets the index at which the first occurrence of `NaN` is found in `array`.
*
* @private
* @param {Array} array The array to search.
* @param {number} fromIndex The index to search from.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {number} Returns the index of the matched `NaN`, else `-1`.
*/
function indexOfNaN(array, fromIndex, fromRight) {
var length = array.length,
index = fromIndex + (fromRight ? 0 : -1);
while ((fromRight ? index-- : ++index < length)) {
var other = array[index];
if (other !== other) {
return index;
}
};
}
return -1;
}
Exam.prototype._find = function(callback) {
this.found = [];
this.unfound = [];
callback();
this.undetect();
return this;
/** Used for built-in method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/
var objectToString = objectProto.toString;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max;
/**
* The base implementation of `_.property` without support for deep paths.
*
* @private
* @param {string} key The key of the property to get.
* @returns {Function} Returns the new function.
*/
function baseProperty(key) {
return function(object) {
return object == null ? undefined : object[key];
};
}
Exam.prototype.find = 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());
}
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(item)) {
results.push(_this.found.push(item));
}
}
return results;
};
})(this));
/**
* Gets the "length" property value of `object`.
*
* **Note:** This function is used to avoid a
* [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
* Safari on at least iOS 8.1-8.3 ARM64.
*
* @private
* @param {Object} object The object to query.
* @returns {*} Returns the "length" value.
*/
var getLength = baseProperty('length');
/**
* Checks if `value` is in `collection`. If `collection` is a string it's
* checked for a substring of `value`, otherwise
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* is used for equality comparisons. If `fromIndex` is negative, it's used as
* the offset from the end of `collection`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Collection
* @param {Array|Object|string} collection The collection to search.
* @param {*} value The value to search for.
* @param {number} [fromIndex=0] The index to search from.
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
* @returns {boolean} Returns `true` if `value` is found, else `false`.
* @example
*
* _.includes([1, 2, 3], 1);
* // => true
*
* _.includes([1, 2, 3], 1, 2);
* // => false
*
* _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
* // => true
*
* _.includes('pebbles', 'eb');
* // => true
*/
function includes(collection, value, fromIndex, guard) {
collection = isArrayLike(collection) ? collection : values(collection);
fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
var length = collection.length;
if (fromIndex < 0) {
fromIndex = nativeMax(length + fromIndex, 0);
}
return isString(collection)
? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
: (!!length && baseIndexOf(collection, value, fromIndex) > -1);
}
/**
* Checks if `value` is classified as an `Array` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @type {Function}
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isArray([1, 2, 3]);
* // => true
*
* _.isArray(document.body.children);
* // => false
*
* _.isArray('abc');
* // => false
*
* _.isArray(_.noop);
* // => false
*/
var isArray = Array.isArray;
/**
* Checks if `value` is array-like. A value is considered array-like if it's
* not a function and has a `value.length` that's an integer greater than or
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
* @example
*
* _.isArrayLike([1, 2, 3]);
* // => true
*
* _.isArrayLike(document.body.children);
* // => true
*
* _.isArrayLike('abc');
* // => true
*
* _.isArrayLike(_.noop);
* // => false
*/
function isArrayLike(value) {
return value != null && isLength(getLength(value)) && !isFunction(value);
}
/**
* Checks if `value` is classified as a `Function` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isFunction(_);
* // => true
*
* _.isFunction(/abc/);
* // => false
*/
function isFunction(value) {
// The use of `Object#toString` avoids issues with the `typeof` operator
// in Safari 8 which returns 'object' for typed array and weak map constructors,
// and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
var tag = isObject(value) ? objectToString.call(value) : '';
return tag == funcTag || tag == genTag;
}
/**
* Checks if `value` is a valid array-like length.
*
* **Note:** This function is loosely based on
* [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length,
* else `false`.
* @example
*
* _.isLength(3);
* // => true
*
* _.isLength(Number.MIN_VALUE);
* // => false
*
* _.isLength(Infinity);
* // => false
*
* _.isLength('3');
* // => false
*/
function isLength(value) {
return typeof value == 'number' &&
value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
}
/**
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(_.noop);
* // => true
*
* _.isObject(null);
* // => false
*/
function isObject(value) {
var type = typeof value;
return !!value && (type == 'object' || type == 'function');
}
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return !!value && typeof value == 'object';
}
/**
* Checks if `value` is classified as a `String` primitive or object.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isString('abc');
* // => true
*
* _.isString(1);
* // => false
*/
function isString(value) {
return typeof value == 'string' ||
(!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
}
/**
* Checks if `value` is classified as a `Symbol` primitive or object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isSymbol(Symbol.iterator);
* // => true
*
* _.isSymbol('abc');
* // => false
*/
function isSymbol(value) {
return typeof value == 'symbol' ||
(isObjectLike(value) && objectToString.call(value) == symbolTag);
}
/**
* Converts `value` to an integer.
*
* **Note:** This function is loosely based on
* [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to convert.
* @returns {number} Returns the converted integer.
* @example
*
* _.toInteger(3);
* // => 3
*
* _.toInteger(Number.MIN_VALUE);
* // => 0
*
* _.toInteger(Infinity);
* // => 1.7976931348623157e+308
*
* _.toInteger('3');
* // => 3
*/
function toInteger(value) {
if (!value) {
return value === 0 ? value : 0;
}
value = toNumber(value);
if (value === INFINITY || value === -INFINITY) {
var sign = (value < 0 ? -1 : 1);
return sign * MAX_INTEGER;
}
var remainder = value % 1;
return value === value ? (remainder ? value - remainder : value) : 0;
}
/**
* Converts `value` to a number.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to process.
* @returns {number} Returns the number.
* @example
*
* _.toNumber(3);
* // => 3
*
* _.toNumber(Number.MIN_VALUE);
* // => 5e-324
*
* _.toNumber(Infinity);
* // => Infinity
*
* _.toNumber('3');
* // => 3
*/
function toNumber(value) {
if (typeof value == 'number') {
return value;
}
if (isSymbol(value)) {
return NAN;
}
if (isObject(value)) {
var other = isFunction(value.valueOf) ? value.valueOf() : value;
value = isObject(other) ? (other + '') : other;
}
if (typeof value != 'string') {
return value === 0 ? value : +value;
}
value = value.replace(reTrim, '');
var isBinary = reIsBinary.test(value);
return (isBinary || reIsOctal.test(value))
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
: (reIsBadHex.test(value) ? NAN : +value);
}
/**
* Creates an array of the own enumerable string keyed property values of `object`.
*
* **Note:** Non-object values are coerced to objects.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property values.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.values(new Foo);
* // => [1, 2] (iteration order is not guaranteed)
*
* _.values('hi');
* // => ['h', 'i']
*/
function values(object) {
return object ? baseValues(object, keys(object)) : [];
}
module.exports = includes;
},{"lodash.keys":2}],2:[function(require,module,exports){
/**
* lodash 4.0.6 (Custom Build) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/
/** Used as references for various `Number` constants. */
var MAX_SAFE_INTEGER = 9007199254740991;
/** `Object#toString` result references. */
var argsTag = '[object Arguments]',
funcTag = '[object Function]',
genTag = '[object GeneratorFunction]',
stringTag = '[object String]';
/** Used to detect unsigned integer values. */
var reIsUint = /^(?:0|[1-9]\d*)$/;
/**
* The base implementation of `_.times` without support for iteratee shorthands
* or max array length checks.
*
* @private
* @param {number} n The number of times to invoke `iteratee`.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the array of results.
*/
function baseTimes(n, iteratee) {
var index = -1,
result = Array(n);
while (++index < n) {
result[index] = iteratee(index);
}
return result;
}
/**
* Checks if `value` is a valid array-like index.
*
* @private
* @param {*} value The value to check.
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
*/
function isIndex(value, length) {
value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
length = length == null ? MAX_SAFE_INTEGER : length;
return value > -1 && value % 1 == 0 && value < length;
}
/** Used for built-in method references. */
var objectProto = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/**
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/
var objectToString = objectProto.toString;
/** Built-in value references. */
var propertyIsEnumerable = objectProto.propertyIsEnumerable;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeGetPrototype = Object.getPrototypeOf,
nativeKeys = Object.keys;
/**
* The base implementation of `_.has` without support for deep paths.
*
* @private
* @param {Object} object The object to query.
* @param {Array|string} key The key to check.
* @returns {boolean} Returns `true` if `key` exists, else `false`.
*/
function baseHas(object, key) {
// Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
// that are composed entirely of index properties, return `false` for
// `hasOwnProperty` checks of them.
return hasOwnProperty.call(object, key) ||
(typeof object == 'object' && key in object && getPrototype(object) === null);
}
/**
* The base implementation of `_.keys` which doesn't skip the constructor
* property of prototypes or treat sparse arrays as dense.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function baseKeys(object) {
return nativeKeys(Object(object));
}
/**
* The base implementation of `_.property` without support for deep paths.
*
* @private
* @param {string} key The key of the property to get.
* @returns {Function} Returns the new function.
*/
function baseProperty(key) {
return function(object) {
return object == null ? undefined : object[key];
};
}
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());
/**
* Gets the "length" property value of `object`.
*
* **Note:** This function is used to avoid a
* [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
* Safari on at least iOS 8.1-8.3 ARM64.
*
* @private
* @param {Object} object The object to query.
* @returns {*} Returns the "length" value.
*/
var getLength = baseProperty('length');
/**
* Gets the `[[Prototype]]` of `value`.
*
* @private
* @param {*} value The value to query.
* @returns {null|Object} Returns the `[[Prototype]]`.
*/
function getPrototype(value) {
return nativeGetPrototype(Object(value));
}
/**
* Creates an array of index keys for `object` values of arrays,
* `arguments` objects, and strings, otherwise `null` is returned.
*
* @private
* @param {Object} object The object to query.
* @returns {Array|null} Returns index keys, else `null`.
*/
function indexKeys(object) {
var length = object ? object.length : undefined;
if (isLength(length) &&
(isArray(object) || isString(object) || isArguments(object))) {
return baseTimes(length, String);
}
return null;
}
/**
* Checks if `value` is likely a prototype object.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
*/
function isPrototype(value) {
var Ctor = value && value.constructor,
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
return value === proto;
}
/**
* Checks if `value` is likely an `arguments` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isArguments(function() { return arguments; }());
* // => true
*
* _.isArguments([1, 2, 3]);
* // => false
*/
function isArguments(value) {
// Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
(!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
}
/**
* Checks if `value` is classified as an `Array` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @type {Function}
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isArray([1, 2, 3]);
* // => true
*
* _.isArray(document.body.children);
* // => false
*
* _.isArray('abc');
* // => false
*
* _.isArray(_.noop);
* // => false
*/
var isArray = Array.isArray;
/**
* Checks if `value` is array-like. A value is considered array-like if it's
* not a function and has a `value.length` that's an integer greater than or
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
* @example
*
* _.isArrayLike([1, 2, 3]);
* // => true
*
* _.isArrayLike(document.body.children);
* // => true
*
* _.isArrayLike('abc');
* // => true
*
* _.isArrayLike(_.noop);
* // => false
*/
function isArrayLike(value) {
return value != null && isLength(getLength(value)) && !isFunction(value);
}
/**
* This method is like `_.isArrayLike` except that it also checks if `value`
* is an object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an array-like object,
* else `false`.
* @example
*
* _.isArrayLikeObject([1, 2, 3]);
* // => true
*
* _.isArrayLikeObject(document.body.children);
* // => true
*
* _.isArrayLikeObject('abc');
* // => false
*
* _.isArrayLikeObject(_.noop);
* // => false
*/
function isArrayLikeObject(value) {
return isObjectLike(value) && isArrayLike(value);
}
/**
* Checks if `value` is classified as a `Function` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isFunction(_);
* // => true
*
* _.isFunction(/abc/);
* // => false
*/
function isFunction(value) {
// The use of `Object#toString` avoids issues with the `typeof` operator
// in Safari 8 which returns 'object' for typed array and weak map constructors,
// and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
var tag = isObject(value) ? objectToString.call(value) : '';
return tag == funcTag || tag == genTag;
}
/**
* Checks if `value` is a valid array-like length.
*
* **Note:** This function is loosely based on
* [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length,
* else `false`.
* @example
*
* _.isLength(3);
* // => true
*
* _.isLength(Number.MIN_VALUE);
* // => false
*
* _.isLength(Infinity);
* // => false
*
* _.isLength('3');
* // => false
*/
function isLength(value) {
return typeof value == 'number' &&
value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
}
/**
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(_.noop);
* // => true
*
* _.isObject(null);
* // => false
*/
function isObject(value) {
var type = typeof value;
return !!value && (type == 'object' || type == 'function');
}
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return !!value && typeof value == 'object';
}
/**
* Checks if `value` is classified as a `String` primitive or object.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
* @example
*
* _.isString('abc');
* // => true
*
* _.isString(1);
* // => false
*/
function isString(value) {
return typeof value == 'string' ||
(!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
}
/**
* Creates an array of the own enumerable property names of `object`.
*
* **Note:** Non-object values are coerced to objects. See the
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
* for more details.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.keys(new Foo);
* // => ['a', 'b'] (iteration order is not guaranteed)
*
* _.keys('hi');
* // => ['0', '1']
*/
function keys(object) {
var isProto = isPrototype(object);
if (!(isProto || isArrayLike(object))) {
return baseKeys(object);
}
var indexes = indexKeys(object),
skipIndexes = !!indexes,
result = indexes || [],
length = result.length;
for (var key in object) {
if (baseHas(object, key) &&
!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
!(isProto && key == 'constructor')) {
result.push(key);
}
}
return result;
}
module.exports = keys;
},{}],3:[function(require,module,exports){
/**
* lodash 4.0.0 (Custom Build) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <https://lodash.com/license>
*/
/**
* Checks if `value` is classified as an `Array` object.
*
* @static
* @memberOf _
* @type Function
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isArray([1, 2, 3]);
* // => true
*
* _.isArray(document.body.children);
* // => false
*
* _.isArray('abc');
* // => false
*
* _.isArray(_.noop);
* // => false
*/
var isArray = Array.isArray;
module.exports = isArray;
},{}],4:[function(require,module,exports){
var Exam, includes, isArray;
isArray = require('lodash.isarray');
includes = require('lodash.includes');
module.exports = Exam = (function() {
function Exam(examing) {
if (typeof examing === 'string') {
this.examing = examing.toLowerCase();
this.examingArr = this.examing.split(" ");
} else {
throw new Error("Examing target must be a String");
}
}
Exam.prototype.different = function(filter) {
if (this.softMode) {
if (this.examing.match(filter)) {
return false;
}
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));
} else {
if (includes(this.examingArr, filter)) {
return false;
}
}
return true;
};
Exam.prototype.yep = function(callback) {
if (this.found.length > 0) {
callback({
found: this.found,
unfound: this.unfound,
filters: this.filters
});
}
return this;
Exam.prototype.atLeast = function(filters, callback) {
return this.exact(filters, callback, true);
};
Exam.prototype.nope = function(callback) {
if (this.unfound.length > 0) {
callback({
found: this.found,
unfound: this.unfound,
filters: this.filters
});
Exam.prototype.exact = function(filters, callback, softMode) {
var filter, i, len, ref;
this.found = [];
this.notfound = [];
this.softMode = softMode || false;
this.filters = isArray(filters) ? filters : [filters];
ref = this.filters;
for (i = 0, len = ref.length; i < len; i++) {
filter = ref[i];
if (!this.different(filter)) {
this.found.push(filter);
} else {
this.notfound.push(filter);
}
}
return this;
this.result = {
found: this.found.length > 0 ? this.found : null,
notfound: this.notfound.length > 0 ? this.notfound : null,
filters: this.filters,
examing: this.examing,
mode: softMode ? "soft" : "strict"
};
if (this.found.length > 0 && this.notfound.length === 0) {
this.result.only = {};
this.result.only.yep = true;
}
if (this.notfound.length > 0 && this.found.length === 0) {
this.result.only = {};
this.result.only.nope = true;
}
if (callback != null) {
callback(this.result);
return this;
}
if (typeof Promise !== "undefined" && Promise !== null) {
return new Promise((function(_this) {
return function(resolve, reject) {
return resolve(_this.result);
};
})(this));
}
};
Exam.prototype.any = function(callback) {
callback({
found: this.found,
unfound: this.unfound,
filters: this.filters
});
return this;
};
return Exam;

@@ -122,3 +1119,3 @@

},{}],2:[function(require,module,exports){
},{"lodash.includes":1,"lodash.isarray":3}],5:[function(require,module,exports){
var Exam, main;

@@ -140,2 +1137,2 @@

},{"./Exam":1}]},{},[2]);
},{"./Exam":4}]},{},[5]);

@@ -1,1 +0,1 @@

!function t(n,r,e){function o(i,f){if(!r[i]){if(!n[i]){var s="function"==typeof require&&require;if(!f&&s)return s(i,!0);if(u)return u(i,!0);var h=new Error("Cannot find module '"+i+"'");throw h.code="MODULE_NOT_FOUND",h}var d=r[i]={exports:{}};n[i][0].call(d.exports,function(t){var r=n[i][1][t];return o(r?r:t)},d,d.exports,t,n,r,e)}return r[i].exports}for(var u="function"==typeof require&&require,i=0;i<e.length;i++)o(e[i]);return o}({1:[function(t,n,r){var e;n.exports=e=function(){function t(t){"string"==typeof t?this.examObject=t.toLowerCase():this.examObject=t.textContent.toLowerCase()}return t.prototype.undetect=function(){var t,n,r,e,o;for(n=this.found.join(""),o=this.filters,r=0,e=o.length;e>r;r++)t=o[r],n.match(t)||this.unfound.push(t)},t.prototype._find=function(t){return this.found=[],this.unfound=[],t(),this.undetect(),this},t.prototype.find=function(t){var n;return this.filters=function(){var r,e,o;for(o=[],r=0,e=t.length;e>r;r++)n=t[r],o.push(n.toLowerCase());return o}(),this._find(function(t){return function(){var n,r,e,o,u;for(o=t.filters,u=[],n=0,e=o.length;e>n;n++)r=o[n],t.examObject.match(r)&&u.push(t.found.push(r));return u}}(this))},t.prototype.strictFind=function(t){var n;return this.filters=function(){var r,e,o;for(o=[],r=0,e=t.length;e>r;r++)n=t[r],o.push(n.toLowerCase());return o}(),this._find(function(t){return function(){var n,r,e,o,u;for(o=t.filters,u=[],n=0,e=o.length;e>n;n++)r=o[n],t.examObject.match(new RegExp(r+"\\b","gi"))&&u.push(t.found.push(r));return u}}(this))},t.prototype.yep=function(t){return this.found.length>0&&t({found:this.found,unfound:this.unfound,filters:this.filters}),this},t.prototype.nope=function(t){return this.unfound.length>0&&t({found:this.found,unfound:this.unfound,filters:this.filters}),this},t.prototype.any=function(t){return t({found:this.found,unfound:this.unfound,filters:this.filters}),this},t}()},{}],2:[function(t,n,r){var e,o;return e=t("./Exam"),o=function(t){return new e(t)},"undefined"!=typeof n&&null!==n?n.exports=o:"undefined"!=typeof window&&null!==window?window.exam=o:void 0},{"./Exam":1}]},{},[2]);
!function t(n,r,e){function o(i,f){if(!r[i]){if(!n[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var s=new Error("Cannot find module '"+i+"'");throw s.code="MODULE_NOT_FOUND",s}var l=r[i]={exports:{}};n[i][0].call(l.exports,function(t){var r=n[i][1][t];return o(r?r:t)},l,l.exports,t,n,r,e)}return r[i].exports}for(var u="function"==typeof require&&require,i=0;i<e.length;i++)o(e[i]);return o}({1:[function(t,n,r){function e(t,n){for(var r=-1,e=t.length,o=Array(e);++r<e;)o[r]=n(t[r],r,t);return o}function o(t,n,r){if(n!==n)return i(t,r);for(var e=r-1,o=t.length;++e<o;)if(t[e]===n)return e;return-1}function u(t,n){return e(n,function(n){return t[n]})}function i(t,n,r){for(var e=t.length,o=n+(r?0:-1);r?o--:++o<e;){var u=t[o];if(u!==u)return o}return-1}function f(t){return function(n){return null==n?void 0:n[t]}}function c(t,n,r,e){t=s(t)?t:b(t),r=r&&!e?g(r):0;var u=t.length;return 0>r&&(r=C(u+r,0)),y(t)?u>=r&&t.indexOf(n,r)>-1:!!u&&o(t,n,r)>-1}function s(t){return null!=t&&a(D(t))&&!l(t)}function l(t){var n=h(t)?L.call(t):"";return n==A||n==E}function a(t){return"number"==typeof t&&t>-1&&t%1==0&&j>=t}function h(t){var n=typeof t;return!!t&&("object"==n||"function"==n)}function p(t){return!!t&&"object"==typeof t}function y(t){return"string"==typeof t||!G(t)&&p(t)&&L.call(t)==S}function d(t){return"symbol"==typeof t||p(t)&&L.call(t)==F}function g(t){if(!t)return 0===t?t:0;if(t=v(t),t===x||t===-x){var n=0>t?-1:1;return n*w}var r=t%1;return t===t?r?t-r:t:0}function v(t){if("number"==typeof t)return t;if(d(t))return O;if(h(t)){var n=l(t.valueOf)?t.valueOf():t;t=h(n)?n+"":n}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(P,"");var r=q.test(t);return r||M.test(t)?N(t.slice(2),r?2:8):$.test(t)?O:+t}function b(t){return t?u(t,m(t)):[]}var m=t("lodash.keys"),x=1/0,j=9007199254740991,w=1.7976931348623157e308,O=NaN,A="[object Function]",E="[object GeneratorFunction]",S="[object String]",F="[object Symbol]",P=/^\s+|\s+$/g,$=/^[-+]0x[0-9a-f]+$/i,q=/^0b[01]+$/i,M=/^0o[0-7]+$/i,N=parseInt,k=Object.prototype,L=k.toString,C=Math.max,D=f("length"),G=Array.isArray;n.exports=c},{"lodash.keys":2}],2:[function(t,n,r){function e(t,n){for(var r=-1,e=Array(t);++r<t;)e[r]=n(r);return e}function o(t,n){return t="number"==typeof t||E.test(t)?+t:-1,n=null==n?x:n,t>-1&&t%1==0&&n>t}function u(t,n){return F.call(t,n)||"object"==typeof t&&n in t&&null===c(t)}function i(t){return M(Object(t))}function f(t){return function(n){return null==n?void 0:n[t]}}function c(t){return q(Object(t))}function s(t){var n=t?t.length:void 0;return d(n)&&(k(t)||b(t)||a(t))?e(n,String):null}function l(t){var n=t&&t.constructor,r="function"==typeof n&&n.prototype||S;return t===r}function a(t){return p(t)&&F.call(t,"callee")&&(!$.call(t,"callee")||P.call(t)==j)}function h(t){return null!=t&&d(N(t))&&!y(t)}function p(t){return v(t)&&h(t)}function y(t){var n=g(t)?P.call(t):"";return n==w||n==O}function d(t){return"number"==typeof t&&t>-1&&t%1==0&&x>=t}function g(t){var n=typeof t;return!!t&&("object"==n||"function"==n)}function v(t){return!!t&&"object"==typeof t}function b(t){return"string"==typeof t||!k(t)&&v(t)&&P.call(t)==A}function m(t){var n=l(t);if(!n&&!h(t))return i(t);var r=s(t),e=!!r,f=r||[],c=f.length;for(var a in t)!u(t,a)||e&&("length"==a||o(a,c))||n&&"constructor"==a||f.push(a);return f}var x=9007199254740991,j="[object Arguments]",w="[object Function]",O="[object GeneratorFunction]",A="[object String]",E=/^(?:0|[1-9]\d*)$/,S=Object.prototype,F=S.hasOwnProperty,P=S.toString,$=S.propertyIsEnumerable,q=Object.getPrototypeOf,M=Object.keys,N=f("length"),k=Array.isArray;n.exports=m},{}],3:[function(t,n,r){var e=Array.isArray;n.exports=e},{}],4:[function(t,n,r){var e,o,u;u=t("lodash.isarray"),o=t("lodash.includes"),n.exports=e=function(){function t(t){if("string"!=typeof t)throw new Error("Examing target must be a String");this.examing=t.toLowerCase(),this.examingArr=this.examing.split(" ")}return t.prototype.different=function(t){if(this.softMode){if(this.examing.match(t))return!1}else if(o(this.examingArr,t))return!1;return!0},t.prototype.atLeast=function(t,n){return this.exact(t,n,!0)},t.prototype.exact=function(t,n,r){var e,o,i,f;for(this.found=[],this.notfound=[],this.softMode=r||!1,this.filters=u(t)?t:[t],f=this.filters,o=0,i=f.length;i>o;o++)e=f[o],this.different(e)?this.notfound.push(e):this.found.push(e);return this.result={found:this.found.length>0?this.found:null,notfound:this.notfound.length>0?this.notfound:null,filters:this.filters,examing:this.examing,mode:r?"soft":"strict"},this.found.length>0&&0===this.notfound.length&&(this.result.only={},this.result.only.yep=!0),this.notfound.length>0&&0===this.found.length&&(this.result.only={},this.result.only.nope=!0),null!=n?(n(this.result),this):"undefined"!=typeof Promise&&null!==Promise?new Promise(function(t){return function(n,r){return n(t.result)}}(this)):void 0},t}()},{"lodash.includes":1,"lodash.isarray":3}],5:[function(t,n,r){var e,o;return e=t("./Exam"),o=function(t){return new e(t)},"undefined"!=typeof n&&null!==n?n.exports=o:"undefined"!=typeof window&&null!==window?window.exam=o:void 0},{"./Exam":4}]},{},[5]);
{
"name": "examjs",
"version": "3.0.1",
"version": "4.1.0",
"description": "You can use this library for examing something for something",

@@ -32,3 +32,7 @@ "main": "dist/module/index.js",

"gulp-watch": "^4.3.4"
},
"dependencies": {
"lodash.includes": "^4.1.2",
"lodash.isarray": "^4.0.0"
}
}

@@ -5,2 +5,12 @@ # Exam.js

### Installation & Usage
```
npm install --save examjs
```
```js
let exam = require("examjs")
```
### Compatibility

@@ -11,57 +21,51 @@

### API
Method | Description | Params | Code
--- | --- | --- | ---
`exam` | inital method | String | `exam("You want to check this string?")`
`exact` | find for exact, letter to letter matches | Array [, callback] | `exam("Some string in there").exact(["some", "in", "no"])`
`atLeast` | find for at least some matches | Array [, callback] | `exam("Some string in there").atLeast(["some", "in", "no"])`
### Notes
- Entirely case insensitive for all arguments and results
- `exam()` Can take string or node element (object). Will examine all content within that element if it's node element.
- `.find()` Takes the array as argument. Can be reusable.
- `.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
- `exact` and `atLeast` functions returns `Promise` if you didn't specify the `callback` as a second argument
- all results are case insensitive
### Simple use
### Simple usage
```js
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( result => {
// Should use 'nope' only if
// you expect something not to be here
console.log(result.unfound)
})
.any( result => {
// Should use 'any' if
// you don't know what to expect
exam("In our village, folks say God crumbles up the old moon into stars. Перевод недоступен.")
.atLeast(["our", "moon", "vill", "перев"], result => {
console.log(result)
/* -->
{
found: [ 'our', 'moon', 'vill', 'перев' ],
notfound: null,
filters: [ 'our', 'moon', 'vill', 'перев' ],
examing: 'in our village, folks say god crumbles up the old moon into stars. перевод недоступен.',
mode: 'soft',
only: { yep: true }
}
*/
})
```
### Reuse methods
**NB!** Will examine by different filters twice and independently
```js
exam("How about that, huh?")
.find(["abou"])
.any( result => {
// we can reuse filters we set
console.log(result.filters)
// and be ready that these badwords we will find
console.log(result.found)
// also we have all results within any of the callback
console.log(result.unfound)
exam("In our village, folks say God crumbles up the old moon into stars. Перевод недоступен.")
.exact(["our", "перевод", "vill", "перев"])
.then( result => {
console.log(result)
/* -->
{
found: [ 'our', 'перевод' ],
notfound: [ 'vill', 'перев' ],
filters: [ 'our', 'перевод', 'vill', 'перев' ],
examing: 'in our village, folks say god crumbles up the old moon into stars. перевод недоступен.',
mode: 'strict'
}
*/
})
.strictFind(["about"])
.yep( result => {
// word 'about' is fully out there
console.log(result.found)
})
```
Enjoy!
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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