@irim/saber

A toolbox for http connect


Keywords
saber, fetch, request
License
BSD-3-Clause
Install
npm install @irim/saber@1.0.0

Documentation

saber tools

version license downloads

A toolbox for http connect.

Getting Started

  • $ npm install @irim/saber --save
import Saber from '@irim/saber';

const saber = new Saber(); // or saber = Saber.singleton()
saber.request('https://httpbin.org/post', {
  method: 'POST',
  data: { foo: 'bar' },
}).then(response => {
  console.log('> response: ', response);
});

Advanced

import Saber from '@irim/saber';

const saber = new Saber();
// add a middleware
saber.use(async ctx => {
  console.log('>>>> before...');
  await ctx.next();
  console.log('>>> after ...');
});

API

工具类方法

  1. serialize 参数序列化
import { serialize } from '@irim/saber';

serialize({ a: 1001, b: 'foo' }); // a=1001&b=foo
serialize({ a: [100, 200] }); // a[]=100&a[]=200
serialize({ a: [100, 200] }, false, 'JOIN'); // a=100,200
serialize({ a: [100, 200] }, false, 'REPEAT'); // a=100&a=200
  1. random 返回范围内的随机整数
import { random } from '@irim/saber';

random(); // 0 ~ 100
random(50); // 0 ~ 50
random(25, 75); // 25 ~ 75
  1. uuid 返回一个唯一的 guid
import { uuid } from '@irim/saber';

uuid(); // unique string, never repeat
  1. logger 打印日志
import { logger } from '@irim/saber';

logger.debug('hello world~');
logger.info('hello world~');
logger.success('hello world~');
logger.warn('hello world~');
logger.error('hello world~');
logger.line('hello world~');

CHANGELOG

  • 1.1.0: 移除 socket 能力,fetcher 方法增加 dataType 参数
  • 1.2.0: 构建结果降级成 ES5
  • 1.3.0: 构建结果移除 dist

LICENSE

BSD-3-Clause License

Contact Us

CAIHUAZHI