Skip to content

Commit

Permalink
Merge 4f13cd6 into 26dcecf
Browse files Browse the repository at this point in the history
  • Loading branch information
DarrenPaulWright committed Feb 3, 2019
2 parents 26dcecf + 4f13cd6 commit af07164
Show file tree
Hide file tree
Showing 94 changed files with 802 additions and 723 deletions.
3 changes: 1 addition & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ module.exports = function(api) {
]
];
const plugins = [
'lodash',
['istanbul', {"exclude": ["tests/**/*.js"]}]
['istanbul', {'exclude': ['tests/**/*.js']}]
];

api.cache(true);
Expand Down
5 changes: 2 additions & 3 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const _ = require('lodash');
const testRunnerConfig = require('test-runner-config');
const config = require('./testRunner.config.js');

Expand All @@ -15,10 +14,10 @@ const files = testRunnerConfig.getKarmaFiles(config, {
src: exclude
});
const preprocessors = {};
_.each(testRunnerConfig.getKarmaFiles(config, {
testRunnerConfig.getKarmaFiles(config, {
css: exclude,
src: exclude
}).files, (pattern) => {
}).files.forEach((pattern) => {
if (pattern.included !== false) {
preprocessors[pattern] = ['webpack'];
}
Expand Down
73 changes: 39 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "type-enforcer",
"version": "0.2.4",
"version": "0.3.0",
"description": "Type enforcement library for javascript",
"main": "src/index.js",
"scripts": {
Expand Down Expand Up @@ -39,15 +39,15 @@
},
"homepage": "https://github.com/DarrenPaulWright/type-enforcer#readme",
"dependencies": {
"lodash": "^4.17.11"
"clone": "^2.1.2",
"deep-equal": "^1.0.1"
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.3.1",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.5",
"babel-plugin-istanbul": "^5.1.0",
"babel-plugin-lodash": "^3.3.4",
"chai": "^4.2.0",
"eslint": "^5.12.1",
"eslint-loader": "^2.1.1",
Expand Down
5 changes: 2 additions & 3 deletions src/checks/types/isArray.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { isArray } from 'lodash';
import { buildCheckWithCoerce } from './checks';
import isJson from './isJson';

/**
* Check if a value is an [array]{@link https://lodash.com/docs/#isArray}
* Check if a value is an array
*
* @example
* ``` javascript
Expand All @@ -26,4 +25,4 @@ import isJson from './isJson';
*
* @returns {Boolean}
*/
export default buildCheckWithCoerce(isArray, (value) => isJson(value) && isArray(JSON.parse(value)));
export default buildCheckWithCoerce((item) => Array.isArray(item), (value) => isJson(value) && Array.isArray(JSON.parse(value)));
6 changes: 3 additions & 3 deletions src/checks/types/isBoolean.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isBoolean } from 'lodash';
import { buildCheckWithCoerce } from './checks';
import isInstanceOf from './isInstanceOf';

/**
* Check if a value is a [boolean]{@link https://lodash.com/docs/#isBoolean}
* Check if a value is a boolean
*
* @example
* ``` javascript
Expand All @@ -25,4 +25,4 @@ import { buildCheckWithCoerce } from './checks';
*
* @returns {Boolean}
*/
export default buildCheckWithCoerce(isBoolean, () => true);
export default buildCheckWithCoerce((item) => item === true || item === false || isInstanceOf(item, Boolean), () => true);
6 changes: 3 additions & 3 deletions src/checks/types/isDate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isDate } from 'lodash';
import { buildCheckWithCoerce } from './checks';
import isInstanceOf from './isInstanceOf';

/**
* Check if a value is a [date]{@link https://lodash.com/docs/#isDate}
* Check if a value is a date
*
* @example
* ``` javascript
Expand All @@ -25,4 +25,4 @@ import { buildCheckWithCoerce } from './checks';
*
* @returns {Boolean}
*/
export default buildCheckWithCoerce(isDate, (value) => !isNaN(Date.parse(value)));
export default buildCheckWithCoerce((item) => isInstanceOf(item, Date), (value) => !isNaN(Date.parse(value)));
6 changes: 2 additions & 4 deletions src/checks/types/isElement.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { isElement } from 'lodash';

/**
* Check if a value is a [DOM element]{@link https://lodash.com/docs/#isElement}
* Check if a value is a DOM element
*
* @example
* ``` javascript
Expand All @@ -17,4 +15,4 @@ import { isElement } from 'lodash';
*
* @returns {Boolean}
*/
export default (value) => isElement(value);
export default (value) => !!value && typeof value === 'object' && value.nodeType === 1;
6 changes: 2 additions & 4 deletions src/checks/types/isFunction.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { isFunction } from 'lodash';

/**
* Check if a value is a [function]{@link https://lodash.com/docs/#isFunction}
* Check if a value is a function
*
* @example
* ``` javascript
Expand All @@ -17,4 +15,4 @@ import { isFunction } from 'lodash';
*
* @returns {Boolean}
*/
export default (value) => isFunction(value);
export default (value) => typeof value === 'function';
12 changes: 11 additions & 1 deletion src/checks/types/isInstanceOf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import Enum from '../../types/Enum';

const objectStringMap = {};
objectStringMap[Array] = '[object Array]';
objectStringMap[Boolean] = '[object Boolean]';
objectStringMap[Date] = '[object Date]';
objectStringMap[Number] = '[object Number]';
objectStringMap[Object] = '[object Object]';
objectStringMap[RegExp] = '[object RegExp]';

const typeOfMap = new Enum({
boolean: Boolean,
number: Number,
Expand Down Expand Up @@ -43,5 +51,7 @@ export default (object, constructor) => {
if (object === undefined || !(typeof constructor === 'function' && constructor.prototype)) {
return false;
}
return object instanceof constructor || typeof object === typeOfMap.key(constructor);
return object instanceof constructor
|| (objectStringMap[constructor] && toString.call(object) === objectStringMap[constructor])
|| typeof object === typeOfMap.key(constructor);
};
Loading

0 comments on commit af07164

Please sign in to comment.