Comparing version 2.0.5 to 2.0.6
/// <reference types="@cloudflare/workers-types" /> | ||
import type { NotFoundHandler } from './hono'; | ||
import type { ContextVariableMap, NotFoundHandler } from './hono'; | ||
import type { CookieOptions } from './utils/cookie'; | ||
@@ -18,4 +18,10 @@ import type { StatusCode } from './utils/http-status'; | ||
status: (status: StatusCode) => void; | ||
set: (key: string, value: any) => void; | ||
get: <T = any>(key: string) => T; | ||
set: { | ||
<Key extends keyof ContextVariableMap>(key: Key, value: ContextVariableMap[Key]): void; | ||
(key: string, value: any): void; | ||
}; | ||
get: { | ||
<Key extends keyof ContextVariableMap>(key: Key): ContextVariableMap[Key]; | ||
<T = any>(key: string): T; | ||
}; | ||
pretty: (prettyJSON: boolean, space?: number) => void; | ||
@@ -22,0 +28,0 @@ newResponse: (data: Data | null, status: StatusCode, headers: Headers) => Response; |
/// <reference types="@cloudflare/workers-types" /> | ||
import type { Context } from './context'; | ||
import type { Router } from './router'; | ||
export interface ContextVariableMap { | ||
} | ||
declare type Env = Record<string, any>; | ||
@@ -5,0 +7,0 @@ export declare type Handler<RequestParamKeyType extends string = string, E = Env> = (c: Context<RequestParamKeyType, E>, next: Next) => Response | Promise<Response> | Promise<void> | Promise<Response | undefined>; |
@@ -22,2 +22,8 @@ "use strict"; | ||
]; | ||
const booleanAttributes = ['checked', 'selected', 'disabled', 'readonly', 'multiple']; | ||
const newHtmlEscapedString = (str) => { | ||
const escapedString = new String(str); | ||
escapedString.isEscaped = true; | ||
return escapedString; | ||
}; | ||
const jsxFn = (tag, props, ...children) => { | ||
@@ -31,20 +37,31 @@ if (typeof tag === 'function') { | ||
const v = props[propsKeys[i]]; | ||
if (propsKeys[i] === 'dangerouslySetInnerHTML') { | ||
if (typeof v === 'string') { | ||
result += ` ${propsKeys[i]}="${(0, html_1.escape)(v)}"`; | ||
} | ||
else if (typeof v === 'number') { | ||
result += ` ${propsKeys[i]}="${v}"`; | ||
} | ||
else if (v === null || v === undefined) { | ||
// Do nothing | ||
} | ||
else if (typeof v === 'boolean' && booleanAttributes.includes(propsKeys[i])) { | ||
if (v) { | ||
result += ` ${propsKeys[i]}=""`; | ||
} | ||
} | ||
else if (propsKeys[i] === 'dangerouslySetInnerHTML') { | ||
if (children.length > 0) { | ||
throw 'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'; | ||
} | ||
const escapedString = new String(v.__html); | ||
escapedString.isEscaped = true; | ||
children = [escapedString]; | ||
continue; | ||
children = [newHtmlEscapedString(v.__html)]; | ||
} | ||
else if (v === null || v === undefined) { | ||
continue; | ||
else { | ||
result += ` ${propsKeys[i]}="${(0, html_1.escape)(v.toString())}"`; | ||
} | ||
result += ` ${propsKeys[i]}="${(0, html_1.escape)(v.toString())}"`; | ||
} | ||
if (emptyTags.includes(tag)) { | ||
result += '/>'; | ||
return newHtmlEscapedString(result); | ||
} | ||
if (tag !== '') { | ||
if (emptyTags.includes(tag)) { | ||
result += '/'; | ||
} | ||
result += '>'; | ||
@@ -65,8 +82,6 @@ } | ||
} | ||
if (tag !== '' && !emptyTags.includes(tag)) { | ||
if (tag !== '') { | ||
result += `</${tag}>`; | ||
} | ||
const escapedString = new String(result); | ||
escapedString.isEscaped = true; | ||
return escapedString; | ||
return newHtmlEscapedString(result); | ||
}; | ||
@@ -73,0 +88,0 @@ exports.jsx = jsxFn; |
@@ -7,3 +7,8 @@ "use strict"; | ||
if (contentType.includes('application/json')) { | ||
return await r.json(); | ||
let body = {}; | ||
try { | ||
body = await r.json(); | ||
} | ||
catch { } // Do nothing | ||
return body; | ||
} | ||
@@ -10,0 +15,0 @@ else if (contentType.includes('application/text')) { |
{ | ||
"name": "hono", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "Ultrafast web framework for Cloudflare Workers.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114139
2900