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

xhrp

v1.1.3

Published

XMLHttpRequest of promise and export jsonp

Downloads

7

Readme

xhrp

XMLHttpRequest of promise and export jsonp. xhrp depend on native Promise.

npm

 npm install --save xhrp

require

  var xhrp = require('xhrp');
  //or
  import * as xhrp from 'xhrp';
  //or browser
  <script src="./index.js"></script>

use

when xhrp request success ,responseText is not parse. error will return array include [err , req , settings].

ajax(options)

let promise = xhrp.ajax({
 url:'http://127.0.0.1:8888/test'
});
promise.then((result)=>{
 console.log(result);
}).catch((e)=>{
 console.log(e);
});
xhrp.abort(promise);

get(url,[options])

xhrp.get('http://127.0.0.1:8888/test')
.then((result)=>{
  console.log(result);
}).catch((e)=>{
  console.log(e);
});

post(url,[options])

xhrp.post({
    url:'http://127.0.0.1:8888/test' ,
    timeout:4000,
    headers :{Accept:'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*'}
}).then((result)=>{
    console.log(result);
}).catch((e)=>{
    console.log(e);
});

upload File:

let formdata = new FormData();
formdata.append('filename',File);
xhrp.post({
    url:'http://127.0.0.1:8888/test' ,
    timeout:4000,
    data: formdata
}).then((result)=>{
    console.log(result);
}).catch((e)=>{
    console.log(e);
});

if you want send application/json , you need set contentType and set processData=false.

jsonp(url,[options])

let promise = xhrp.jsonp({url:'http://127.0.0.1:8888/test' ,timeout:4000});
promise.then((result)=>{
  console.log(result);
}).catch((e)=>{
  console.log(e);
});
xhrp.abort(promise);

abort(promise)

xhrp.abort(promise);

settings

ajax

//请求类型
type :'GET',
//是否跨域
crossDomain: false, //ineffect of jsonp ,please set params
//超时设置  默认不超时
timeout: 0,
//数据需要被序列化,默认为true
processData: true,
//对get请求数据进行缓存
cache: true,
//url
url : 'string',
//是否异步
async:'boolean',
//用户名
user:'string',
//密码
password:'string',
//请求头数据类型
contentType:'string',
//数据
data:'object',
//设置请求头
headers:'object'

jsonp

//请求类型
type :'GET',
//是否跨域
crossDomain: false, //ineffect of jsonp ,please set params
//超时设置  默认不超时
timeout: 0,
//数据需要被序列化
processData: true,
//对get请求数据进行缓存
cache: true,
//设置script属性
params:'object',
//default server get params name is "callback" , you can set it.
//服务器回调函数参数
jsonp:'string',
//url
url : 'string'

demo

cd test
node server.js

open the test/index.html

test

cmd rum:

webpack