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

@porkchopsandwich/dsn

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@porkchopsandwich/dsn

DSN URI parsing and stringifying

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@porkchopsandwich/dsn

DSN URI string parsing and stringifying.

Install

npm install @porkchopsandwich/dsn

Usage

import { parse, stringify } from "@porkchopsandwich/dsn";

// Parse a DSN URI into elements
const parsed = parse("mysqli://user:p&ssw!rd@hostname:1234/path/to/entity?extra=1");
// -> { protocol: "mysqli", username: "user", "password": "p&ssw!rd", host: "hostname", port: 1234, path: "path/to/entity", query: URLSearchParams }

// Compile a DSN object into a URI string
const dsnUriString = stringify({
    protocol: "arbitrary",
    host: "unprotected.host",
    path: "path/to/dsn/entity"
});
// -> "arbitrary://unprotected.host/path/to/dsn/entity"

parse(dsnString: string): Dsn | undefined

parse() takes a string, and returns either a Dsn object (see below), or undefined if it does not look like a DSN URI.

The Dsn string must contain a protocol, host and path. It may contain a username, password, port and/or query.

stringify(dsn: Dsn): string

stringify() takes a Dsn object (see below) and returns a string.

The Dsn object must contain a protocol string, host string and path string. It may contain a username string, password string, port number and/or query URLSearchParams.

Dsn object

Dsn objects are returned by parse() and taken by stringify(). They have the following form:

FieldTypeNotes
protocolstringRequired
hoststringRequired
pathstringRequired
usernamestringOptional
passwordstringOptional
hostnumberOptional
queryURLSearchParamsOptional

Keywords

FAQs

Package last updated on 03 Dec 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