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 🙏

© 2025 – Pkg Stats / Ryan Hefner

apiurl

v1.3.6

Published

自动适配测试环境API地址

Readme

#转换URL地址,用于统一指向测试环境

 stepA 
    $ cnpm/npm install apiurl 
    后将自动引入 axios
 stepB 
    直接调用apiurl()方法
    apiurl,并在构造函数中传入对应参数
        可以直接使用 toString() 返回修改后的URL地址
        该方法提供3个参数
    * 转换当前地址
    * 传入参数为一个对象,其中必需包含的参数有:
    *  @param {string} url 当前需要请求的地址
    * 可选参数:
    *  @param {string} mark 需要标记的前缀,如果不设置,默认: test_
    *  @param {string} envName 当前环境变量的变量名称,不填默认: JMG_ENV

例如:
    let apiurl = require("apiurl")
    let result = await apiurl.post("localhost:8081/h", {mint:1});
    let result = await apiurl.get("192.168.9.169/h", {mint:1});

    当前地址如果为HTTPS的话,如果在接口前缀不加任何协议,则会原样使用当前浏览器地址的协议
    apiurl("www.baidu.com") => http://test_www.baidu.com (默认使用:http://)
    apiurl("xxx.xxx.xxx.xxx") => 无论在生产或开发环境,都会原样返回
    apiurl("www.baidu.com","testingenvironment_","JMG_ENV") https://testingenvironment_www.baidu.com



Promise API 方式:

    let p = () => {
        return apiurl.post("localhost:8081/h", data);
    }
    let g = () => {
        return apiurl.get("192.168.9.169:8081/h", data);
    }
    let value = await apiurl.axios.all([p(), g()]);
    console.log(value)

CallBack 方式:
    apiurl.axios.all([p(), g()]).then(apiurl.axios.spread((postResult, getResult) => {
        console.log(postResult.data, getResult.data)
    })).catch(err => {
        
    })

实列化方式:

    let apiurl = require("apiurl")
    let api = new apiurl("www.baidu.com")
    api.toString() => http://test_www.baidu.com (默认使用:http://)
    let api= new apiurl("www.baidu.com","testingenvironment_")
    api.toString() =>  https://testingenvironment_www.baidu.com
    当在生产环境中(express,vue-cli) 中打包后,会自动去除前缀
    
    发起Ajax请求
    api.post/get/put/delete 等
    api.post(url,data)


#0.1 调用示列:

    let s = new apiurl("localhost:8081/h");
    let data = {
        mint: 1
    }
    s.axios.all([s.post(data), s.get(data)]).then(s.axios.spread((postResult, getResult) => {
        let post = postResult.data
        let get = getResult.data;
    }))


也可同时发起多个并发请求
#0.1.1 调用示列

s.axios.all([g(data), p(data)])
    .then(s.axios.spread((acct, perms) => {)
        // Object {get: "1"}
        // Object {post: 2}
    })).catch(err => {
        //如果其中一个失败,则全部请求失败
        // Request failed with status code 500
        console.log(err)
});

支持 Promise API
#0.2 示列如下:

try {
    let datavArray = await s.axios.all([g(data), p(data)]);
        //datavArray.length 为传入的请求的个数,此时为2
    console.log(datavArray)
        //datavArray[0].data => get(data) 的值
        //datavArray[1].data => post(data) 的值
} catch (error) {
        //如果其中一个失败,则全部请求失败
        // Request failed with status code 500
    console.log(error);

}

HTML静态页调用说明
    HTML中引入JS文件 apiurl.js
    * 调用debug 方法模板当前静态页面的环境变量 例如:debug(false); 为生产环境debug(true); 为测试环境
    * 目前暂不支持同时发起多个并发请求
调用示例:
    <script src="../javascripts/apiurl.js"></script>
    let testurl= apiurl("localhost:8081/h")=> test_localhost:8081/h
    let g = await apiurl.get("192.168.9.169:8081/h", {
            mint: 1
    });
    let p = await apiurl.get("192.168.9.169:8081/h", {
        mint: 1
    });

    let url = apiurl("www.baidu.com"); 
    apiurl.get/post 可直接发送请求,调用方法与 #0.1 相同

    
支持 Promise API
#0.3 示列如下:

    try {
        let g = await apiurl.get(url,{mint:1});
        let p = await apiurl.post(url,{mint:1});
    } catch (error) {

        
    }

同样支持new实列化方式调用
    let api = new apiurl("192.168.9.169:8081", "tt_");
    try {
        let s = await api.get("/h", {
            mint: 1
        })
        console.log(api.toString());
        let p = await api.post("/h", {
            data: 1
        });
        console.log(s.data, p.data)
    } catch (error) {

    }

let g = await api.get(router,obj);
let p = await api.post(router,obj);