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

ctrl-url

v1.2.4

Published

control url params

Downloads

3

Readme

cUrl使用说明

常规使用

  1. npm i ctrl-url --save
  2. 该模块提供了4个方法供调用,各个方法传入必要参数就可以运行,目的是简化基本的url参数读写

方法说明

get

/**
 * 获取 url 对象
 * @param {String || null} str  传入 String,则获取的是 str的对象, 不传str, 获取的是当前url的对象
 * @return {Object} 
 * return {
 *     search: { key1: value1, key2: value2 },
 *     hash: { key1: value1 } || '/home/user',
 *     query: { key1: value1 }
 * }
 */
cUrl.get();
cUrl.get('http://127.0.0.1:7777?a=1#b=2&c=3?d=4');

set

/**
 * 设置新url    str 为字符串时 改变的是str ,str是对象时改变的是当前 url
 * 对象格式: value 为空则删除当前 key 
 * paramObj = {
 *     search: { key1: value1, key2: value2 },
 *     hash: { key1: value1 } || '/home/user',
 *     query: { key1: value1 }
 * }
 * typeObj 格式: {type: 'replace', reload: false}
 * @param {String || Object} str 
 * @param {Object || null} paramObj 
 * @return {String}
 */
cUrl.set(paramObj);
cUrl.set('http://127.0.0.1:7777?a=1#b=2&c=3?d=4', paramObj);
cUrl.set('http://127.0.0.1:7777?a=1#b=2&c=3?d=4', paramObj, {type: 'replace'});

第三个参数的说明:
如果存在第三个参数,则页面会自动跳转,不需要在业务里写 window.locaiton xxx

  1. typeObj对象 type属性的说明:

    • 值为 replace 或者 push;
    • replace 就是 替换 url 记录的意思;
    • push 就是 添加 url 记录的意思
  2. typeObj对象 reload属性的说明:

    • true 将会使用 window.location 的形式跳转,原本如果是添加参数,则js脚本会重新执行一边;
    • false 将会使用 window.history 的形式改变url, 脚本不会重新执行,只是改变url;
    • history 形式做了兼容处理, 如果不兼容则使用 location 的形式, 调用者不需要关心这里。

get_url_params

/**
 * 提供获取参数的轻便方法
 * 获取当前url 的 name 的参数
 * @param {String} name 
 */
cUrl.get_url_params('key')

set_url_params

/**
 * 提供设置参数的轻便方法
 * 设置当前url 为新 url
 * obj 格式 : { key1: value1, key2:value2 }  当value为''||false 时 删除当前key 
 * typeObj 格式: {type: 'replace', reload: false}
 * @param {Object} obj
 * @param {String} typeObj  replace push 
 */
cUrl.set_url_params(obj, typeObj)
cUrl.set_url_params(obj, {type: 'replace', reload: true})