@react-hive/honey-utils 4.1.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.
- package/README.md +48 -1
- package/dist/README.md +48 -1
- package/dist/env/storage/index.d.ts +1 -0
- package/dist/env/storage/local-storage-json.d.ts +29 -0
- package/dist/guards.d.ts +23 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.dev.cjs +97 -3
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.dev.cjs
CHANGED
|
@@ -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"
|
|
@@ -2440,6 +2507,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2440
2507
|
/* harmony export */ isDecimal: () => (/* binding */ isDecimal),
|
|
2441
2508
|
/* harmony export */ isDefined: () => (/* binding */ isDefined),
|
|
2442
2509
|
/* harmony export */ isEmptyObject: () => (/* binding */ isEmptyObject),
|
|
2510
|
+
/* harmony export */ isEnumValue: () => (/* binding */ isEnumValue),
|
|
2443
2511
|
/* harmony export */ isError: () => (/* binding */ isError),
|
|
2444
2512
|
/* harmony export */ isFiniteNumber: () => (/* binding */ isFiniteNumber),
|
|
2445
2513
|
/* harmony export */ isInteger: () => (/* binding */ isInteger),
|
|
@@ -2663,6 +2731,29 @@ const isInteger = (value) => isNumber(value) && Number.isInteger(value);
|
|
|
2663
2731
|
* ```
|
|
2664
2732
|
*/
|
|
2665
2733
|
const isDecimal = (value) => isFiniteNumber(value) && !Number.isInteger(value);
|
|
2734
|
+
/**
|
|
2735
|
+
* Checks if a value is one of a string enum's values.
|
|
2736
|
+
*
|
|
2737
|
+
* @template Value - The type of the enum's values.
|
|
2738
|
+
*
|
|
2739
|
+
* @param enumObject - The enum, or any object whose values are the allowed strings.
|
|
2740
|
+
* @param value - The value to check.
|
|
2741
|
+
*
|
|
2742
|
+
* @returns `true` if the value is one of the enum's values; otherwise, `false`.
|
|
2743
|
+
*
|
|
2744
|
+
* @example
|
|
2745
|
+
* ```ts
|
|
2746
|
+
* enum Fruit {
|
|
2747
|
+
* APPLE = 'apple',
|
|
2748
|
+
* PEAR = 'pear',
|
|
2749
|
+
* }
|
|
2750
|
+
*
|
|
2751
|
+
* isEnumValue(Fruit, 'apple'); // true
|
|
2752
|
+
* isEnumValue(Fruit, 'APPLE'); // false
|
|
2753
|
+
* isEnumValue(Fruit, null); // false
|
|
2754
|
+
* ```
|
|
2755
|
+
*/
|
|
2756
|
+
const isEnumValue = (enumObject, value) => Object.values(enumObject).includes(value);
|
|
2666
2757
|
|
|
2667
2758
|
|
|
2668
2759
|
/***/ },
|
|
@@ -3928,6 +4019,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3928
4019
|
/* harmony export */ isDefined: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_8__.isDefined),
|
|
3929
4020
|
/* harmony export */ isEmptyArray: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.isEmptyArray),
|
|
3930
4021
|
/* harmony export */ isEmptyObject: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_8__.isEmptyObject),
|
|
4022
|
+
/* harmony export */ isEnumValue: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_8__.isEnumValue),
|
|
3931
4023
|
/* harmony export */ isError: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_8__.isError),
|
|
3932
4024
|
/* harmony export */ isFile: () => (/* reexport safe */ _file__WEBPACK_IMPORTED_MODULE_5__.isFile),
|
|
3933
4025
|
/* harmony export */ isFiniteNumber: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_8__.isFiniteNumber),
|
|
@@ -3957,6 +4049,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3957
4049
|
/* harmony export */ parseJson: () => (/* reexport safe */ _json__WEBPACK_IMPORTED_MODULE_17__.parseJson),
|
|
3958
4050
|
/* harmony export */ pipe: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.pipe),
|
|
3959
4051
|
/* harmony export */ readFilesFromDataTransfer: () => (/* reexport safe */ _file__WEBPACK_IMPORTED_MODULE_5__.readFilesFromDataTransfer),
|
|
4052
|
+
/* harmony export */ readLocalStorageJson: () => (/* reexport safe */ _env__WEBPACK_IMPORTED_MODULE_4__.readLocalStorageJson),
|
|
3960
4053
|
/* harmony export */ reduceAsync: () => (/* reexport safe */ _async__WEBPACK_IMPORTED_MODULE_2__.reduceAsync),
|
|
3961
4054
|
/* harmony export */ replaceHistorySearchParams: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_3__.replaceHistorySearchParams),
|
|
3962
4055
|
/* harmony export */ resolveAxisDelta: () => (/* reexport safe */ _intersection__WEBPACK_IMPORTED_MODULE_10__.resolveAxisDelta),
|
|
@@ -3973,7 +4066,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3973
4066
|
/* harmony export */ toKebabCase: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_13__.toKebabCase),
|
|
3974
4067
|
/* harmony export */ toggleArrayItem: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.toggleArrayItem),
|
|
3975
4068
|
/* harmony export */ traverseFileSystemDirectory: () => (/* reexport safe */ _file__WEBPACK_IMPORTED_MODULE_5__.traverseFileSystemDirectory),
|
|
3976
|
-
/* 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)
|
|
3977
4071
|
/* harmony export */ });
|
|
3978
4072
|
/* harmony import */ var _a11y__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./a11y */ "./src/a11y/index.ts");
|
|
3979
4073
|
/* harmony import */ var _array__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./array */ "./src/array/index.ts");
|