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

urljs

v2.7.0

Published

A lightweight JavaScript library to manipulate the page url.

Downloads

285

Readme

url.js

Version Downloads

A lightweight JavaScript library to manipulate the page url.

Demo

Browse the demos on http://jillix.github.io/url.js/

CDN

The library is available on CDNJS as well. To use it, just do:

<script src="https://cdnjs.cloudflare.com/ajax/libs/urljs/2.6.2/url.min.js"></script>

Usage

<script src="path/to/url.js"></script>
<!-- or use the cdn
<script src="https://cdnjs.cloudflare.com/ajax/libs/urljs/2.6.2/url.min.js"></script>
-->
<script>
    Url.updateSearchParam("answer", 42);
</script>

CommonJS-compatible

The library is CommonJS-compatible. You can require("url.js") in your files.

:cloud: Installation

Check out the dist directory to download the needed files and include them on your page.

If you're using this module in a CommonJS environment, you can install it using npm or yarn and require it:

# Using npm
npm install --save urljs

# Using yarn
yarn add urljs

:question: Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. For bug reports and feature requests, open issues. :bug:

:memo: Documentation

queryString(name, notDecoded)

Finds the value of parameter passed in first argument.

Params

  • String name: The parameter name.
  • Boolean notDecoded: If true, the result will be encoded.

Return

  • String|Boolean|Undefined The parameter value (as string), true if the parameter is there, but doesn't have a value, or undefined if it is missing.

parseQuery(search)

Parses a string as querystring. Like the queryString method does, if the parameter is there, but it doesn't have a value, the value will be true.

Params

  • String search: An optional string that should be parsed (default: window.location.search).

Return

  • Object The parsed querystring. Note this will contain empty strings for

stringify(queryObj)

Stringifies a query object.

Params

  • Object queryObj: The object that should be stringified.

Return

  • String The stringified value of queryObj object.

updateSearchParam(param, value, push, triggerPopState)

Adds, updates or deletes a parameter (without page refresh).

Params

  • String|Object param: The parameter name or name-value pairs as object.
  • String value: The parameter value. If undefined, the parameter will be removed.
  • Boolean push: If true, the page will be kept in the history, otherwise the location will be changed but by pressing the back button will not bring you to the old location.
  • Boolean triggerPopState: Triggers the popstate handlers (by default falsly).

Return

  • Url The Url object.

getLocation(excludeHash)

Returns the page url, but not including the domain name.

Params

  • Boolean excludeHash: If true, the location hash will not be appended in the result.

Return

  • String The page url (without domain).

hash(newHash, triggerPopState)

Sets/gets the hash value.

Params

  • String newHash: The hash to set.
  • Boolean triggerPopState: Triggers the hashchange (by default falsly).

Return

  • String The location hash.

_updateAll(s, push, triggerPopState)

Update the full url (pathname, search, hash).

Params

  • String s: The new url to set.
  • Boolean push: If true, the page will be kept in the history, otherwise the location will be changed but by pressing the back button will not bring you to the old location.
  • Boolean triggerPopState: Triggers the popstate handlers (by default falsly).

Return

  • String The set url.

pathname(pathname, push, triggerPopState)

Sets/gets the pathname.

Params

  • String pathname: The pathname to set.
  • Boolean push: If true, the page will be kept in the history, otherwise the location will be changed but by pressing the back button will not bring you to the old location.
  • Boolean triggerPopState: Triggers the popstate handlers (by default falsly).

Return

  • String The set url.

triggerHashchangeCb()

Calls the hashchange handlers.

triggerPopStateCb()

Calls the popstate handlers.

onPopState(cb)

Adds a popstate handler.

Params

  • Function cb: The callback function.

onHashchange(cb)

Adds a hashchange handler.

Params

  • Function cb: The callback function.

removeHash(push, trigger)

Removes the hash from the url.

Params

  • Boolean push: If true, the page will be kept in the history, otherwise the location will be changed but by pressing the back button will not bring you to the old location.
  • Boolean trigger: Triggers the popstate handlers (by default falsly).

removeQuery(push, trigger)

Removes the querystring parameters from the url.

Params

  • Boolean push: If true, the page will be kept in the history, otherwise the location will be changed but by pressing the back button will not bring you to the old location.
  • Boolean trigger: Triggers the popstate handlers (by default falsly).

:yum: How to contribute

Have an idea? Found a bug? See how to contribute.

:dizzy: Where is this library used?

If you are using this library in one of your projects, add it in this list. :sparkles:

  • ember-cli-mocha-reporter

:scroll: License

MIT © jillix