New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

html-form-component

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-form-component

Little library to generate an HTML form and parse the request it submits. Based on html-encode-template-tag.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

html-form-component

Little library to generate an HTML form and parse the request it submits. Based on html-encode-template-tag.

import html from 'encode-html-template-tag';
import form from 'html-form-component';

const nameForm = form(
	{
		method: 'POST'
	},
	html`<label>
		What's your name?
		<input name="name">
	</label>
	<button>Submit</button>
	`,
	params => params.get('name')
);

export default async (req, res) => {
	if(req.method==='POST') {
		const name = await nameForm.parse(req);

		res.end(await html`Your name is ${name}`.render());
		return;
	}

	res.end(await nameForm.render());
}

Constants

parser

Create a function for parsing form values from a request object. The new function will recieve the request object and retrieve the submitted form values as URLSearchParams. You can then supply a function for transforming these params before returning them.

Functions

form(attributes, body, parser)FormElement

Creates a form element.

parse(req)URLSearchParams

Parse a request and return a URLSearchParams object

Typedefs

FormElement

A representation of a form element, for rendering a form

parser

Create a function for parsing form values from a request object. The new function will recieve the request object and retrieve the submitted form values as URLSearchParams. You can then supply a function for transforming these params before returning them.

ParamTypeDescription
parseParamsfunctionA function that accepts URLSearchParams and returns the parsed form values

form(attributes, body, parser) ⇒ FormElement

Creates a form element.

ParamTypeDescription
attributesObjectDict of attributes to add to the form element
body*Body of the form
parserfunctionFunction to transform the request body

parse(req) ⇒ URLSearchParams

Parse a request and return a URLSearchParams object

ParamTypeDescription
reqhttp.IncomingMessageThe request object to parse

FormElement

A representation of a form element, for rendering a form

ParamTypeDescription
renderfunctionGenerate the element as a string
parsefunctionGet the form data from a request object

Keywords

FAQs

Package last updated on 04 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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