Skip to content

Commit

Permalink
fix(html): Remove circular dependencies in hono/html (#2143)
Browse files Browse the repository at this point in the history
* refactor: Refactor helper/html and utils/html to remove circular dependencies

* chore: denoify

* chore: reformat code

* chore: denoify
  • Loading branch information
javascripter authored Feb 3, 2024
1 parent f2ec8d4 commit f44c705
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
17 changes: 3 additions & 14 deletions deno_dist/helper/html/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { escapeToBuffer, stringBufferToString } from '../../utils/html.ts'
import type {
StringBuffer,
HtmlEscaped,
HtmlEscapedString,
HtmlEscapedCallback,
} from '../../utils/html.ts'
import { escapeToBuffer, stringBufferToString, raw } from '../../utils/html.ts'
import type { StringBuffer, HtmlEscaped, HtmlEscapedString } from '../../utils/html.ts'

export const raw = (value: unknown, callbacks?: HtmlEscapedCallback[]): HtmlEscapedString => {
const escapedString = new String(value) as HtmlEscapedString
escapedString.isEscaped = true
escapedString.callbacks = callbacks

return escapedString
}
export { raw }

export const html = (
strings: TemplateStringsArray,
Expand Down
8 changes: 7 additions & 1 deletion deno_dist/utils/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export type HtmlEscapedString = string & HtmlEscaped
*/
export type StringBuffer = (string | Promise<string>)[]

import { raw } from '../helper/html/index.ts'
export const raw = (value: unknown, callbacks?: HtmlEscapedCallback[]): HtmlEscapedString => {
const escapedString = new String(value) as HtmlEscapedString
escapedString.isEscaped = true
escapedString.callbacks = callbacks

return escapedString
}

// The `escapeToBuffer` implementation is based on code from the MIT licensed `react-dom` package.
// https://github.com/facebook/react/blob/main/packages/react-dom-bindings/src/server/escapeTextForBrowser.js
Expand Down
17 changes: 3 additions & 14 deletions src/helper/html/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { escapeToBuffer, stringBufferToString } from '../../utils/html'
import type {
StringBuffer,
HtmlEscaped,
HtmlEscapedString,
HtmlEscapedCallback,
} from '../../utils/html'
import { escapeToBuffer, stringBufferToString, raw } from '../../utils/html'
import type { StringBuffer, HtmlEscaped, HtmlEscapedString } from '../../utils/html'

export const raw = (value: unknown, callbacks?: HtmlEscapedCallback[]): HtmlEscapedString => {
const escapedString = new String(value) as HtmlEscapedString
escapedString.isEscaped = true
escapedString.callbacks = callbacks

return escapedString
}
export { raw }

export const html = (
strings: TemplateStringsArray,
Expand Down
8 changes: 7 additions & 1 deletion src/utils/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export type HtmlEscapedString = string & HtmlEscaped
*/
export type StringBuffer = (string | Promise<string>)[]

import { raw } from '../helper/html'
export const raw = (value: unknown, callbacks?: HtmlEscapedCallback[]): HtmlEscapedString => {
const escapedString = new String(value) as HtmlEscapedString
escapedString.isEscaped = true
escapedString.callbacks = callbacks

return escapedString
}

// The `escapeToBuffer` implementation is based on code from the MIT licensed `react-dom` package.
// https://github.com/facebook/react/blob/main/packages/react-dom-bindings/src/server/escapeTextForBrowser.js
Expand Down

0 comments on commit f44c705

Please sign in to comment.