basic.mjs 802 B

12345678910111213141516171819202122232425262728293031323334
  1. import { isObject } from "./validate.mjs";
  2. function noop() {
  3. }
  4. const extend = Object.assign;
  5. const inBrowser = typeof window !== "undefined";
  6. function get(object, path) {
  7. const keys = path.split(".");
  8. let result = object;
  9. keys.forEach((key) => {
  10. var _a;
  11. result = isObject(result) ? (_a = result[key]) != null ? _a : "" : "";
  12. });
  13. return result;
  14. }
  15. function pick(obj, keys, ignoreUndefined) {
  16. return keys.reduce((ret, key) => {
  17. if (!ignoreUndefined || obj[key] !== void 0) {
  18. ret[key] = obj[key];
  19. }
  20. return ret;
  21. }, {});
  22. }
  23. const isSameValue = (newValue, oldValue) => JSON.stringify(newValue) === JSON.stringify(oldValue);
  24. const toArray = (item) => Array.isArray(item) ? item : [item];
  25. export {
  26. extend,
  27. get,
  28. inBrowser,
  29. isSameValue,
  30. noop,
  31. pick,
  32. toArray
  33. };