source: node_modules/ramda-adjunct/lib/isPlainObj.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[d24f17c]1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _ramda = require("ramda");
6var _isNull = _interopRequireDefault(require("./isNull"));
7var _isObjLike = _interopRequireDefault(require("./isObjLike"));
8var _isFunction = _interopRequireDefault(require("./isFunction"));
9function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10var isObject = (0, _ramda.pipe)(_ramda.type, (0, _ramda.identical)('Object'));
11var isObjectConstructor = (0, _ramda.pipe)(_ramda.toString, (0, _ramda.equals)((0, _ramda.toString)(Object)));
12var 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 */
42var 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});
52var _default = isPlainObj;
53exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.