@react-hive/honey-utils 4.2.0 → 4.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.
@@ -1758,7 +1758,9 @@ __webpack_require__.r(__webpack_exports__);
1758
1758
  __webpack_require__.r(__webpack_exports__);
1759
1759
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1760
1760
  /* harmony export */ getLocalStorageCapabilities: () => (/* reexport safe */ _storage__WEBPACK_IMPORTED_MODULE_0__.getLocalStorageCapabilities),
1761
- /* harmony export */ isLocalStorageReadable: () => (/* reexport safe */ _storage__WEBPACK_IMPORTED_MODULE_0__.isLocalStorageReadable)
1761
+ /* harmony export */ isLocalStorageReadable: () => (/* reexport safe */ _storage__WEBPACK_IMPORTED_MODULE_0__.isLocalStorageReadable),
1762
+ /* harmony export */ readLocalStorageJson: () => (/* reexport safe */ _storage__WEBPACK_IMPORTED_MODULE_0__.readLocalStorageJson),
1763
+ /* harmony export */ writeLocalStorageJson: () => (/* reexport safe */ _storage__WEBPACK_IMPORTED_MODULE_0__.writeLocalStorageJson)
1762
1764
  /* harmony export */ });
1763
1765
  /* harmony import */ var _storage__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./storage */ "./src/env/storage/index.ts");
1764
1766
 
@@ -1775,12 +1777,77 @@ __webpack_require__.r(__webpack_exports__);
1775
1777
  __webpack_require__.r(__webpack_exports__);
1776
1778
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1777
1779
  /* harmony export */ getLocalStorageCapabilities: () => (/* reexport safe */ _local_storage__WEBPACK_IMPORTED_MODULE_0__.getLocalStorageCapabilities),
1778
- /* harmony export */ isLocalStorageReadable: () => (/* reexport safe */ _local_storage__WEBPACK_IMPORTED_MODULE_0__.isLocalStorageReadable)
1780
+ /* harmony export */ isLocalStorageReadable: () => (/* reexport safe */ _local_storage__WEBPACK_IMPORTED_MODULE_0__.isLocalStorageReadable),
1781
+ /* harmony export */ readLocalStorageJson: () => (/* reexport safe */ _local_storage_json__WEBPACK_IMPORTED_MODULE_1__.readLocalStorageJson),
1782
+ /* harmony export */ writeLocalStorageJson: () => (/* reexport safe */ _local_storage_json__WEBPACK_IMPORTED_MODULE_1__.writeLocalStorageJson)
1779
1783
  /* harmony export */ });
1780
1784
  /* harmony import */ var _local_storage__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./local-storage */ "./src/env/storage/local-storage.ts");
1785
+ /* harmony import */ var _local_storage_json__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./local-storage-json */ "./src/env/storage/local-storage-json.ts");
1781
1786
 
1782
1787
 
1783
1788
 
1789
+
1790
+ /***/ },
1791
+
1792
+ /***/ "./src/env/storage/local-storage-json.ts"
1793
+ /*!***********************************************!*\
1794
+ !*** ./src/env/storage/local-storage-json.ts ***!
1795
+ \***********************************************/
1796
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1797
+
1798
+ __webpack_require__.r(__webpack_exports__);
1799
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1800
+ /* harmony export */ readLocalStorageJson: () => (/* binding */ readLocalStorageJson),
1801
+ /* harmony export */ writeLocalStorageJson: () => (/* binding */ writeLocalStorageJson)
1802
+ /* harmony export */ });
1803
+ /* harmony import */ var _json__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ~/json */ "./src/json/index.ts");
1804
+
1805
+ /**
1806
+ * Reads the value stored as JSON under a key in `localStorage`.
1807
+ *
1808
+ * Never throws: storage that cannot be read at all (SSR, disabled storage, sandboxed iframes, strict
1809
+ * privacy modes) reads as nothing stored, as does a value that is not JSON.
1810
+ *
1811
+ * The value is only cast to `Value`, not checked against it - something stored by an older version
1812
+ * of the app, or by hand, can be of any shape, so check it before relying on it.
1813
+ *
1814
+ * @param key - The `localStorage` key to read.
1815
+ *
1816
+ * @returns The parsed value, or `null` when nothing is stored under the key, what is stored is not
1817
+ * valid JSON, or storage cannot be read.
1818
+ */
1819
+ const readLocalStorageJson = (key) => {
1820
+ try {
1821
+ const value = window.localStorage.getItem(key);
1822
+ return value === null ? null : (0,_json__WEBPACK_IMPORTED_MODULE_0__.parseJson)(value);
1823
+ }
1824
+ catch {
1825
+ return null;
1826
+ }
1827
+ };
1828
+ /**
1829
+ * Stores a value under a key in `localStorage`, as JSON.
1830
+ *
1831
+ * Never throws: a write that fails - storage full (`QuotaExceededError`), Safari Private Mode,
1832
+ * security-restricted contexts, SSR, or a value `JSON.stringify()` cannot serialise (a circular
1833
+ * reference, a `BigInt`) - reports `false` instead.
1834
+ *
1835
+ * @param key - The `localStorage` key to write.
1836
+ * @param value - Any JSON-serialisable value.
1837
+ *
1838
+ * @returns `true` once the value is stored, `false` when it could not be.
1839
+ */
1840
+ const writeLocalStorageJson = (key, value) => {
1841
+ try {
1842
+ window.localStorage.setItem(key, JSON.stringify(value));
1843
+ return true;
1844
+ }
1845
+ catch {
1846
+ return false;
1847
+ }
1848
+ };
1849
+
1850
+
1784
1851
  /***/ },
1785
1852
 
1786
1853
  /***/ "./src/env/storage/local-storage.ts"
@@ -3982,6 +4049,7 @@ __webpack_require__.r(__webpack_exports__);
3982
4049
  /* harmony export */ parseJson: () => (/* reexport safe */ _json__WEBPACK_IMPORTED_MODULE_17__.parseJson),
3983
4050
  /* harmony export */ pipe: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.pipe),
3984
4051
  /* harmony export */ readFilesFromDataTransfer: () => (/* reexport safe */ _file__WEBPACK_IMPORTED_MODULE_5__.readFilesFromDataTransfer),
4052
+ /* harmony export */ readLocalStorageJson: () => (/* reexport safe */ _env__WEBPACK_IMPORTED_MODULE_4__.readLocalStorageJson),
3985
4053
  /* harmony export */ reduceAsync: () => (/* reexport safe */ _async__WEBPACK_IMPORTED_MODULE_2__.reduceAsync),
3986
4054
  /* harmony export */ replaceHistorySearchParams: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.replaceHistorySearchParams),
3987
4055
  /* harmony export */ resolveAxisDelta: () => (/* reexport safe */ _intersection__WEBPACK_IMPORTED_MODULE_10__.resolveAxisDelta),
@@ -3998,7 +4066,8 @@ __webpack_require__.r(__webpack_exports__);
3998
4066
  /* harmony export */ toKebabCase: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_13__.toKebabCase),
3999
4067
  /* harmony export */ toggleArrayItem: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.toggleArrayItem),
4000
4068
  /* harmony export */ traverseFileSystemDirectory: () => (/* reexport safe */ _file__WEBPACK_IMPORTED_MODULE_5__.traverseFileSystemDirectory),
4001
- /* harmony export */ unique: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.unique)
4069
+ /* harmony export */ unique: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.unique),
4070
+ /* harmony export */ writeLocalStorageJson: () => (/* reexport safe */ _env__WEBPACK_IMPORTED_MODULE_4__.writeLocalStorageJson)
4002
4071
  /* harmony export */ });
4003
4072
  /* harmony import */ var _a11y__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./a11y */ "./src/a11y/index.ts");
4004
4073
  /* harmony import */ var _array__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./array */ "./src/array/index.ts");