@vueuse/shared 10.2.1 → 10.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -442,6 +442,22 @@ const directiveHooks = {
442
442
  unmounted: vueDemi.isVue3 ? "unmounted" : "unbind"
443
443
  };
444
444
 
445
+ function cacheStringFunction(fn) {
446
+ const cache = /* @__PURE__ */ Object.create(null);
447
+ return (str) => {
448
+ const hit = cache[str];
449
+ return hit || (cache[str] = fn(str));
450
+ };
451
+ }
452
+ const hyphenateRE = /\B([A-Z])/g;
453
+ const hyphenate = cacheStringFunction(
454
+ (str) => str.replace(hyphenateRE, "-$1").toLowerCase()
455
+ );
456
+ const camelizeRE = /-(\w)/g;
457
+ const camelize = cacheStringFunction((str) => {
458
+ return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
459
+ });
460
+
445
461
  function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
446
462
  return new Promise((resolve, reject) => {
447
463
  if (throwOnTimeout)
@@ -723,24 +739,30 @@ var __spreadValues$9 = (a, b) => {
723
739
  return a;
724
740
  };
725
741
  var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
726
- function toRefs(objectRef) {
742
+ function toRefs(objectRef, options = {}) {
727
743
  if (!vueDemi.isRef(objectRef))
728
744
  return vueDemi.toRefs(objectRef);
729
- const result = Array.isArray(objectRef.value) ? new Array(objectRef.value.length) : {};
745
+ const result = Array.isArray(objectRef.value) ? Array.from({ length: objectRef.value.length }) : {};
730
746
  for (const key in objectRef.value) {
731
747
  result[key] = vueDemi.customRef(() => ({
732
748
  get() {
733
749
  return objectRef.value[key];
734
750
  },
735
751
  set(v) {
736
- if (Array.isArray(objectRef.value)) {
737
- const copy = [...objectRef.value];
738
- copy[key] = v;
739
- objectRef.value = copy;
752
+ var _a;
753
+ const replaceRef = (_a = toValue(options.replaceRef)) != null ? _a : true;
754
+ if (replaceRef) {
755
+ if (Array.isArray(objectRef.value)) {
756
+ const copy = [...objectRef.value];
757
+ copy[key] = v;
758
+ objectRef.value = copy;
759
+ } else {
760
+ const newObject = __spreadProps$7(__spreadValues$9({}, objectRef.value), { [key]: v });
761
+ Object.setPrototypeOf(newObject, Object.getPrototypeOf(objectRef.value));
762
+ objectRef.value = newObject;
763
+ }
740
764
  } else {
741
- const newObject = __spreadProps$7(__spreadValues$9({}, objectRef.value), { [key]: v });
742
- Object.setPrototypeOf(newObject, Object.getPrototypeOf(objectRef.value));
743
- objectRef.value = newObject;
765
+ objectRef.value[key] = v;
744
766
  }
745
767
  }
746
768
  }));
@@ -1009,17 +1031,18 @@ function useArrayUnique(list, compareFn) {
1009
1031
  }
1010
1032
 
1011
1033
  function useCounter(initialValue = 0, options = {}) {
1034
+ let _initialValue = vueDemi.unref(initialValue);
1012
1035
  const count = vueDemi.ref(initialValue);
1013
1036
  const {
1014
- max = Infinity,
1015
- min = -Infinity
1037
+ max = Number.POSITIVE_INFINITY,
1038
+ min = Number.NEGATIVE_INFINITY
1016
1039
  } = options;
1017
1040
  const inc = (delta = 1) => count.value = Math.min(max, count.value + delta);
1018
1041
  const dec = (delta = 1) => count.value = Math.max(min, count.value - delta);
1019
1042
  const get = () => count.value;
1020
1043
  const set = (val) => count.value = Math.max(min, Math.min(max, val));
1021
- const reset = (val = initialValue) => {
1022
- initialValue = val;
1044
+ const reset = (val = _initialValue) => {
1045
+ _initialValue = val;
1023
1046
  return set(val);
1024
1047
  };
1025
1048
  return { count, inc, dec, get, set, reset };
@@ -1072,13 +1095,13 @@ function formatDate(date, formatStr, options = {}) {
1072
1095
  aa: () => meridiem(hours, minutes, true, true)
1073
1096
  };
1074
1097
  return formatStr.replace(REGEX_FORMAT, (match, $1) => {
1075
- var _a2;
1076
- return $1 || ((_a2 = matches[match]) == null ? void 0 : _a2.call(matches)) || match;
1098
+ var _a2, _b;
1099
+ return (_b = $1 != null ? $1 : (_a2 = matches[match]) == null ? void 0 : _a2.call(matches)) != null ? _b : match;
1077
1100
  });
1078
1101
  }
1079
1102
  function normalizeDate(date) {
1080
1103
  if (date === null)
1081
- return /* @__PURE__ */ new Date(NaN);
1104
+ return new Date(Number.NaN);
1082
1105
  if (date === void 0)
1083
1106
  return /* @__PURE__ */ new Date();
1084
1107
  if (date instanceof Date)
@@ -1319,7 +1342,7 @@ function watchArray(source, cb, options) {
1319
1342
  ...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)
1320
1343
  ];
1321
1344
  return vueDemi.watch(source, (newList, _, onCleanup) => {
1322
- const oldListRemains = new Array(oldList.length);
1345
+ const oldListRemains = Array.from({ length: oldList.length });
1323
1346
  const added = [];
1324
1347
  for (const obj of newList) {
1325
1348
  let found = false;
@@ -1792,6 +1815,7 @@ function whenever(source, cb, options) {
1792
1815
  exports.assert = assert;
1793
1816
  exports.autoResetRef = refAutoReset;
1794
1817
  exports.bypassFilter = bypassFilter;
1818
+ exports.camelize = camelize;
1795
1819
  exports.clamp = clamp;
1796
1820
  exports.computedEager = computedEager;
1797
1821
  exports.computedWithControl = computedWithControl;
@@ -1814,6 +1838,7 @@ exports.extendRef = extendRef;
1814
1838
  exports.formatDate = formatDate;
1815
1839
  exports.get = get;
1816
1840
  exports.hasOwn = hasOwn;
1841
+ exports.hyphenate = hyphenate;
1817
1842
  exports.identity = identity;
1818
1843
  exports.ignorableWatch = watchIgnorable;
1819
1844
  exports.increaseWithUnit = increaseWithUnit;