Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remix-utils

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remix-utils - npm Package Compare versions

Comparing version 2.4.0 to 2.5.0

2

browser/server/csrf.js

@@ -38,3 +38,3 @@ import { v4 as uuid } from "uuid";

// still be used and parsed without errors.
let formData = await request.formData();
let formData = await request.clone().formData();
// if the session doesn't have a csrf token, throw an error

@@ -41,0 +41,0 @@ if (!session.has(sessionKey)) {

@@ -0,1 +1,2 @@

/// <reference types="node" />
import { JsonValue } from "type-fest";

@@ -106,1 +107,49 @@ /**

export declare function notModified(init?: Omit<ResponseInit, "status">): Response;
/**
* Create a response with a JavaScript file response.
* It receives a string with the JavaScript content and set the Content-Type
* header to `application/javascript; charset=utf-8` always.
*
* This is useful to dynamically create a JS file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return javascript("console.log('Hello World')");
* }
*/
export declare function javascript(content: string, init?: number | ResponseInit): Response;
/**
* Create a response with a CSS file response.
* It receives a string with the CSS content and set the Content-Type header to
* `text/css; charset=utf-8` always.
*
* This is useful to dynamically create a CSS file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return css("body { color: red; }");
* }
*/
export declare function stylesheet(content: string, init?: number | ResponseInit): Response;
/**
* Create a response with a PDF file response.
* It receives a string with the PDF content and set the Content-Type header to
* `application/pdf; charset=utf-8` always.
*
* This is useful to dynamically create a PDF file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return pdf(await generatePDF(request.formData()));
* }
*/
export declare function pdf(content: Blob | Buffer | ArrayBuffer, init?: number | ResponseInit): Response;
/**
* Create a response with a HTML file response.
* It receives a string with the HTML content and set the Content-Type header to
* `text/html; charset=utf-8` always.
*
* This is useful to dynamically create a HTML file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return html("<h1>Hello World</h1>");
* }
*/
export declare function html(content: string, init?: number | ResponseInit): Response;

@@ -123,1 +123,89 @@ import { json as remixJson, redirect } from "@remix-run/server-runtime";

}
/**
* Create a response with a JavaScript file response.
* It receives a string with the JavaScript content and set the Content-Type
* header to `application/javascript; charset=utf-8` always.
*
* This is useful to dynamically create a JS file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return javascript("console.log('Hello World')");
* }
*/
export function javascript(content, init = {}) {
let responseInit = typeof init === "number" ? { status: init } : init;
let headers = new Headers(responseInit.headers);
if (!headers.has("Content-Type")) {
headers.set("Content-Type", "application/javascript; charset=utf-8");
}
return new Response(content, {
...responseInit,
headers,
});
}
/**
* Create a response with a CSS file response.
* It receives a string with the CSS content and set the Content-Type header to
* `text/css; charset=utf-8` always.
*
* This is useful to dynamically create a CSS file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return css("body { color: red; }");
* }
*/
export function stylesheet(content, init = {}) {
let responseInit = typeof init === "number" ? { status: init } : init;
let headers = new Headers(responseInit.headers);
if (!headers.has("Content-Type")) {
headers.set("Content-Type", "text/css; charset=utf-8");
}
return new Response(content, {
...responseInit,
headers,
});
}
/**
* Create a response with a PDF file response.
* It receives a string with the PDF content and set the Content-Type header to
* `application/pdf; charset=utf-8` always.
*
* This is useful to dynamically create a PDF file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return pdf(await generatePDF(request.formData()));
* }
*/
export function pdf(content, init = {}) {
let responseInit = typeof init === "number" ? { status: init } : init;
let headers = new Headers(responseInit.headers);
if (!headers.has("Content-Type")) {
headers.set("Content-Type", "application/pdf");
}
return new Response(content, {
...responseInit,
headers,
});
}
/**
* Create a response with a HTML file response.
* It receives a string with the HTML content and set the Content-Type header to
* `text/html; charset=utf-8` always.
*
* This is useful to dynamically create a HTML file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return html("<h1>Hello World</h1>");
* }
*/
export function html(content, init = {}) {
let responseInit = typeof init === "number" ? { status: init } : init;
let headers = new Headers(responseInit.headers);
if (!headers.has("Content-Type")) {
headers.set("Content-Type", "text/html; charset=utf-8");
}
return new Response(content, {
...responseInit,
headers,
});
}

@@ -42,3 +42,3 @@ "use strict";

// still be used and parsed without errors.
let formData = await request.formData();
let formData = await request.clone().formData();
// if the session doesn't have a csrf token, throw an error

@@ -45,0 +45,0 @@ if (!session.has(sessionKey)) {

@@ -0,1 +1,2 @@

/// <reference types="node" />
import { JsonValue } from "type-fest";

@@ -106,1 +107,49 @@ /**

export declare function notModified(init?: Omit<ResponseInit, "status">): Response;
/**
* Create a response with a JavaScript file response.
* It receives a string with the JavaScript content and set the Content-Type
* header to `application/javascript; charset=utf-8` always.
*
* This is useful to dynamically create a JS file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return javascript("console.log('Hello World')");
* }
*/
export declare function javascript(content: string, init?: number | ResponseInit): Response;
/**
* Create a response with a CSS file response.
* It receives a string with the CSS content and set the Content-Type header to
* `text/css; charset=utf-8` always.
*
* This is useful to dynamically create a CSS file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return css("body { color: red; }");
* }
*/
export declare function stylesheet(content: string, init?: number | ResponseInit): Response;
/**
* Create a response with a PDF file response.
* It receives a string with the PDF content and set the Content-Type header to
* `application/pdf; charset=utf-8` always.
*
* This is useful to dynamically create a PDF file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return pdf(await generatePDF(request.formData()));
* }
*/
export declare function pdf(content: Blob | Buffer | ArrayBuffer, init?: number | ResponseInit): Response;
/**
* Create a response with a HTML file response.
* It receives a string with the HTML content and set the Content-Type header to
* `text/html; charset=utf-8` always.
*
* This is useful to dynamically create a HTML file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return html("<h1>Hello World</h1>");
* }
*/
export declare function html(content: string, init?: number | ResponseInit): Response;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.notModified = exports.serverError = exports.unprocessableEntity = exports.notFound = exports.forbidden = exports.unauthorized = exports.badRequest = exports.redirectBack = exports.json = void 0;
exports.html = exports.pdf = exports.stylesheet = exports.javascript = exports.notModified = exports.serverError = exports.unprocessableEntity = exports.notFound = exports.forbidden = exports.unauthorized = exports.badRequest = exports.redirectBack = exports.json = void 0;
const server_runtime_1 = require("@remix-run/server-runtime");

@@ -135,1 +135,93 @@ /**

exports.notModified = notModified;
/**
* Create a response with a JavaScript file response.
* It receives a string with the JavaScript content and set the Content-Type
* header to `application/javascript; charset=utf-8` always.
*
* This is useful to dynamically create a JS file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return javascript("console.log('Hello World')");
* }
*/
function javascript(content, init = {}) {
let responseInit = typeof init === "number" ? { status: init } : init;
let headers = new Headers(responseInit.headers);
if (!headers.has("Content-Type")) {
headers.set("Content-Type", "application/javascript; charset=utf-8");
}
return new Response(content, {
...responseInit,
headers,
});
}
exports.javascript = javascript;
/**
* Create a response with a CSS file response.
* It receives a string with the CSS content and set the Content-Type header to
* `text/css; charset=utf-8` always.
*
* This is useful to dynamically create a CSS file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return css("body { color: red; }");
* }
*/
function stylesheet(content, init = {}) {
let responseInit = typeof init === "number" ? { status: init } : init;
let headers = new Headers(responseInit.headers);
if (!headers.has("Content-Type")) {
headers.set("Content-Type", "text/css; charset=utf-8");
}
return new Response(content, {
...responseInit,
headers,
});
}
exports.stylesheet = stylesheet;
/**
* Create a response with a PDF file response.
* It receives a string with the PDF content and set the Content-Type header to
* `application/pdf; charset=utf-8` always.
*
* This is useful to dynamically create a PDF file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return pdf(await generatePDF(request.formData()));
* }
*/
function pdf(content, init = {}) {
let responseInit = typeof init === "number" ? { status: init } : init;
let headers = new Headers(responseInit.headers);
if (!headers.has("Content-Type")) {
headers.set("Content-Type", "application/pdf");
}
return new Response(content, {
...responseInit,
headers,
});
}
exports.pdf = pdf;
/**
* Create a response with a HTML file response.
* It receives a string with the HTML content and set the Content-Type header to
* `text/html; charset=utf-8` always.
*
* This is useful to dynamically create a HTML file from a Resource Route.
* @example
* export let loader: LoaderFunction = async ({ request }) => {
* return html("<h1>Hello World</h1>");
* }
*/
function html(content, init = {}) {
let responseInit = typeof init === "number" ? { status: init } : init;
let headers = new Headers(responseInit.headers);
if (!headers.has("Content-Type")) {
headers.set("Content-Type", "text/html; charset=utf-8");
}
return new Response(content, {
...responseInit,
headers,
});
}
exports.html = html;
{
"name": "remix-utils",
"version": "2.4.0",
"version": "2.5.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "engines": {

@@ -66,5 +66,3 @@ # Remix Utils

{ csrf: token },
{
headers: await commitSession(session),
}
{ headers: { "Set-Cookie": await commitSession(session) } }
);

@@ -87,3 +85,3 @@ };

return (
<AuthenticityTokenProvider value={csrf}>
<AuthenticityTokenProvider token={csrf}>
<Document>

@@ -218,3 +216,3 @@ <Outlet />

// create the scripts function with the correct type
let scripts: ScriptsFunction = () => {
let scripts: ExternalScriptsFunction = () => {
return [

@@ -669,2 +667,60 @@ {

#### Not Modified
Helper function to create a Not Modified (304) response without a body and any header.
```ts
export let loader: LoaderFunction = async ({ request }) => {
return notModified();
};
```
#### JavaScript
Helper function to create a JavaScript file response with any header.
This is useful to create JS files based on data inside a Resource Route.
```ts
export let loader: LoaderFunction = async ({ request }) => {
return javascript("console.log('Hello World')");
};
```
#### Stylesheet
Helper function to create a CSS file response with any header.
This is useful to create CSS files based on data inside a Resource Route.
```ts
export let loader: LoaderFunction = async ({ request }) => {
return stylesheet("body { color: red; }");
};
```
#### PDF
Helper function to create a PDF file response with any header.
This is useful to create PDF files based on data inside a Resource Route.
```ts
export let loader: LoaderFunction = async ({ request }) => {
return pdf(await generatePDF(request.formData()));
};
```
#### HTML
Helper function to create a HTML file response with any header.
This is useful to create HTML files based on data inside a Resource Route.
```ts
export let loader: LoaderFunction = async ({ request }) => {
return html("<h1>Hello World</h1>");
};
```
## Author

@@ -677,1 +733,5 @@

- MIT License
```
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc