Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanniser committed Dec 7, 2024
1 parent e8c9eca commit 176b88b
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 145 deletions.
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## This PR:
<!-- describe what changes were made -->

<!-- describe what changes were made -->

- [ ] (if ready to be merged) Yes I have made a changeset
- [ ] (if ready to be merged) Yes I have made a changeset

<!-- make sure you made a change set!! -->

Expand Down
1 change: 0 additions & 1 deletion examples/appdir/_next-typesafe-url_.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// prettier-ignore
/* eslint-disable */


declare module "@@@next-typesafe-url" {
import type { InferRoute, StaticRoute } from "next-typesafe-url";

Expand Down
1 change: 0 additions & 1 deletion examples/pagesdir/_next-typesafe-url_.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// prettier-ignore
/* eslint-disable */


declare module "@@@next-typesafe-url" {
import type { InferRoute, StaticRoute } from "next-typesafe-url";

Expand Down
4 changes: 2 additions & 2 deletions examples/pagesdir/src/pages/[slug]/[...foo].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ const Page: NextPage = () => {
const [input, setInput] = useState("");

const { data: routeData, error: routeError } = useRouteParams(
Route.routeParams
Route.routeParams,
);

const { data: searchData, error: searchError } = useSearchParams(
Route.searchParams
Route.searchParams,
);

return (
Expand Down
2 changes: 1 addition & 1 deletion examples/pagesdir/src/pages/[slug]/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ServerSideProps = RouterOutputs["/[slug]/server"]["searchParams"] &
RouterOutputs["/[slug]/server"]["routeParams"];

export const getServerSideProps: GetServerSideProps<ServerSideProps> = async (
context
context,
) => {
await Promise.resolve();
const routeParams = parseServerSideParams({
Expand Down
4 changes: 2 additions & 2 deletions examples/pagesdir/src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Html, Head, Main, NextScript } from 'next/document'
import { Html, Head, Main, NextScript } from "next/document";

export default function Document() {
return (
Expand All @@ -9,5 +9,5 @@ export default function Document() {
<NextScript />
</body>
</Html>
)
);
}
2 changes: 1 addition & 1 deletion packages/next-typesafe-url/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ if (require.main === module) {
const absoluteOutputPath = path.join(process.cwd(), outputPath);
const relativePathFromOutputToSrc = path.relative(
path.dirname(absoluteOutputPath),
absoluteSrcPath
absoluteSrcPath,
);

const appPath = path.join(absoluteSrcPath, "app");
Expand Down
8 changes: 4 additions & 4 deletions packages/next-typesafe-url/src/generateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function getPAGESRoutesWithExportedRoute({

const fileContent = fs.readFileSync(fullPath, "utf8");
const hasExportedRouteType = /export\s+type\s+RouteType\b/.test(
fileContent
fileContent,
);

let routePath = fullPath
Expand Down Expand Up @@ -123,7 +123,7 @@ export function getAPPRoutesWithExportedRoute({
}

const routeTypePaths = ["ts", "tsx"].map((ext) =>
path.join(dir, `routeType.${ext}`)
path.join(dir, `routeType.${ext}`),
);
const didAddRoute = routeTypePaths.reduce((didAdd, routeTypePath) => {
// Avoid adding the same route twice
Expand Down Expand Up @@ -172,7 +172,7 @@ export function generateTypesFile({
const pathAfterSrc = path.join(
type,
route === "/" ? "" : route,
type === "app" ? "routeType" : ""
type === "app" ? "routeType" : "",
);
const finalRelativePath = path
.join(paths.relativePathFromOutputToSrc, pathAfterSrc)
Expand All @@ -188,7 +188,7 @@ export function generateTypesFile({

const staticRoutesDeclarations = [
...allDoesntHaveRoute_app.map(
(route) => ` "${route.replace(/\/\([^()]+\)/g, "")}": StaticRoute;`
(route) => ` "${route.replace(/\/\([^()]+\)/g, "")}": StaticRoute;`,
),
...allDoesntHaveRoute_pages.map((route) => ` "${route}": StaticRoute;`),
].join("\n ");
Expand Down
4 changes: 2 additions & 2 deletions packages/next-typesafe-url/src/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export { parseServerSideParams } from "./utils";
* const { data, isLoading, isError, error } = routeParams;
*/
export function useRouteParams<T extends z.AnyZodObject>(
validator: T
validator: T,
): UseParamsResult<T> {
const router = useRouter();
const [isError, setIsError] = useState(false);
Expand Down Expand Up @@ -89,7 +89,7 @@ export function useRouteParams<T extends z.AnyZodObject>(
* const { data, isLoading, isError, error } = searchParams;
*/
export function useSearchParams<T extends z.AnyZodObject>(
searchValidator: T
searchValidator: T,
): UseParamsResult<T> {
const router = useRouter();
const [isError, setIsError] = useState(false);
Expand Down
20 changes: 10 additions & 10 deletions packages/next-typesafe-url/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function encodeValue(value: unknown): string {
} else {
// if its anything else, throw
throw new Error(
"only null, non-empty string, number, boolean, array, and object are able to be encoded"
"only null, non-empty string, number, boolean, array, and object are able to be encoded",
);
}
}
Expand All @@ -45,7 +45,7 @@ export function encodeValue(value: unknown): string {
*
*/
export function generateSearchParamStringFromObj(
obj: Record<string, unknown>
obj: Record<string, unknown>,
): string {
// array to collect the encoded params
const params: string[] = [];
Expand Down Expand Up @@ -88,7 +88,7 @@ export function decodeAndTryJSONParse(value: string | undefined): unknown {
* If passed a string, calls decodeAndTryJSONParse on it.
*/
export function parseOrMapParse(
obj: string | string[] | undefined
obj: string | string[] | undefined,
): unknown | unknown[] {
if (Array.isArray(obj)) {
return obj.map(decodeAndTryJSONParse);
Expand All @@ -102,7 +102,7 @@ export function parseOrMapParse(
* Maps over the object, calling parseOrMapParse on each value.
*/
export function parseMapObject(
obj: Record<string, string | string[] | undefined>
obj: Record<string, string | string[] | undefined>,
): Record<string, unknown | unknown[]> {
const result: Record<string, unknown | unknown[]> = {};

Expand All @@ -125,7 +125,7 @@ export function parseMapObject(
* @example handleSearchParamMultipleKeys(new URLSearchParams("?foo=bar&baz&baz=lux&baz=flux")) -> { foo: "bar", baz: ["lux", "flux"] }
*/
export function handleSearchParamMultipleKeys(
urlParams: URLSearchParams | ReadonlyURLSearchParams
urlParams: URLSearchParams | ReadonlyURLSearchParams,
): Record<string, string | string[] | undefined> {
const result: Record<string, string | string[] | undefined> = {};

Expand Down Expand Up @@ -162,7 +162,7 @@ export function handleSearchParamMultipleKeys(
* @example parseObjectFromParamString("?foo=true&baz=56&bar=hello") -> { foo: true, baz: 56, bar: "hello" }
*/
export function parseObjectFromParamString(
paramString: string
paramString: string,
): Record<string, unknown> {
const params = new URLSearchParams(paramString);
const handledParams = handleSearchParamMultipleKeys(params);
Expand All @@ -176,7 +176,7 @@ export function parseObjectFromParamString(
* @example parseObjectFromReadonlyURLParams(new ReadonlyURLSearchParams("?foo=true&baz=56&bar=hello")) -> { foo: true, baz: 56, bar: "hello" }
*/
export function parseObjectFromReadonlyURLParams(
params: ReadonlyURLSearchParams
params: ReadonlyURLSearchParams,
): Record<string, unknown> {
const handledParams = handleSearchParamMultipleKeys(params);
return parseMapObject(handledParams);
Expand All @@ -189,7 +189,7 @@ export function parseObjectFromReadonlyURLParams(
* @example parseObjectFromStringRecord({ foo: "true", baz: "56", bar: "hello" }) -> { foo: true, baz: 56, bar: "hello" }
*/
export function parseObjectFromStringRecord(
params: Record<string, string | string[] | undefined>
params: Record<string, string | string[] | undefined>,
): Record<string, unknown> {
return parseMapObject(params);
}
Expand Down Expand Up @@ -259,7 +259,7 @@ export function parseSegment(segment: string): Segment {
*/
export function encodeAndFillRoute(
route: string,
routeParams: Record<string, unknown>
routeParams: Record<string, unknown>,
): string {
// split the route into its segments
const segments = route.split("/");
Expand Down Expand Up @@ -293,7 +293,7 @@ export function encodeAndFillRoute(
parts.push(encodeValue(paramValue));
} else {
throw new Error(
`Missing value for catch-all segment "${segment.value}"`
`Missing value for catch-all segment "${segment.value}"`,
);
}
} else if (segment.type === "optionalCatchAll") {
Expand Down
Loading

0 comments on commit 176b88b

Please sign in to comment.