-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs-partial-is-object.js
73 lines (64 loc) · 2.75 KB
/
js-partial-is-object.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
|----------------------------------------------------------------------------------------------------------------------
| A partial to check whether an object is a plain object.
|----------------------------------------------------------------------------------------------------------------------
*/
/**
* More information on [JavaScript Open Standards]{@link https://github.com/jsopenstd/jsopenstd}.
*
* @namespace js.partial
* @version 0.0.2
*
* @author Richard King <richrdkng@gmail.com> [GitHub]{@link https://github.com/richrdkng}
* @license [MIT]{@link https://github.com/jsopenstd/js-partial-foreach/blob/master/license.md}
*/
/**
* UMD - [returnExports.js pattern]{@link https://github.com/umdjs/umd/blob/master/templates/returnExports.js}
* For more information and license, check the link below:
* [UMD GitHub Repository]{@link https://github.com/umdjs/umd}
*/
(function(root, factory) {
// AMD
/* istanbul ignore next: ignore coverage test for UMD */
if (typeof define === 'function' && define.amd) {
define([], factory);
// CommonJS
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
// Browser
} else {
root.js_partial_isObject = factory();
}
}(this, function() {
'use strict';
/**
* Determines whether an object is a plain object.
* By default it handles **null-prototype objects** as plain objects created via **Object.create(null)**.
*
* @function isObject
* @memberOf js.partial
*
* @param {*} object - The object to check.
* @param {boolean} [handleNullPrototypeObjectAsPlainObject=true] - Handle a null-prototype object as plain object
* too, when created via **Object.create(null)**.
* By default a null-prototype object will be also
* classified as a plain object.
*
* @returns {boolean} If the object is a plain object, it will return true.
*/
return function isObject(object, handleNullPrototypeObjectAsPlainObject) {
var handleNullProtoObj = true;
if (typeof handleNullPrototypeObjectAsPlainObject === 'boolean') {
handleNullProtoObj = handleNullPrototypeObjectAsPlainObject;
}
if (object !== null) {
if (Object.prototype.toString.call(object) === '[object Object]') {
if ( ! handleNullProtoObj) {
return typeof object.constructor !== 'undefined';
}
return true;
}
}
return false;
};
}));