npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

urli

v1.12.0

Published

An interface for manipulating and querying a URL

Downloads

21

Readme

URLi (URL Interface)

A constructor for manipulating and querying URLs

File size

8.73 kB

Usage

import URL from "urli";
const location = new URL(Schema, Location);

Types

Arguments

Argument|Type -|- Schema|UrlObject|String|null Location|UrlObject|String|null

UrlObject

Property|Type|Optional -|- origin|String|true href|String|true pathname|String|true hash|String|true search|String|true

Example Usage

location.setSchema(String)
-> URL

Methods

URL.prototype.set
url.set({
  pathname? : String,
  href?     : String,
  hash?     : String,
  origin?   : String,
  search?   : String
});
let url = new URL({ href: "http://localhost:3000/?string" });
url.set({
  pathname : "/path/name"
});
url.toString();
-> "http://localhost:3000/path/name?string=1"
URL.prototype.test
const url = new URL("/language/:lang");
url.test("/lang/english")     -> false
url.test("/language/english") -> true
let url = new URL({ href: "http://localhost:3000/?string" });
url.set({
  pathname : "/path/name"
});
url.toString();
-> "http://localhost:3000/path/name?string=1"

Params

Any path which is prefixed with : will be converted to a key value pair which is accessible at location.params

const location = new URL(
  "/user/:userID",
  "/user/SeanJM"
);
location.params.userID -> "SeanJM"
const location = new URL("/user/:userID", {
  pathname: "/user/SeanJM",
  search  : ""
});
location.params.userID -> "SeanJM"

Arrays

const location = new URL("/user/:userID?depth[]=:number+:id", {
  pathname: "/user/SeanJM",
  search  : "?depth[]=0+o8jk&depth[]=1+99qE&depth[]=2+eBPs"
});

location.search.depth -> [{
  number: 0,
  id    : "o8jk"
}, {
  number: 1,
  id    : "99qE"
}, {
  number: 2,
  id    : "eBPs"
}]

Objects & Constants

const location = new URL("/post/:postID?origin=board+:category+:page", {
  pathname: "/post/ezAYhlkuGEz",
  search  : "?origin=board+food+1"
});
location.search.origin -> {
  category: "food",
  page: 1
}

location.search.origin.category = "fitness";
location.toString() -> "/post/ezAYhlkuGEz?origin=board+fitness+1"

Changing values of params

location.params.userID = "HungryHippo";
location.toString();
-> "/user/HungryHippo"

Using set method

location.params
  .set({ userID: "HungryHippo" });
  .toString();
-> "/user/HungryHippo"

Methods

startsWith
let url = new URL({
  href: "http://localhost:3000/starts/with/this"
});

return url.params.startsWith("starts/with");
-> true
is
let url = new URL({
  href: "http://localhost:3000/starts/with/this"
});

return url.params.is("starts/with/this");
-> true
push
let url = new URL({
  href: "http://localhost:3000/starts/with/this"
});

url.params.push("login");
return url.toString();
-> "http://localhost:3000/starts/with/this/login"
let url = new URL({
  href: "http://localhost:3000/starts/with/this"
});

url.params.push({ name: "login" });
return url.params.name;
-> "login"
unshift
let url = new URL({
  href: "http://localhost:3000/starts/with/this"
});

url.params.unshift("login");
return url.toString();
-> "http://localhost:3000/login/starts/with/this"
let url = new URL({
  href: "http://localhost:3000/starts/with/this"
});

url.params.unshift({ name: "login" });
return url.params.name;
-> "login"

Changing values of search

location.search.comments = "100";
location.toString();
-> "/user/HungryHippo?comments=100"

Search queries default values

const loc = new URL({ href: "http://localhost:3000/login?reset" });
loc.search.reset -> 1
loc.toString()   -> "http://localhost:3000/login?reset=1"

Methods

set(props: Object)
get(key)
-> value
get(Array[key])
-> { key: value }
copy()
params.toString()
search.toString()
search.fromString(String)

copy()

The copy method will create a whole new object instance

location.copy();

Hash

const url = new Url({ href: "http://www.location.com/#hash" });
url.hash -> Hash { value : "#hash" }
url.location.hash -> "#hash"

// You can omit the "#" when setting the value
url.hash.value = "my-hash";
url.hash.toString() -> "#my-hash";