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

adria-parser

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adria-parser

A super simple library for parsing form data and search params

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Adria

A super simple library for parsing form data and search params. It makes it easy to narrow the type and convert the input to something useful before doing the validation.

npm i adria-parser
yarn add adria-parser
pnpm add adria-parser

Overview

import { parse } from "adria-parser";

const formData = new FormData();

// intellisense
const { username, age, profile_image, birthday interests } = parse(formData, {
  username: "string",
  age: "number",
  profile_image: "file",
  birthday: "date",
  interests: "array.string",
});

// null if empty or can't be converted to defined type

// username: string | null
// age: number | null
// profile_image: File | null
// birthday: Date | null
// interests: string[]

Reference

const parse: (
  input: FormData | URLSearchParams,
  schema: Record<string, InputType>
) => Record<string, any>;

The result will be a FieldName:DefinedType | null record, where it's null if the field didn't exist or it couldn't coerce the input to the defined type.

InputType

  • PrimitiveType
  • ${CompoundType}.${PrimitiveType}

PrimitiveType

  • string => string
  • number => number
  • boolean => boolean
  • date => Date
  • file => File

CompoundType

  • array => T[]

Keywords

FAQs

Package last updated on 06 Jan 2023

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