diff --git a/CHANGELOG.md b/CHANGELOG.md index f759baf..d9d3a36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # deverything +## 1.11.2 + +### Patch Changes + +- small patch on helper and 2 type renames + ## 1.11.1 ### Patch Changes diff --git a/README.md b/README.md index c8fb20e..6fd643b 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ These functions are optimized for low entropy random data generation useful for - `Coords` - `DateLike` -- `DefinedKeys<>` +- `Defined` - `Dimensions` - `HashMap<>` - `BoolMap` @@ -204,10 +204,10 @@ These functions are optimized for low entropy random data generation useful for - `ObjectValue<>` - `ObjectValues<>` - ⭐ `PlainObject` use this instead of `Record<,>` or `extends object`, also makes sure it's not an array -- `PickRequired<>` +- `PickDefined` +- `PickRequired` - `PlainKey` - `Point` -- `Required<>` - `VoidFn` ## Development diff --git a/package.json b/package.json index 5e681da..542c846 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "deverything", - "version": "1.11.1", + "version": "1.11.2", "description": "Everything you need for Dev", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/src/helpers/setUrlSearchParams.test.ts b/src/helpers/setUrlSearchParams.test.ts index e1c46cf..77a52a9 100644 --- a/src/helpers/setUrlSearchParams.test.ts +++ b/src/helpers/setUrlSearchParams.test.ts @@ -21,8 +21,14 @@ describe("setUrlSearchParams", () => { "/signin?in=&UPPER=CASE#sec" ); expect( - setUrlSearchParams("/signin?in#sec", { and: "&", equals: "=" }) - ).toBe("/signin?in=&and=%26&equals=%3D#sec"); + setUrlSearchParams("/signin?in#sec", { + and: "&", + equals: "=", + filter: { date: "2024" }, + }) + ).toBe( + "/signin?in=&and=%26&equals=%3D&filter=%7B%22date%22%3A%222024%22%7D#sec" + ); }); test("ip", () => { diff --git a/src/helpers/setUrlSearchParams.ts b/src/helpers/setUrlSearchParams.ts index 567ed36..f3c7e9d 100644 --- a/src/helpers/setUrlSearchParams.ts +++ b/src/helpers/setUrlSearchParams.ts @@ -1,8 +1,12 @@ -import { Maybe } from "../types"; +import { Maybe, PlainObject } from "../types"; +import { isObject } from "../validators"; export const setUrlSearchParams = ( currentURL: string, - searchParams: Record> = {} + searchParams: Record< + string, + Maybe + > = {} ) => { const isRelativeUrl = currentURL.startsWith("/"); const url = new URL( @@ -12,7 +16,10 @@ export const setUrlSearchParams = ( Object.entries(searchParams).forEach(([paramKey, paramValue]) => { if (paramValue === null || paramValue === undefined) return; - url.searchParams.set(paramKey, paramValue.toString()); + + if (isObject(paramValue)) + url.searchParams.set(paramKey, JSON.stringify(paramValue)); + else url.searchParams.set(paramKey, paramValue.toString()); }); if (isRelativeUrl) { diff --git a/src/types/DefinedKeys.ts b/src/types/Defined.ts similarity index 60% rename from src/types/DefinedKeys.ts rename to src/types/Defined.ts index 23a7dbd..f44428e 100644 --- a/src/types/DefinedKeys.ts +++ b/src/types/Defined.ts @@ -1,5 +1,5 @@ /** - * Makes all keys in required and removes undefined and null from the value types. + * Makes all keys required and removes undefined and null from the value types. * @example * type Example = { * a: string; @@ -7,7 +7,7 @@ * c?: string; * d?: number | null; * }; - * type Result = DefinedKeys; + * type Result = Defined; * { * a: string, * b: string, @@ -15,6 +15,6 @@ * d: number * } */ -export type DefinedKeys = { +export type Defined = { [P in keyof T]-?: NonNullable; }; diff --git a/src/types/PickDefined.ts b/src/types/PickDefined.ts new file mode 100644 index 0000000..5d42a56 --- /dev/null +++ b/src/types/PickDefined.ts @@ -0,0 +1,30 @@ +import { Defined } from "./Defined"; + +/** + * Makes picked keys required and defined. + * @example + * type Example = { + * a: string; + * b: string | undefined; + * c?: string; + * d?: number | null; + * }; + * type Result = PickDefined; + * { + * a: string; + * b: string | undefined; + * d: number | null; + * } + */ +export type PickDefined = Pick, K>; + +// Test +// type Example = { +// a: string; +// b: string | undefined; +// c?: string; +// d?: number | null; +// e: never; +// }; + +// type Result = PickDefined; diff --git a/src/types/PickRequired.ts b/src/types/PickRequired.ts index 13f0652..9a9a361 100644 --- a/src/types/PickRequired.ts +++ b/src/types/PickRequired.ts @@ -7,11 +7,22 @@ * c?: string; * d?: number | null; * }; - * type Result = PickRequired; + * type Result = PickRequired; * { * a: string; * b: string | undefined; * d: number | null; * } */ -export type PickRequired = Required>; +export type PickRequired = Pick, K>; + +// Test +// type Example = { +// a: string; +// b: string | undefined; +// c?: string; +// d?: number | null; +// e: never; +// }; + +// type Result = PickRequired; diff --git a/src/types/index.ts b/src/types/index.ts index 4ee3652..036ddf2 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,6 +1,6 @@ export * from "./Coords"; export * from "./Date"; -export * from "./DefinedKeys"; +export * from "./Defined"; export * from "./Dimensions"; export * from "./Function"; export * from "./HashMap"; @@ -8,6 +8,8 @@ export * from "./Matrix"; export * from "./Maybe"; export * from "./NonUndefined"; export * from "./Object"; +export * from "./PickDefined"; +export * from "./PickRequired"; export * from "./PickRequired"; export * from "./Point"; export * from "./PrismaSelect";