Skip to content

Commit ddc684d

Browse files
committed
refactor(@typed-storage/core): fix all linting errors
1 parent 528c1c5 commit ddc684d

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

packages/core/src/define-storage.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from "zod"
22
import { defineStorage } from "./define-storage.js"
3-
import { test, assertType, expectTypeOf } from "vitest"
3+
import { test, assertType } from "vitest"
44

55
test("it's not possible to set a value that violates the schema", () => {
66
// ARRANGE

packages/core/src/define-storage.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, test, expect, describe } from "vitest"
1+
import { beforeEach, test, expect } from "vitest"
22
import { defineStorage } from "./define-storage.js"
33
import { z } from "zod"
44

packages/core/src/define-storage.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ export function defineStorage<T extends Record<string, StandardSchemaV1>>(
3434
let parsedValue: unknown
3535
try {
3636
parsedValue = JSON.parse(item)
37-
} catch (e) {
37+
} catch {
3838
if (item === "true") parsedValue = true
3939
else if (item === "false") parsedValue = false
40-
else if (!isNaN(Number(item))) parsedValue = Number(item)
41-
else parsedValue = item
40+
else if (Number.isNaN(Number(item))) {
41+
parsedValue = item
42+
} else {
43+
parsedValue = Number(item)
44+
}
4245
}
4346

4447
try {
@@ -65,12 +68,10 @@ export function defineStorage<T extends Record<string, StandardSchemaV1>>(
6568
const schemaForKey = schema[key] as StandardSchemaV1
6669
const validatedValue = standardValidate(schemaForKey, value)
6770

68-
let stringifiedValue: string
69-
if (typeof validatedValue === "object" && validatedValue !== null) {
70-
stringifiedValue = JSON.stringify(validatedValue)
71-
} else {
72-
stringifiedValue = String(validatedValue)
73-
}
71+
const stringifiedValue =
72+
typeof validatedValue === "object" && validatedValue !== null
73+
? JSON.stringify(validatedValue)
74+
: String(validatedValue)
7475

7576
localStorage.setItem(key as string, stringifiedValue)
7677
}

0 commit comments

Comments
 (0)