diff --git a/package.json b/package.json index 5cb8003..ae5416b 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,8 @@ "classnames": "2.2.5", "prop-types": "15.5.10", "react": "16.3.2", - "react-dom": "16.3.2" + "react-dom": "16.3.2", + "underscore": "1.9.1" }, "jest": { "collectCoverageFrom": [ diff --git a/packages/react-bootstrap-table2/src/utils.js b/packages/react-bootstrap-table2/src/utils.js index 16572b2..7d13d6e 100644 --- a/packages/react-bootstrap-table2/src/utils.js +++ b/packages/react-bootstrap-table2/src/utils.js @@ -1,6 +1,7 @@ /* eslint no-empty: 0 */ /* eslint no-param-reassign: 0 */ /* eslint prefer-rest-params: 0 */ +import _ from 'underscore'; function splitNested(str) { return [str] @@ -38,22 +39,8 @@ function set(target, field, value, safe = false) { }, target); } -function isFunction(obj) { - return obj && (typeof obj === 'function'); -} - -/** - * Checks if `value` is the Object. the `Object` except `Function` and `Array.` - * - * @param {*} obj - The value gonna check - */ -function isObject(obj) { - const type = typeof obj; - return obj !== null && type === 'object' && obj.constructor === Object; -} - function isEmptyObject(obj) { - if (!isObject(obj)) return false; + if (!_.isObject(obj)) return false; const hasOwnProperty = Object.prototype.hasOwnProperty; const keys = Object.keys(obj); @@ -96,13 +83,4 @@ function debounce(func, wait, immediate) { }; } -export default { - get, - set, - isFunction, - isObject, - isEmptyObject, - isDefined, - sleep, - debounce -}; +export default Object.assign(_, { get, set, isDefined, isEmptyObject, sleep, debounce }); diff --git a/packages/react-bootstrap-table2/test/utils.test.js b/packages/react-bootstrap-table2/test/utils.test.js index 2aa43b1..89d9ff1 100644 --- a/packages/react-bootstrap-table2/test/utils.test.js +++ b/packages/react-bootstrap-table2/test/utils.test.js @@ -58,32 +58,6 @@ describe('Utils', () => { }); }); - describe('isObject', () => { - describe('when given Object', () => { - it('should return true', () => { - expect(_.isObject({})).toBe(true); - }); - }); - - describe('when given Function', () => { - it('should return false', () => { - expect(_.isObject(() => 'test')).toBe(false); - }); - }); - - describe('when given Array', () => { - it('should return false', () => { - expect(_.isObject([])).toBe(false); - }); - }); - - describe('when given null', () => { - it('should return false', () => { - expect(_.isObject(null)).toBe(false); - }); - }); - }); - describe('isEmptyObject', () => { describe('when given empty Object', () => { it('should return true', () => { @@ -98,14 +72,14 @@ describe('Utils', () => { }); describe('when given Function', () => { - it('should return false', () => { - expect(_.isEmptyObject(() => 'test')).toBe(false); + it('should return true', () => { + expect(_.isEmptyObject(() => 'test')).toBe(true); }); }); describe('when given Array', () => { - it('should return false', () => { - expect(_.isEmptyObject([])).toBe(false); + it('should return true', () => { + expect(_.isEmptyObject([])).toBe(true); }); }); diff --git a/yarn.lock b/yarn.lock index ff2fc0d..4329d62 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8286,6 +8286,10 @@ unc-path-regex@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/unc-path-regex/-/unc-path-regex-0.1.2.tgz#e73dd3d7b0d7c5ed86fbac6b0ae7d8c6a69d50fa" +underscore@1.9.1: + version "1.9.1" + resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.9.1.tgz#06dce34a0e68a7babc29b365b8e74b8925203961" + underscore@~1.4.4: version "1.4.4" resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.4.4.tgz#61a6a32010622afa07963bf325203cf12239d604"