Socket
Book a DemoInstallSign in
Socket

@acta/url

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@acta/url

Parse URLs to formated objects and build URLs from objects.

1.0.3
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

URL @acta/url

To parse URLs to formated objects and build URLs from objects.

Table of Contents

  • Parsing URLs
  • Formating URLs
  • Dev scripts

Parsing URLs

back to ToC ↑

You can parse an URL that way:

import URL from '@acta/url';

const parsedURL = URL.parse('http://username:password@subdomain.domain.tld:8080/foo/bar/baz?key1=value1&key2=value2#hashvalue')

/**
 {
    auth: { password: 'password', username: 'username' },
    domain: 'domain',
    domainChain: ['tld', 'domain', 'subdomain'],
    hash: 'hashvalue',
    host: 'subdomain.domain.tld:8080',
    hostname: 'subdomain.domain.tld',
    href: 'http://username:password@subdomain.domain.tld:8080/foo/bar/baz?key1=value1&key2=value2#hashvalue',
    isValidURL: true,
    origin: 'http://subdomain.domain.tld:8080',
    path: '/foo/bar/baz?key1=value1&key2=value2',
    pathname: '/foo/bar/baz',
    port: '8080',
    protocol: 'http:',
    query: 'key1=value1&key2=value2',
    queryParams: { key1: 'value1', key2: 'value2' },
    search: '?key1=value1&key2=value2',
    tld: 'tld',
  }
  */

The query parser is integrated.

When an element is missing, its value is null (ex without hash: hash: null).

Formating URLs

back to ToC ↑

You can format an URL that way:

import URL from '@acta/url';

const formatedURL = URL.format({
  auth: { password: 'password', username: 'username' },
  domain: 'domain',
  domainChain: ['tld', 'domain', 'subdomain'],
  hash: 'hashvalue',
  host: 'subdomain.domain.tld:8080',
  hostname: 'subdomain.domain.tld',
  href: 'http://username:password@subdomain.domain.tld:8080/foo/bar/baz?key1=value1&key2=value2#hashvalue',
  isValidURL: true,
  origin: 'http://subdomain.domain.tld:8080',
  path: '/foo/bar/baz?key1=value1&key2=value2',
  pathname: '/foo/bar/baz',
  port: '8080',
  protocol: 'http:',
  query: 'key1=value1&key2=value2',
  queryParams: { key1: 'value1', key2: 'value2' },
  search: '?key1=value1&key2=value2',
  tld: 'tld',
})

/**
 * http://username:password@subdomain.domain.tld:8080/foo/bar/baz?key1=value1&key2=value2#hashvalue
 */

Dev scripts

back to ToC ↑

  • npm run dev to dev (build, test and watch)
  • npm run build to build the production version
  • npm run release to release a new version. Relies on release-it for deployments.

To develop in local using the package from another application or package, go for a symlink: npm link /the/absolute/path/url.

To publish: npm publish --access=public.

Keywords

URL parser

FAQs

Package last updated on 02 Jan 2019

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.