[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports["default"] = void 0;
|
---|
| 5 | var _ramda = require("ramda");
|
---|
| 6 | var _isNull = _interopRequireDefault(require("./isNull"));
|
---|
| 7 | var _isObjLike = _interopRequireDefault(require("./isObjLike"));
|
---|
| 8 | var _isFunction = _interopRequireDefault(require("./isFunction"));
|
---|
| 9 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 10 | var isObject = (0, _ramda.pipe)(_ramda.type, (0, _ramda.identical)('Object'));
|
---|
| 11 | var isObjectConstructor = (0, _ramda.pipe)(_ramda.toString, (0, _ramda.equals)((0, _ramda.toString)(Object)));
|
---|
| 12 | var hasObjectConstructor = (0, _ramda.pathSatisfies)((0, _ramda.both)(_isFunction["default"], isObjectConstructor), ['constructor']);
|
---|
| 13 |
|
---|
| 14 | /* eslint-disable max-len */
|
---|
| 15 | /**
|
---|
| 16 | * Check to see if an object is a plain object (created using `{}`, `new Object()` or `Object.create(null)`).
|
---|
| 17 | *
|
---|
| 18 | * @func isPlainObj
|
---|
| 19 | * @aliases isPlainObject
|
---|
| 20 | * @memberOf RA
|
---|
| 21 | * @since {@link https://char0n.github.io/ramda-adjunct/0.5.0|v0.5.0}
|
---|
| 22 | * @category Type
|
---|
| 23 | * @sig * -> Boolean
|
---|
| 24 | * @param {*} val The value to test
|
---|
| 25 | * @return {boolean}
|
---|
| 26 | * @see {@link RA.isNotPlainObj|isNotPlainObj}, {@link RA.isObjLike|isObjLike}, {@link RA.isObj|isObj}
|
---|
| 27 | * @example
|
---|
| 28 | *
|
---|
| 29 | * class Bar {
|
---|
| 30 | * constructor() {
|
---|
| 31 | * this.prop = 'value';
|
---|
| 32 | * }
|
---|
| 33 | * }
|
---|
| 34 | *
|
---|
| 35 | * RA.isPlainObj(new Bar()); //=> false
|
---|
| 36 | * RA.isPlainObj({ prop: 'value' }); //=> true
|
---|
| 37 | * RA.isPlainObj(['a', 'b', 'c']); //=> false
|
---|
| 38 | * RA.isPlainObj(Object.create(null); //=> true
|
---|
| 39 | * RA.isPlainObj(new Object()); //=> true
|
---|
| 40 | */
|
---|
| 41 | /* eslint-enable max-len */
|
---|
| 42 | var isPlainObj = (0, _ramda.curryN)(1, function (val) {
|
---|
| 43 | if (!(0, _isObjLike["default"])(val) || !isObject(val)) {
|
---|
| 44 | return false;
|
---|
| 45 | }
|
---|
| 46 | var proto = Object.getPrototypeOf(val);
|
---|
| 47 | if ((0, _isNull["default"])(proto)) {
|
---|
| 48 | return true;
|
---|
| 49 | }
|
---|
| 50 | return hasObjectConstructor(proto);
|
---|
| 51 | });
|
---|
| 52 | var _default = isPlainObj;
|
---|
| 53 | exports["default"] = _default; |
---|