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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sugo-resource

v0.0.2

Published

api resource manager for frontend by JavaScript

Downloads

11

Readme

Build Status npm version

目的

  1. 为接口提供统一管理能力
  2. 统一接口相关api

特性

  1. url参数解析
  2. 返回值容错
  3. 返回结果为Promise

示例

import { Resource } from 'resource'
// create instance
const $resources = {
    create: Resource.create('/user/create'),
    findOne: Resource.create('/user/find/:email')
}
// use
// post
const create_res = await $resources.create({}, {email: '[email protected]', password:'xxx'}).json()
console.log(create_res) // {...}
// get
const find_res = await $resources.findOne({email: '[email protected]'}, {}).json()
console.log(find_res) // {...}
// static
// send post request
const sign_res = await Resouce.post('/user/sign', {}, {email: '[email protected]', password:'xxx'}).json()
console.log(sign_res) // {...}

实例方法

  1. resource.get(param:any, data:any, option = {}): Resource
  2. resource.post(param:any, data:any, option = {}): Resource
  3. resource.put(param:any, data:any, option = {}): Resource
  4. resource.del(param:any, data:any, option = {}): Resource
  5. resource.send(param:any, method:string, data:any, option = {}): Resource
  6. resource.arrayBuffer(): Promise
  7. resource.blob(): Promise
  8. resource.json(): Promise
  9. resource.text(): Promise
  10. resource.formData(): Promise

静态方法

  1. Resource.create(uri:string): Resource
  2. Resource.get(uri:string, params:any, data:any, options:any): Resource
  3. Resource.post(uri:string, params:any, data:any, options:any): Resource
  4. Resource.put(uri:string, params:any, data:any, options:any): Resource
  5. Resource.del(uri:string, params:any, data:any, options:any): Resource

配置请求服务函数

Resource 默认使用window.fetch提供发送请求能力,如果用户需要其他发送请求工具, 可以通过Resource.setServer来变发送请求功能,server函数必需满足如下定义。

function server(input: RequestInfo, init?: RequestInit): Promise<Response>
  1. 接收两个参数
  1. 返回值为一个Promise,Promise结果必须为Response
import {Resource} from 'resource'
Resource.setServer(function(input, opt){
    const {method, body} = opt
    if (method === 'get') {
        return window.fetch(input)
    }
    if (method === 'post') {
        return window.fetch(input, {
            headers: {
                'Content-type':'application/json'
            },
            credentials: 'include',
            body: typeof body === 'object' ? JSON.stringfy(body) : body
        })
    }
    return window.fetch(input, opt)
})

在服务端可以使用node-fetch来代替

import fetch from 'node-fetch'
import {Resource} from 'resource'
Resource.setServer(function(input, init){
    return fetch(input, init)
})