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

catta

v2.2.0

Published

Simple promise base request client for browser

Readme

forthebadge forthebadge sizebadge

catta

catta is a simple request client for browser Support Fetch, AJAX, JSONP and even custom your own adapter. 中文文档-请点我

  • Dead simple to use
  • Uniform options and usage for each adapter
  • Support all modern browser (include IE 9+, with comp. version)
  • Support auto-detect browser to choice adapter (more detail)
  • Custom own adapter
  • light weight, core version less then 2 KB (min + gzip)

Browser support

  • catta-min.js
    • All modern browser, except IE
    • No any es6+ polyfill, just pure library
  • catta-min-comp.js
    • All modern browser, IE 9+
    • Core library with Promise and Object.assign polyfill
    • No Formdata polyfill, send {data: HTMLFormElement} need IE 10+ to work
    • No Global Fetch polyfill, if browser not support this feature, then it will downgrade to AJAX

Recommend to use the pure one, if your project already have those polyfill or no need IE Support.

Usage

Install First

# local install
npm install catta --save

Then import to your project

// With ES6 - *Recommend*
import catta from 'catta';

catta('http://some/url').then(function (res) {
  console.log(res);
});
// With CommonJS
const catta = require('catta');

// or catta.ajax or catta.jsonp or catta.fetch
catta.default('http://some/url').then(function (res) {
  console.log(res);
});
<!-- And also with <script> in HTML - *Not Recommend* -->
<script src="./node_modules/catta/dist/catta-min.js"></script>
<script>
  // or catta.ajax or catta.jsonp or catta.fetch
  catta.default('http://some/url').then(function (res) {
    console.log(res);
  });
</script>

Options

API

  import {ajax, fetch, jsonp, getScript} from 'catta';

  /**
   * make fetch/ajax/jsonp/getScript request
   * @param {string} url - request url
   * @param {Object} options - request options
   * 
   */
  ajax(url, options);

  // fetch request
  fetch(url, options);

  // jsonp request
  jsonp(url, options);

  // getScript 
  getScript(url);

Important Options

| | Description | Type | Default | Fetch | AJAX | JSONP | | :------ | :---------------------- | :--------------------------------------- | :-----: | :---: | :--: | :---: | | url | request url | string | null | v | v | v | | method | request method | string { get , post, put, delete, head } | 'get' | v | v | x | | data | the data send to server | string/Object/Form Element [3] | {} | v | v | v |

Secondary Options

| | Description | Type | Default | Fetch | AJAX | JSONP | | ---------- | ------------------------------------- | ----------------------------- | :-----: | :-------: | :--: | :-------: | | type | restrict request type | string { fetch, ajax, jsonp, script } | 'auto' | — | — | — | | timeout | throw timeout error after seconds | number | 3 | ! [1] | v | ! [1] | | resultType | the type of result | { text, json, response } | text | v | v | ! [2] |

v Supported ! Partial Supported × Not Supported

  1. Fetch and JSONP request can't be abort, current timeout is just throw timeout error

  2. resultType option can't work with jsonp, because the result must be executable javascript code

  3. Only support form element with FormData feature

Special Options

| | Property | Description | Type | | ----- | ------------ | ---------------------------------------- | ------- | | jsonp | callbackName | set custom callback name | string | | fetch | cross | indicate whether request can cross-origin | boolean | | ajax | - | - | - |

Examples

Simple

import catta from 'catta';

catta('http://some/url').then(function (res) {
  console.log(res);
});

With full Options

import catta from 'catta';

catta('http://some/url', {
  type: 'jsonp',
  data: {
    page: 5,
    count: 20
  },
  timeout: 2,
  credential: false,
  cross: false,
  
  // sp. options
  jsonp: {
      callbackName: 'myCustomJSONP1'
  }
})
.then(res => console.log(res))
.catch(err => console.log(err));

Only use Fetch / AJAX / JSONP

import {fetch} from 'catta';

// only use fetch
fetch('http://some/url', {
  data: {a:1}
}).then(function (res) {
  console.log(res);
});

Custom request headers

import catta from 'catta';

catta('http://some/url', {
  headers: {
    'Content-Type': 'appliction/json'
  }
})
.then(function (res) {
  console.log(res);
});

Overwrite global config

import {globalConfig} from 'catta';

// set global config, it will work for each request
globalConfig({
  timeout: 10
});

Custom adapter

A custom adapter is just an object, that has detector and processor function.This feature is use to make a wrapper to your special request, and let catta to handle it.More detail see mtop adapter example

import {customAdapter} from 'catta';
import mtopAdapter from 'catta/lib/custom/mtop';

// set mtop adapter
customAdapter('mtop', mtopAdapter);

Other notices

  • Auto-detect adapter logic
    • Specific options.type
    • Each custom adapter
    • Support fetch ? fetch : ajax

License

MIT License