From b7e8c8a15e990d8ad58c69bbaa6a0fa06f2e13b0 Mon Sep 17 00:00:00 2001 From: fairsky0201 Date: Thu, 31 May 2018 13:50:48 -0700 Subject: [PATCH] Simplify object check and eliminate lodash depdency (#936) * Simplify object check and eliminate lodash depdency, mirroring https://github.com/reactjs/redux/pull/2599 . * Add missing files. * Replace isPlainObject with unmodified version from Redux * Also replace the spec with the unmodified version --- .babelrc | 6 - build/use-lodash-es.js | 10 - package-lock.json | 365 +++++++++++++++++-------------- package.json | 14 +- src/utils/isPlainObject.js | 14 ++ src/utils/verifyPlainObject.js | 2 +- test/utils/isPlainObject.spec.js | 21 ++ 7 files changed, 241 insertions(+), 191 deletions(-) delete mode 100644 build/use-lodash-es.js create mode 100644 src/utils/isPlainObject.js create mode 100644 test/utils/isPlainObject.spec.js diff --git a/.babelrc b/.babelrc index a84feab..fc1a8d9 100644 --- a/.babelrc +++ b/.babelrc @@ -34,14 +34,8 @@ ["transform-es2015-modules-commonjs", { "loose": true }] ] }, - "es": { - "plugins": [ - "./build/use-lodash-es" - ] - }, "rollup": { "plugins": [ - "./build/use-lodash-es", "external-helpers" ] } diff --git a/build/use-lodash-es.js b/build/use-lodash-es.js deleted file mode 100644 index ba4f2f5..0000000 --- a/build/use-lodash-es.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = function () { - return { - visitor: { - ImportDeclaration(path) { - var source = path.node.source - source.value = source.value.replace(/^lodash($|\/)/, 'lodash-es$1') - } - } - } -} diff --git a/package-lock.json b/package-lock.json index 5d4f802..c76413e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,56 +13,6 @@ "@babel/highlight": "7.0.0-beta.42" } }, - "@babel/generator": { - "version": "7.0.0-beta.42", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.0.0-beta.42.tgz", - "integrity": "sha512-9x3zS4nG/6GAvJWB8fAK+5g/Di36xdubB43dMNSucNJTwPvmyfCippir/0I8zyG+ID66hLCLi8V9bomlWRYaHA==", - "dev": true, - "requires": { - "@babel/types": "7.0.0-beta.42", - "jsesc": "2.5.1", - "lodash": "4.17.5", - "source-map": "0.5.6", - "trim-right": "1.0.1" - }, - "dependencies": { - "jsesc": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.1.tgz", - "integrity": "sha1-5CGiqOINawgZ3yiQj3glJrlt0f4=", - "dev": true - } - } - }, - "@babel/helper-function-name": { - "version": "7.0.0-beta.42", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.42.tgz", - "integrity": "sha512-6IZ+kkPypwJrnmNzI3y31qAps2kXoPtCE241SvBva2YzB0n/YORWx2YM0jHPYOJBU9Xx5KkUhOKuWkeXZQgtTA==", - "dev": true, - "requires": { - "@babel/helper-get-function-arity": "7.0.0-beta.42", - "@babel/template": "7.0.0-beta.42", - "@babel/types": "7.0.0-beta.42" - } - }, - "@babel/helper-get-function-arity": { - "version": "7.0.0-beta.42", - "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.42.tgz", - "integrity": "sha512-hF5KKcn+V/5PwU7KZ1aVwo535woLC9eV+djaoyNPZeMMJ2s+8bZlEa66Tarei0T68VRL5LXIs1Ao4hSabSkpBg==", - "dev": true, - "requires": { - "@babel/types": "7.0.0-beta.42" - } - }, - "@babel/helper-split-export-declaration": { - "version": "7.0.0-beta.42", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0-beta.42.tgz", - "integrity": "sha512-2r8pZG6SAJTTaI2OhxCmz5PKlMUPY5adOHrHtb1gM3ibJPDOzPAeOQNzItdxNnM33jjRakEGitXX6iYg7Sz73w==", - "dev": true, - "requires": { - "@babel/types": "7.0.0-beta.42" - } - }, "@babel/highlight": { "version": "7.0.0-beta.42", "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0-beta.42.tgz", @@ -105,86 +55,6 @@ } } }, - "@babel/template": { - "version": "7.0.0-beta.42", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.0.0-beta.42.tgz", - "integrity": "sha512-EK7YdTe47j4VxlwNvz5bnlk5Jx/wWublnqfgOY2IuSNdxCQgXrLD34PfTnabGxywNSkJkcSo6jwr2JGT+S48dA==", - "dev": true, - "requires": { - "@babel/code-frame": "7.0.0-beta.42", - "@babel/types": "7.0.0-beta.42", - "babylon": "7.0.0-beta.42", - "lodash": "4.17.5" - }, - "dependencies": { - "babylon": { - "version": "7.0.0-beta.42", - "resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.42.tgz", - "integrity": "sha512-h6E/OkkvcBw/JimbL0p8dIaxrcuQn3QmIYGC/GtJlRYif5LTKBYPHXYwqluJpfS/kOXoz0go+9mkmOVC0M+zWw==", - "dev": true - } - } - }, - "@babel/traverse": { - "version": "7.0.0-beta.42", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.0.0-beta.42.tgz", - "integrity": "sha512-DZwMuZBfYVIn/cxpXZzHDgKmarW/MWqplLv1k7QJYhK5r5l6GAac/DkKl75A0CjPYrD3VGco6H6ZQp12QaYKSw==", - "dev": true, - "requires": { - "@babel/code-frame": "7.0.0-beta.42", - "@babel/generator": "7.0.0-beta.42", - "@babel/helper-function-name": "7.0.0-beta.42", - "@babel/helper-split-export-declaration": "7.0.0-beta.42", - "@babel/types": "7.0.0-beta.42", - "babylon": "7.0.0-beta.42", - "debug": "3.1.0", - "globals": "11.4.0", - "invariant": "2.2.4", - "lodash": "4.17.5" - }, - "dependencies": { - "babylon": { - "version": "7.0.0-beta.42", - "resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.42.tgz", - "integrity": "sha512-h6E/OkkvcBw/JimbL0p8dIaxrcuQn3QmIYGC/GtJlRYif5LTKBYPHXYwqluJpfS/kOXoz0go+9mkmOVC0M+zWw==", - "dev": true - }, - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "globals": { - "version": "11.4.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.4.0.tgz", - "integrity": "sha512-Dyzmifil8n/TmSqYDEXbm+C8yitzJQqQIlJQLNRMwa+BOUJpRC19pyVeN12JAjt61xonvXjtff+hJruTRXn5HA==", - "dev": true - } - } - }, - "@babel/types": { - "version": "7.0.0-beta.42", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.0.0-beta.42.tgz", - "integrity": "sha512-+pmpISmTHQqMMpHHtDLxcvtRhmn53bAxy8goJfHipS/uy/r3PLcuSdPizLW7DhtBWbtgIKZufLObfnIMoyMNsw==", - "dev": true, - "requires": { - "esutils": "2.0.2", - "lodash": "4.17.5", - "to-fast-properties": "2.0.0" - }, - "dependencies": { - "to-fast-properties": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", - "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", - "dev": true - } - } - }, "@types/acorn": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/@types/acorn/-/acorn-4.0.3.tgz", @@ -650,23 +520,182 @@ } }, "babel-eslint": { - "version": "8.2.2", - "resolved": "http://registry.npmjs.org/babel-eslint/-/babel-eslint-8.2.2.tgz", - "integrity": "sha512-Qt2lz2egBxNYWqN9JIO2z4NOOf8i4b5JS6CFoYrOZZTDssueiV1jH/jsefyg+86SeNY3rB361/mi3kE1WK2WYQ==", + "version": "8.2.3", + "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-8.2.3.tgz", + "integrity": "sha512-0HeSTtaXg/Em7FCUWxwOT+KeFSO1O7LuRuzhk7g+1BjwdlQGlHq4OyMi3GqGxrNfEq8jEi6Hmt5ylEQUhurgiQ==", "dev": true, "requires": { - "@babel/code-frame": "7.0.0-beta.42", - "@babel/traverse": "7.0.0-beta.42", - "@babel/types": "7.0.0-beta.42", - "babylon": "7.0.0-beta.42", + "@babel/code-frame": "7.0.0-beta.44", + "@babel/traverse": "7.0.0-beta.44", + "@babel/types": "7.0.0-beta.44", + "babylon": "7.0.0-beta.44", "eslint-scope": "3.7.1", "eslint-visitor-keys": "1.0.0" }, "dependencies": { + "@babel/code-frame": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0-beta.44.tgz", + "integrity": "sha512-cuAuTTIQ9RqcFRJ/Y8PvTh+paepNcaGxwQwjIDRWPXmzzyAeCO4KqS9ikMvq0MCbRk6GlYKwfzStrcP3/jSL8g==", + "dev": true, + "requires": { + "@babel/highlight": "7.0.0-beta.44" + } + }, + "@babel/generator": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.0.0-beta.44.tgz", + "integrity": "sha512-5xVb7hlhjGcdkKpMXgicAVgx8syK5VJz193k0i/0sLP6DzE6lRrU1K3B/rFefgdo9LPGMAOOOAWW4jycj07ShQ==", + "dev": true, + "requires": { + "@babel/types": "7.0.0-beta.44", + "jsesc": "2.5.1", + "lodash": "4.17.5", + "source-map": "0.5.6", + "trim-right": "1.0.1" + } + }, + "@babel/helper-function-name": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.44.tgz", + "integrity": "sha512-MHRG2qZMKMFaBavX0LWpfZ2e+hLloT++N7rfM3DYOMUOGCD8cVjqZpwiL8a0bOX3IYcQev1ruciT0gdFFRTxzg==", + "dev": true, + "requires": { + "@babel/helper-get-function-arity": "7.0.0-beta.44", + "@babel/template": "7.0.0-beta.44", + "@babel/types": "7.0.0-beta.44" + } + }, + "@babel/helper-get-function-arity": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.44.tgz", + "integrity": "sha512-w0YjWVwrM2HwP6/H3sEgrSQdkCaxppqFeJtAnB23pRiJB5E/O9Yp7JAAeWBl+gGEgmBFinnTyOv2RN7rcSmMiw==", + "dev": true, + "requires": { + "@babel/types": "7.0.0-beta.44" + } + }, + "@babel/helper-split-export-declaration": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0-beta.44.tgz", + "integrity": "sha512-aQ7QowtkgKKzPGf0j6u77kBMdUFVBKNHw2p/3HX/POt5/oz8ec5cs0GwlgM8Hz7ui5EwJnzyfRmkNF1Nx1N7aA==", + "dev": true, + "requires": { + "@babel/types": "7.0.0-beta.44" + } + }, + "@babel/highlight": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0-beta.44.tgz", + "integrity": "sha512-Il19yJvy7vMFm8AVAh6OZzaFoAd0hbkeMZiX3P5HGD+z7dyI7RzndHB0dg6Urh/VAFfHtpOIzDUSxmY6coyZWQ==", + "dev": true, + "requires": { + "chalk": "2.4.0", + "esutils": "2.0.2", + "js-tokens": "3.0.2" + } + }, + "@babel/template": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.0.0-beta.44.tgz", + "integrity": "sha512-w750Sloq0UNifLx1rUqwfbnC6uSUk0mfwwgGRfdLiaUzfAOiH0tHJE6ILQIUi3KYkjiCDTskoIsnfqZvWLBDng==", + "dev": true, + "requires": { + "@babel/code-frame": "7.0.0-beta.44", + "@babel/types": "7.0.0-beta.44", + "babylon": "7.0.0-beta.44", + "lodash": "4.17.5" + } + }, + "@babel/traverse": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.0.0-beta.44.tgz", + "integrity": "sha512-UHuDz8ukQkJCDASKHf+oDt3FVUzFd+QYfuBIsiNu/4+/ix6pP/C+uQZJ6K1oEfbCMv/IKWbgDEh7fcsnIE5AtA==", + "dev": true, + "requires": { + "@babel/code-frame": "7.0.0-beta.44", + "@babel/generator": "7.0.0-beta.44", + "@babel/helper-function-name": "7.0.0-beta.44", + "@babel/helper-split-export-declaration": "7.0.0-beta.44", + "@babel/types": "7.0.0-beta.44", + "babylon": "7.0.0-beta.44", + "debug": "3.1.0", + "globals": "11.4.0", + "invariant": "2.2.4", + "lodash": "4.17.5" + } + }, + "@babel/types": { + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.0.0-beta.44.tgz", + "integrity": "sha512-5eTV4WRmqbaFM3v9gHAIljEQJU4Ssc6fxL61JN+Oe2ga/BwyjzjamwkCVVAQjHGuAX8i0BWo42dshL8eO5KfLQ==", + "dev": true, + "requires": { + "esutils": "2.0.2", + "lodash": "4.17.5", + "to-fast-properties": "2.0.0" + } + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "1.9.1" + } + }, "babylon": { - "version": "7.0.0-beta.42", - "resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.42.tgz", - "integrity": "sha512-h6E/OkkvcBw/JimbL0p8dIaxrcuQn3QmIYGC/GtJlRYif5LTKBYPHXYwqluJpfS/kOXoz0go+9mkmOVC0M+zWw==", + "version": "7.0.0-beta.44", + "resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.44.tgz", + "integrity": "sha512-5Hlm13BJVAioCHpImtFqNOF2H3ieTOHd0fmFGMxOJ9jgeFqeAwsv3u5P5cR7CSeFrkgHsT19DgFJkHV0/Mcd8g==", + "dev": true + }, + "chalk": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.0.tgz", + "integrity": "sha512-Wr/w0f4o9LuE7K53cD0qmbAMM+2XNLzR29vFn5hqko4sxGlUsyy363NvmyGIyk5tpe9cjTr9SJYbysEyPkRnFw==", + "dev": true, + "requires": { + "ansi-styles": "3.2.1", + "escape-string-regexp": "1.0.5", + "supports-color": "5.4.0" + } + }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "globals": { + "version": "11.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.4.0.tgz", + "integrity": "sha512-Dyzmifil8n/TmSqYDEXbm+C8yitzJQqQIlJQLNRMwa+BOUJpRC19pyVeN12JAjt61xonvXjtff+hJruTRXn5HA==", + "dev": true + }, + "jsesc": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.1.tgz", + "integrity": "sha1-5CGiqOINawgZ3yiQj3glJrlt0f4=", + "dev": true + }, + "supports-color": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", + "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", + "dev": true, + "requires": { + "has-flag": "3.0.0" + } + }, + "to-fast-properties": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", + "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", "dev": true } } @@ -2419,12 +2448,11 @@ } }, "eslint-plugin-import": { - "version": "2.10.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.10.0.tgz", - "integrity": "sha1-+gkIPVp1KI35xsfQn+EiVZhWVec=", + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.11.0.tgz", + "integrity": "sha1-Fa7qN6Z0mdhI6OmBgG1GJ7VQOBY=", "dev": true, "requires": { - "builtin-modules": "1.1.1", "contains-path": "0.1.0", "debug": "2.6.8", "doctrine": "1.5.0", @@ -2433,7 +2461,8 @@ "has": "1.0.1", "lodash": "4.17.5", "minimatch": "3.0.4", - "read-pkg-up": "2.0.0" + "read-pkg-up": "2.0.0", + "resolve": "1.6.0" }, "dependencies": { "doctrine": { @@ -5953,12 +5982,14 @@ "lodash": { "version": "4.17.5", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", - "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==" + "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==", + "dev": true }, "lodash-es": { "version": "4.17.8", "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.8.tgz", - "integrity": "sha512-I9mjAxengFAleSThFhhAhvba6fsO0hunb9/0sQ6qQihSZsJRBofv2rYH58WXaOb/O++eUmYpCLywSQ22GfU+sA==" + "integrity": "sha512-I9mjAxengFAleSThFhhAhvba6fsO0hunb9/0sQ6qQihSZsJRBofv2rYH58WXaOb/O++eUmYpCLywSQ22GfU+sA==", + "dev": true }, "lodash.sortby": { "version": "4.7.0", @@ -6827,9 +6858,9 @@ } }, "react": { - "version": "16.3.0", - "resolved": "https://registry.npmjs.org/react/-/react-16.3.0.tgz", - "integrity": "sha512-Qh35tNbwY8SLFELkN3PCLO16EARV+lgcmNkQnoZXfzAF1ASRpeucZYUwBlBzsRAzTb7KyfBaLQ4/K/DLC6MYeA==", + "version": "16.3.2", + "resolved": "https://registry.npmjs.org/react/-/react-16.3.2.tgz", + "integrity": "sha512-o5GPdkhciQ3cEph6qgvYB7LTOHw/GB0qRI6ZFNugj49qJCFfgHwVNjZ5u+b7nif4vOeMIOuYj3CeYe2IBD74lg==", "dev": true, "requires": { "fbjs": "0.8.16", @@ -6839,9 +6870,9 @@ } }, "react-dom": { - "version": "16.3.0", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.3.0.tgz", - "integrity": "sha512-xT/FxawAurL6AV8YtAP7LkdDJFFX2vvv17AqFLQRF81ZtWLXkV/0dcAaiFIy0lmoQEFT931TU9aaH+5dBUxTcw==", + "version": "16.3.2", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.3.2.tgz", + "integrity": "sha512-MMPko3zYncNrz/7gG17wJWUREZDvskZHXOwbttzl0F0L3wDmToyuETuo/r8Y5yvDejwYcRyWI1lvVBjLJWFwKA==", "dev": true, "requires": { "fbjs": "0.8.16", @@ -6850,22 +6881,24 @@ "prop-types": "15.6.1" } }, - "react-is": { - "version": "16.3.0", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.3.0.tgz", - "integrity": "sha512-YOo+BNK2z8LiDxh2viaOklPqhwrMMsNPWnXTseOqJa8/ob8mv9aD9Z5FqqQnKNbIerBm+DoIwjAAAKcpdDo1/w==", - "dev": true - }, "react-test-renderer": { - "version": "16.3.0", - "resolved": "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-16.3.0.tgz", - "integrity": "sha512-7FAfgIT8Kvew36b2VFXnhMxjKkwAnicD1dyopq7Ot19WAhfJkyhYNwPzM1AnCfYccvEhO0x4FbqJETyMGQwgIg==", + "version": "16.3.2", + "resolved": "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-16.3.2.tgz", + "integrity": "sha512-lL8WHIpCTMdSe+CRkt0rfMxBkJFyhVrpdQ54BaJRIrXf9aVmbeHbRA8GFRpTvohPN5tPzMabmrzW2PUfWCfWwQ==", "dev": true, "requires": { "fbjs": "0.8.16", "object-assign": "4.1.1", "prop-types": "15.6.1", - "react-is": "16.3.0" + "react-is": "16.3.2" + }, + "dependencies": { + "react-is": { + "version": "16.3.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.3.2.tgz", + "integrity": "sha512-ybEM7YOr4yBgFd6w8dJqwxegqZGJNBZl6U27HnGKuTZmDvVrD5quWOK/wAnMywiZzW+Qsk+l4X2c70+thp/A8Q==", + "dev": true + } } }, "read-pkg": { @@ -7280,9 +7313,9 @@ } }, "rollup-plugin-babel": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/rollup-plugin-babel/-/rollup-plugin-babel-3.0.3.tgz", - "integrity": "sha512-5kzM/Rr4jQSRPLc2eN5NuD+CI/6AAy7S1O18Ogu4U3nq1Q42VJn0C9EMtqnvxtfwf1XrezOtdA9ro1VZI5B0mA==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/rollup-plugin-babel/-/rollup-plugin-babel-3.0.4.tgz", + "integrity": "sha512-TGhQbliTZnRoUhd2214K3r4KJUBu9J1DPzcrAnkluVXOVrveU9OvAaYQ16KyOmujAoq+LMC1+x6YF2xBrU7t+g==", "dev": true, "requires": { "rollup-pluginutils": "1.5.2" diff --git a/package.json b/package.json index 40db75d..fdc6c5e 100644 --- a/package.json +++ b/package.json @@ -45,15 +45,13 @@ "dependencies": { "hoist-non-react-statics": "^2.5.0", "invariant": "^2.2.4", - "lodash": "^4.17.5", - "lodash-es": "^4.17.5", "loose-envify": "^1.1.0", "prop-types": "^15.6.1" }, "devDependencies": { "babel-cli": "^6.26.0", "babel-core": "^6.26.0", - "babel-eslint": "^8.2.2", + "babel-eslint": "^8.2.3", "babel-plugin-check-es2015-constants": "^6.3.13", "babel-plugin-external-helpers": "^6.22.0", "babel-plugin-syntax-jsx": "^6.3.13", @@ -83,17 +81,17 @@ "cross-env": "^5.1.4", "es3ify": "^0.2.0", "eslint": "^4.19.1", - "eslint-plugin-import": "^2.10.0", + "eslint-plugin-import": "^2.11.0", "eslint-plugin-react": "^7.7.0", "glob": "^7.1.1", "jest": "^22.4.3", - "react": "^16.3.0", - "react-dom": "^16.3.0", - "react-test-renderer": "^16.3.0", + "react": "^16.3.2", + "react-dom": "^16.3.2", + "react-test-renderer": "^16.3.2", "redux": "^3.0.0", "rimraf": "^2.6.2", "rollup": "^0.57.1", - "rollup-plugin-babel": "^3.0.3", + "rollup-plugin-babel": "^3.0.4", "rollup-plugin-commonjs": "^9.1.0", "rollup-plugin-node-resolve": "^3.3.0", "rollup-plugin-replace": "^2.0.0", diff --git a/src/utils/isPlainObject.js b/src/utils/isPlainObject.js new file mode 100644 index 0000000..3560c2c --- /dev/null +++ b/src/utils/isPlainObject.js @@ -0,0 +1,14 @@ +/** + * @param {any} obj The object to inspect. + * @returns {boolean} True if the argument appears to be a plain object. + */ +export default function isPlainObject(obj) { + if (typeof obj !== 'object' || obj === null) return false + + let proto = obj + while (Object.getPrototypeOf(proto) !== null) { + proto = Object.getPrototypeOf(proto) + } + + return Object.getPrototypeOf(obj) === proto +} diff --git a/src/utils/verifyPlainObject.js b/src/utils/verifyPlainObject.js index a56e1c6..8e98b39 100644 --- a/src/utils/verifyPlainObject.js +++ b/src/utils/verifyPlainObject.js @@ -1,4 +1,4 @@ -import isPlainObject from 'lodash/isPlainObject' +import isPlainObject from './isPlainObject' import warning from './warning' export default function verifyPlainObject(value, displayName, methodName) { diff --git a/test/utils/isPlainObject.spec.js b/test/utils/isPlainObject.spec.js new file mode 100644 index 0000000..f8addd7 --- /dev/null +++ b/test/utils/isPlainObject.spec.js @@ -0,0 +1,21 @@ +import isPlainObject from '../../src/utils/isPlainObject' +import vm from 'vm' + +describe('isPlainObject', () => { + it('returns true only if plain object', () => { + function Test() { + this.prop = 1 + } + + const sandbox = { fromAnotherRealm: false } + vm.runInNewContext('fromAnotherRealm = {}', sandbox) + + expect(isPlainObject(sandbox.fromAnotherRealm)).toBe(true) + expect(isPlainObject(new Test())).toBe(false) + expect(isPlainObject(new Date())).toBe(false) + expect(isPlainObject([1, 2, 3])).toBe(false) + expect(isPlainObject(null)).toBe(false) + expect(isPlainObject()).toBe(false) + expect(isPlainObject({ x: 1, y: 2 })).toBe(true) + }) +})