mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-12-06 19:03:43 +00:00
Address terminal encoding review feedback
This commit is contained in:
1 parent
b7491fd05a
commit
2e9c021e68
7 files changed
+38
-7
No files matched your search
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
createStoredStringSyncHandlers,
|
||||
readOptionalStoredStringValue,
|
||||
readStoredStringValue,
|
||||
resolveStoredStringUpdate,
|
||||
} from "./useStoredString.ts";
|
||||
@@ -85,12 +86,15 @@ test("stored string helpers read fallback and resolve updater-style toggles", (t
|
||||
|
||||
const storageKey = "netcatty:test-mode";
|
||||
assert.equal(readStoredStringValue(storageKey, "edit", isTestMode), "edit");
|
||||
assert.equal(readOptionalStoredStringValue(storageKey, isTestMode), null);
|
||||
|
||||
env.storage.setItem(storageKey, "preview");
|
||||
assert.equal(readStoredStringValue(storageKey, "edit", isTestMode), "preview");
|
||||
assert.equal(readOptionalStoredStringValue(storageKey, isTestMode), "preview");
|
||||
|
||||
env.storage.setItem(storageKey, "invalid");
|
||||
assert.equal(readStoredStringValue(storageKey, "edit", isTestMode), "edit");
|
||||
assert.equal(readOptionalStoredStringValue(storageKey, isTestMode), null);
|
||||
|
||||
assert.equal(resolveStoredStringUpdate<TestMode>("edit", "preview"), "preview");
|
||||
assert.equal(
|
||||
|
||||
@@ -18,6 +18,15 @@ export const readStoredStringValue = <T extends string>(
|
||||
return isAllowedValue(stored) ? stored : fallback;
|
||||
};
|
||||
|
||||
export const readOptionalStoredStringValue = <T extends string>(
|
||||
storageKey: string,
|
||||
isAllowedValue: (value: string | null) => value is T,
|
||||
): T | null => {
|
||||
if (!canUseLocalStorage()) return null;
|
||||
const stored = localStorageAdapter.readString(storageKey);
|
||||
return isAllowedValue(stored) ? stored : null;
|
||||
};
|
||||
|
||||
export const resolveStoredStringUpdate = <T extends string>(
|
||||
currentValue: T,
|
||||
nextValue: T | ((currentValue: T) => T),
|
||||
|
||||
Reference in new issue
Block a user