@aistarfish/utils

0.1.28 • Public • Published

frontend-utils

介绍

前端工具库

发布

npm run build

getUrlParams

返回 url 参数

const params = getUrlParams('?aaa=bbb'); // { aaa: 'bbb' }

fetch

对 fetch 进行了一些封装处理

// post
fetch('http://example.com', {
  method: 'post',
  data: { name: '张三', account: '12345' },
}).then((res) => {
if (res && res.code === 'SUCCESS') {
  ...
}
...
}).catch(err => console.log(err));

// get
fetch('http://example.com', {
  method: 'get',
  data: { name: '张三', account: '12345' },
}).then((res) => {
if (res && res.code === 'SUCCESS') {
  ...
}
...
}).catch(err => console.log(err));

pointer

链式调用,避免报错:Uncaught TypeError: Cannot read property 'xxx' of undefined

const a = { a: { b: { c : 1 } } };
pointer(a).b.c(); // 1
pointer(a).c.c(); // undefined

showEllipsis

超出一定字数显示...

const str = '一个矢量图标管理平台,可以用字体代替繁多的小图片。';
showEllipsis(str, 4) // 一个矢量...

log

使用 console.log 打印对象,如果是对象使用 JSON.parse(JSON.stringify(xx)) 深拷贝,

const a = { a: { b: { c : 1 } } };
log(a); // { a: { b: { c : 1 } } }

stringify parse

qs 中的 stringify parse

debounce throttle isObject

lodash 中的 debounce throttle isObject

Readme

Keywords

Package Sidebar

Install

npm i @aistarfish/utils

Weekly Downloads

1

Version

0.1.28

License

ISC

Unpacked Size

207 kB

Total Files

36

Last publish

Collaborators

  • lw_windy
  • doin0719
  • doin
  • yunque.wly
  • chujiu
  • stuartpounds
  • fantasy123
  • wangqi_sl
  • liuhao1
  • yiyun220