react-steersman-url

1.0.0 • Public • Published

React Steersman URL

Tiny and Fast URL utils

NPM version Downloads Build Status

Usage

URI

interface URI {
 protocol      // returns protocol
 username      // returns username if exists otherwise false
 password      // returns password if exists otherwise false
 hostname      // returns hostname
 port          // returns port if exists otherwise false
 host          // returns host
 origin        // returns origin
 path          // returns path
 pathParts     // returns path parts
 query         // returns query
 queryParams   // returns query as object
 hash          // returns hash
 toString()    // converts URI instance to string
 toObject()    // converts URI instance to Object
}
 
const uri = URI.parse('https://example.com');
console.log(uri.toObject());

Pattern

interface Pattern {
  static fromString(url: string): Pattern
  build(params: object): string
  match(url: string): (object|null)
}
 
const compiled = Pattern.fromString('/user/:userId(\\d+)|int');
const userId = 4520;
const url = compiled.build({ userId });
console.log(url) // /user/4520
const params = compiled.match(url);
console.log(params) // { userId: 4520 }

License

License The MIT License Copyright (c) 2017-2018 Ivan Zakharchanka

Readme

Keywords

none

Package Sidebar

Install

npm i react-steersman-url

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • 3axap4ehko