Comparing version 1.2.0 to 1.2.1
@@ -1,2 +0,2 @@ | ||
export declare const useLocalStorage: <T = StoredData>(key: StorageKey, initialValue?: T | undefined, version?: number | undefined) => { | ||
export declare const useLocalStorage: <T = StoredData>(key: StorageKey, initialValue?: T | undefined, version?: Version | undefined) => { | ||
mergeState: (state: Record<string, unknown>) => void; | ||
@@ -7,5 +7,5 @@ resetValue: () => void; | ||
value?: T | undefined; | ||
version?: number | undefined; | ||
version?: Version | undefined; | ||
}; | ||
export declare const useSessionStorage: <T = StoredData>(key: StorageKey, initialValue?: T | undefined, version?: number | undefined) => { | ||
export declare const useSessionStorage: <T = StoredData>(key: StorageKey, initialValue?: T | undefined, version?: Version | undefined) => { | ||
mergeState: (state: Record<string, unknown>) => void; | ||
@@ -16,4 +16,4 @@ resetValue: () => void; | ||
value?: T | undefined; | ||
version?: number | undefined; | ||
version?: Version | undefined; | ||
}; | ||
//# sourceMappingURL=useStorage.d.ts.map |
@@ -5,3 +5,3 @@ export declare const isServerSide: () => boolean; | ||
export declare const safeGetStorageValue: <T>(storageType: StorageType, key: string) => StorageStructure<T>; | ||
export declare const safeSetStorageValue: <T>(storageType: StorageType, key: string, value: T, ts?: Date | undefined, version?: number | undefined) => void; | ||
export declare const safeSetStorageValue: <T>(storageType: StorageType, key: string, value: T, ts?: Date | undefined, version?: Version | undefined) => void; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -21,7 +21,11 @@ "use strict"; | ||
var timestamp = new Date(ts); | ||
var versionNumber = typeof version !== 'undefined' ? Number(version) : undefined; | ||
var parsedVersion = typeof version !== 'undefined' | ||
? isNaN(Number(version)) | ||
? version | ||
: Number(version) | ||
: undefined; | ||
parsedValue = { | ||
data: data, | ||
ts: timestamp, | ||
version: versionNumber, | ||
version: parsedVersion, | ||
}; | ||
@@ -28,0 +32,0 @@ } |
@@ -8,3 +8,3 @@ { | ||
"license": "MIT", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"main": "dist/index.js", | ||
@@ -46,6 +46,6 @@ "types": "dist/index.d.ts", | ||
"@testing-library/react-hooks": "7.0.2", | ||
"@types/jest": "27.0.1", | ||
"@types/react": "17.0.19", | ||
"@typescript-eslint/eslint-plugin": "4.30.0", | ||
"@typescript-eslint/parser": "4.30.0", | ||
"@types/jest": "27.0.2", | ||
"@types/react": "17.0.24", | ||
"@typescript-eslint/eslint-plugin": "4.32.0", | ||
"@typescript-eslint/parser": "4.32.0", | ||
"eslint": "7.32.0", | ||
@@ -56,10 +56,10 @@ "eslint-config-prettier": "8.3.0", | ||
"husky": "7.0.2", | ||
"jest": "27.1.0", | ||
"jest-localstorage-mock": "2.4.17", | ||
"jest": "27.2.4", | ||
"jest-localstorage-mock": "2.4.18", | ||
"lint-staged": "11.1.2", | ||
"mockdate": "3.0.5", | ||
"prettier": "2.3.2", | ||
"prettier": "2.4.1", | ||
"react-test-renderer": "17.0.2", | ||
"ts-jest": "27.0.5", | ||
"typescript": "4.4.2" | ||
"typescript": "4.4.3" | ||
}, | ||
@@ -66,0 +66,0 @@ "peerDependencies": { |
@@ -94,3 +94,3 @@ # Haversack | ||
You can pass an optional number to the hook to apply a specific version to your stored data. If the structure of your data changes, users who have stored data from the previous structure can experience issues when the incompatible data is applied to the new structure. Think of the `version` param as a schema version for the data. | ||
You can pass an optional number or string to the hook to apply a specific version to your stored data. If the structure of your data changes, users who have stored data from the previous structure can experience issues when the incompatible data is applied to the new structure. Think of the `version` param as a schema version for the data. | ||
@@ -113,4 +113,6 @@ ```jsx | ||
There is no enforcement of standards on the version number—Haversack will do a simple `===` equality check to determine if the version number has changed. Any change in version number, forward or backward, will cause the stored data to be deleted to await new data with the current version number. If previous data was stored without a version number, the data will be invalidated when a version number is introduced. | ||
There is no enforcement of standards on the version—Haversack will do a simple `===` equality check to determine if the version has changed. Any change in version number, forward or backward, will cause the stored data to be deleted to await new data with the current version number. If previous data was stored without a version number, the data will be invalidated when a version number is introduced. | ||
Using a string for the version is especially useful if you want to create a hash of a data set to dynamically determine whether or not to invalidate the cache. | ||
## Reset the Stored Value | ||
@@ -117,0 +119,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23632
173
211