New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

common-cores

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

common-cores

一些通用函数和方法

  • 0.0.4
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Install

npm install common-cores

yarn add common-cores

pnpm add common-cores

Description

使用typescript的通用api仓库,目前只有dayjs、http和其常用的方法,http是对fetch进行封装的一个请求库,。后续会添加更多的api。

Usage dayjs

import { dayjs } from 'common-cores';

<script>

dayjs().add(1,'day').format('YYYY-MM-DD');

dayjs('2020-01-01').subtract(10,'month').format('YYYY-MM-DD');

dayjs('2023/03/10 10:10:10').format('YYYY-MM-DD HH:mm:ss');

dayjs().getYear();
dayjs().getMonth();
dayjs().valueOf();

dayjs().compare('2020-01-01');

</script>

Usage http

import { http } from 'common-cores';

<script>

<!-- 接口请求 -->
http('user/page',{ method: 'post',data: { page: 1, size: 10 }}).then(res=>res);
http('user/detail/1').then(res=>res).catch(err=>err);
http('user/delete',{ method: 'delete',data:[1,2,3] }).then(res=>res).catch(err=>err);

<!-- 创建实例,实例会有相应和请求拦截器 -->
const httpInstance = http.create({
    baseURL: 'api/',
    timeout: 10000,
    headers: {
        'Content-Type': 'application/json'
    }
});

<!-- 请求拦截器 -->
httpInstance.rerequestInterceptor(config=>{
    config.headers['Authorization'] = 'token';
    return config;
});

<!-- 响应拦截器 -->
httpInstance.rereponseInterceptor(response=>{
    return response;
},error=>{
    
})

<!-- 接口请求 -->
httpInstance('user/page',{ method: 'post',data: { page: 1, size: 10 }}).then(res=>res);
httpInstance('user/detail/1').then(res=>res).catch(err=>err);
httpInstance('user/delete',{ method: 'delete',data:[1,2,3] }).then(res=>res).catch(err=>err);

</script>

Keywords

FAQs

Package last updated on 22 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc