-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
<script src="../node_modules/lodash/lodash.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script> | ||
<link data-require="[email protected]" data-semver="2.4.1" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.css" /> | ||
<script data-require="[email protected]" data-semver="2.4.1" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js"></script> | ||
<script data-require="[email protected]" data-semver="2.4.1" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine-html.js"></script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const toString = Object.prototype.toString | ||
|
||
/** | ||
* Gets the `toStringTag` of `value`. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {string} Returns the `toStringTag`. | ||
*/ | ||
function getTag(value) { | ||
if (value == null) { | ||
return value === undefined ? '[object Undefined]' : '[object Null]' | ||
} | ||
return toString.call(value) | ||
} | ||
|
||
/** | ||
* Checks if `value` is object-like. A value is object-like if it's not `null` | ||
* and has a `typeof` result of "object". | ||
* | ||
* @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(Function) | ||
* // => false | ||
* | ||
* isObjectLike(null) | ||
* // => false | ||
*/ | ||
function isObjectLike(value) { | ||
return typeof value == 'object' && value !== null | ||
} | ||
|
||
/** | ||
* Checks if `value` is a plain object, that is, an object created by the | ||
* `Object` constructor or one with a `[[Prototype]]` of `null`. | ||
* | ||
* @since 0.8.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`. | ||
* @example | ||
* | ||
* function Foo() { | ||
* this.a = 1 | ||
* } | ||
* | ||
* isPlainObject(new Foo) | ||
* // => false | ||
* | ||
* isPlainObject([1, 2, 3]) | ||
* // => false | ||
* | ||
* isPlainObject({ 'x': 0, 'y': 0 }) | ||
* // => true | ||
* | ||
* isPlainObject(Object.create(null)) | ||
* // => true | ||
*/ | ||
function isPlainObject(value) { | ||
if (!isObjectLike(value) || getTag(value) != '[object Object]') { | ||
return false | ||
} | ||
if (Object.getPrototypeOf(value) === null) { | ||
return true | ||
} | ||
let proto = value | ||
while (Object.getPrototypeOf(proto) !== null) { | ||
proto = Object.getPrototypeOf(proto) | ||
} | ||
return Object.getPrototypeOf(value) === proto | ||
} | ||
|
||
export default isPlainObject |