UNPKG

@xlink-network/xlink-sdk

Version:
1 lines 4.88 kB
{"version":3,"sources":["../../src/utils/isPlainObject.ts"],"sourcesContent":["/**\n * lodash (Custom Build) <https://lodash.com/>\n * Build: `lodash modularize exports=\"npm\" -o ./`\n * Copyright jQuery Foundation and other contributors <https://jquery.org/>\n * Released under MIT license <https://lodash.com/license>\n * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>\n * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n */\n\n/** `Object#toString` result references. */\nconst objectTag = \"[object Object]\"\n\n/**\n * Checks if `value` is a host object in IE < 9.\n *\n * @private\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a host object, else `false`.\n */\nfunction isHostObject(value: any): boolean {\n // Many host objects are `Object` objects that can coerce to strings\n // despite having improperly defined `toString` methods.\n let result = false\n if (value != null && typeof value.toString != \"function\") {\n try {\n result = !!(value + \"\")\n } catch (e) {}\n }\n return result\n}\n\n/**\n * Creates a unary function that invokes `func` with its argument transformed.\n *\n * @private\n * @param {Function} func The function to wrap.\n * @param {Function} transform The argument transform.\n * @returns {Function} Returns the new function.\n */\nfunction overArg<A1, A2, R1>(\n func: (arg: A2) => R1,\n transform: (arg: A1) => A2,\n): (arg: A1) => R1 {\n return function (arg: A1): R1 {\n return func(transform(arg))\n }\n}\n\n/** Used for built-in method references. */\nconst funcProto = Function.prototype,\n objectProto = Object.prototype\n\n/** Used to resolve the decompiled source of functions. */\nconst funcToString = funcProto.toString\n\n/** Used to check objects for own properties. */\nconst hasOwnProperty = objectProto.hasOwnProperty\n\n/** Used to infer the `Object` constructor. */\nconst objectCtorString = funcToString.call(Object)\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nconst objectToString = objectProto.toString\n\n/** Built-in value references. */\nconst getPrototype = overArg(Object.getPrototypeOf, Object)\n\n/**\n * Checks if `value` is object-like. A value is object-like if it's not `null`\n * and has a `typeof` result of \"object\".\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is object-like, else `false`.\n * @example\n *\n * _.isObjectLike({});\n * // => true\n *\n * _.isObjectLike([1, 2, 3]);\n * // => true\n *\n * _.isObjectLike(_.noop);\n * // => false\n *\n * _.isObjectLike(null);\n * // => false\n */\nfunction isObjectLike(value: any): boolean {\n return !!value && typeof value == \"object\"\n}\n\n/**\n * Checks if `value` is a plain object, that is, an object created by the\n * `Object` constructor or one with a `[[Prototype]]` of `null`.\n *\n * @static\n * @memberOf _\n * @since 0.8.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.\n * @example\n *\n * function Foo() {\n * this.a = 1;\n * }\n *\n * _.isPlainObject(new Foo);\n * // => false\n *\n * _.isPlainObject([1, 2, 3]);\n * // => false\n *\n * _.isPlainObject({ 'x': 0, 'y': 0 });\n * // => true\n *\n * _.isPlainObject(Object.create(null));\n * // => true\n */\nexport function isPlainObject(value: any): boolean {\n if (\n !isObjectLike(value) ||\n objectToString.call(value) != objectTag ||\n isHostObject(value)\n ) {\n return false\n }\n const proto = getPrototype(value)\n if (proto === null) {\n return true\n }\n const Ctor = hasOwnProperty.call(proto, \"constructor\") && proto.constructor\n return (\n typeof Ctor == \"function\" &&\n Ctor instanceof Ctor &&\n funcToString.call(Ctor) == objectCtorString\n )\n}\n"],"mappings":";;;AAUA,IAAM,YAAY;AASlB,SAAS,aAAa,OAAqB;AAGzC,MAAI,SAAS;AACb,MAAI,SAAS,QAAQ,OAAO,MAAM,YAAY,YAAY;AACxD,QAAI;AACF,eAAS,CAAC,EAAE,QAAQ;AAAA,IACtB,SAAS,GAAG;AAAA,IAAC;AAAA,EACf;AACA,SAAO;AACT;AAUA,SAAS,QACP,MACA,WACiB;AACjB,SAAO,SAAU,KAAa;AAC5B,WAAO,KAAK,UAAU,GAAG,CAAC;AAAA,EAC5B;AACF;AAGA,IAAM,YAAY,SAAS;AAA3B,IACE,cAAc,OAAO;AAGvB,IAAM,eAAe,UAAU;AAG/B,IAAM,iBAAiB,YAAY;AAGnC,IAAM,mBAAmB,aAAa,KAAK,MAAM;AAOjD,IAAM,iBAAiB,YAAY;AAGnC,IAAM,eAAe,QAAQ,OAAO,gBAAgB,MAAM;AA0B1D,SAAS,aAAa,OAAqB;AACzC,SAAO,CAAC,CAAC,SAAS,OAAO,SAAS;AACpC;AA8BO,SAAS,cAAc,OAAqB;AACjD,MACE,CAAC,aAAa,KAAK,KACnB,eAAe,KAAK,KAAK,KAAK,aAC9B,aAAa,KAAK,GAClB;AACA,WAAO;AAAA,EACT;AACA,QAAM,QAAQ,aAAa,KAAK;AAChC,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AACA,QAAM,OAAO,eAAe,KAAK,OAAO,aAAa,KAAK,MAAM;AAChE,SACE,OAAO,QAAQ,cACf,gBAAgB,QAChB,aAAa,KAAK,IAAI,KAAK;AAE/B;","names":[]}