Skip to content

Commit

Permalink
fix(hooks/utils): move utils to hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaslz committed Mar 10, 2024
1 parent bc3eeef commit 87b981d
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/hooks/useDebounceFn/useDebounceFn.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useDebounceFn } from "..";
import { useDebounceFn } from "@/hooks";

vi.useFakeTimers();

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useDocumentTitle/useDocumentTitle.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { get } from "svelte/store";

import { useDocumentTitle } from "..";
import { useDocumentTitle } from "@/hooks";

describe("Hooks - useDocumentTitle", () => {
test("update document title", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLocalStorage/useLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { get } from "svelte/store";

import { type TsetValue, useEventListener, useState } from "@/hooks";
import { parseJSON } from "@/utils";
import { parseJSON } from "@/hooks/utils";

declare global {
interface WindowEventMap {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSessionStorage/useSessionStorage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { get } from "svelte/store";

import { type TsetValue, useEventListener, useState } from "@/hooks";
import { parseJSON } from "@/utils";
import { parseJSON } from "@/hooks/utils";

declare global {
interface WindowEventMap {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useThrottleFn/useThrottleFn.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useThrottleFn } from "..";
import { useThrottleFn } from "@/hooks";

vi.useFakeTimers();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { parseJSON } from "@/utils";
export function parseJSON<T>(value: string | null | undefined): T | undefined {
try {
return value === "undefined"
? undefined
: typeof value === "string" && value !== "true" && value !== "false"
? value
: JSON.parse(value ?? "");
} catch {
console.log("parsing error on", { value });
return undefined;
}
}

describe("Utils - parseJSON", () => {
test("parse JSON", () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 87b981d

Please sign in to comment.