Skip to content

Commit

Permalink
fix: only merge text values in slateToText function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierniki committed Sep 5, 2023
1 parent 2083579 commit 8d41ba9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion utils/slateToText.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { isArray, isObject, isString, values } from "lodash"

export function slateToText(obj: unknown): string {
if (isObject(obj))
if (isObject(obj)) {
if ("text" in obj && typeof obj["text"] === "string") {
return obj["text"]
}
return values(obj)
.map(slateToText)
.reduce((acc, val) => acc + val, "")
}
if (isArray(obj)) return obj.map(slateToText).reduce((acc, val) => acc + val, "")
if (isString(obj)) return obj
return ""
Expand Down

0 comments on commit 8d41ba9

Please sign in to comment.