react-steersman-url
v1.0.0
Published
Tiny and Fast URL utils
Downloads
8
Readme
React Steersman URL
Tiny and Fast URL utils
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