basic.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name in all)
  7. __defProp(target, name, { get: all[name], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. extend: () => extend,
  21. get: () => get,
  22. inBrowser: () => inBrowser,
  23. isSameValue: () => isSameValue,
  24. noop: () => noop,
  25. pick: () => pick,
  26. toArray: () => toArray
  27. });
  28. module.exports = __toCommonJS(stdin_exports);
  29. var import_validate = require("./validate");
  30. function noop() {
  31. }
  32. const extend = Object.assign;
  33. const inBrowser = typeof window !== "undefined";
  34. function get(object, path) {
  35. const keys = path.split(".");
  36. let result = object;
  37. keys.forEach((key) => {
  38. var _a;
  39. result = (0, import_validate.isObject)(result) ? (_a = result[key]) != null ? _a : "" : "";
  40. });
  41. return result;
  42. }
  43. function pick(obj, keys, ignoreUndefined) {
  44. return keys.reduce((ret, key) => {
  45. if (!ignoreUndefined || obj[key] !== void 0) {
  46. ret[key] = obj[key];
  47. }
  48. return ret;
  49. }, {});
  50. }
  51. const isSameValue = (newValue, oldValue) => JSON.stringify(newValue) === JSON.stringify(oldValue);
  52. const toArray = (item) => Array.isArray(item) ? item : [item];