Skip to content

Commit

Permalink
docs(changeset): flatKeys | Move from hotscript to type-fest utilit…
Browse files Browse the repository at this point in the history
…y types
  • Loading branch information
Maggi64 committed Nov 22, 2024
1 parent 57ec52e commit 5944656
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-ducks-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"moderndash": minor
---

`flatKeys` | Move from hotscript to type-fest utility types
6 changes: 3 additions & 3 deletions package/src/object/flatKeys.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { GenericObject } from "@type/GenericObject";
import type { Call, Objects } from "hotscript";
import type { Paths } from "type-fest";

import { isPlainObject } from "@validate/isPlainObject.js";

type StringIfNever<Type> = [Type] extends [never] ? string : Type;
type Paths<TObj> = StringIfNever<Call<Objects.AllPaths, TObj>>;
type PathOrString<TObj> = StringIfNever<Paths<TObj, { bracketNotation: true, maxRecursionDepth: 20 }>>;

/**
* Flattens an object into a single level object.
Expand All @@ -19,7 +19,7 @@ type Paths<TObj> = StringIfNever<Call<Objects.AllPaths, TObj>>;
* @returns A new object with flattened keys.
*/

export function flatKeys<TObj extends GenericObject>(obj: TObj): Record<Paths<TObj>, unknown> {
export function flatKeys<TObj extends GenericObject>(obj: TObj): Record<PathOrString<TObj>, unknown> {
const flatObject: Record<string, unknown> = {};

for (const [key, value] of Object.entries(obj)) {
Expand Down

0 comments on commit 5944656

Please sign in to comment.