frog-request 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Frog Request
2
+
3
+ - 一个轻量的axios封装库
4
+ - 支持请求拦截器、响应拦截器、错误处理等功能
5
+ - 支持自定义配置项,如超时时间、请求头、请求体等
@@ -0,0 +1,18 @@
1
+ import * as axios$1 from "axios";
2
+ import { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from "axios";
3
+
4
+ //#region src/axios.d.ts
5
+ type CreateAxiosRequestOptions = AxiosRequestConfig & {
6
+ handleRequestError?: (error: AxiosError) => Promise<AxiosError>;
7
+ handleResponseError?: (error: AxiosError) => Promise<AxiosError>;
8
+ handleRequestSuccess?: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig;
9
+ handleResponseSuccess?: (response: AxiosResponse) => AxiosResponse;
10
+ };
11
+ /**
12
+ * 创建 axios 基础实例
13
+ * @param options 配置选项
14
+ * @returns axios 实例
15
+ */
16
+ declare function createAxiosRequest(options: CreateAxiosRequestOptions): axios$1.AxiosInstance;
17
+ //#endregion
18
+ export { createAxiosRequest };
package/dist/index.mjs ADDED
@@ -0,0 +1,28 @@
1
+ import axios from "axios";
2
+ //#region src/axios.ts
3
+ /**
4
+ * 创建 axios 基础实例
5
+ * @param options 配置选项
6
+ * @returns axios 实例
7
+ */
8
+ function createAxiosRequest(options) {
9
+ const instance = axios.create({
10
+ baseURL: options.baseURL || "/api",
11
+ timeout: options.timeout || 1e4,
12
+ headers: options.headers || {},
13
+ ...options
14
+ });
15
+ instance.interceptors.request.use((config) => {
16
+ return options.handleRequestSuccess?.(config) || config;
17
+ }, (error) => {
18
+ return options.handleRequestError?.(error) || Promise.reject(error);
19
+ });
20
+ instance.interceptors.response.use((response) => {
21
+ return options.handleResponseSuccess?.(response) || response;
22
+ }, (error) => {
23
+ return options.handleResponseError?.(error) || Promise.reject(error);
24
+ });
25
+ return instance;
26
+ }
27
+ //#endregion
28
+ export { createAxiosRequest };
package/package.json CHANGED
@@ -1,15 +1,82 @@
1
- {
2
- "name": "frog-request",
3
- "version": "0.0.1",
4
- "type": "module",
5
- "private": false,
6
- "description": "",
7
- "main": "src/index.ts",
8
- "keywords": [
9
- "frog",
10
- "request"
11
- ],
12
- "author": "",
13
- "license": "ISC",
14
- "scripts": {}
15
- }
1
+ {
2
+ "name": "frog-request",
3
+ "version": "0.0.2",
4
+ "private": false,
5
+ "description": "A simple request library based on axios",
6
+ "keywords": [
7
+ "frog",
8
+ "request"
9
+ ],
10
+ "license": "ISC",
11
+ "author": {
12
+ "name": "Silas",
13
+ "email": "frogfrog7423@gmail.com"
14
+ },
15
+ "files": [
16
+ "dist/**/*"
17
+ ],
18
+ "type": "module",
19
+ "types": "./dist/index.d.mts",
20
+ "exports": {
21
+ ".": "./dist/index.mjs",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "scripts": {
28
+ "build": "tsdown",
29
+ "dev": "tsdown --watch",
30
+ "lint": "oxlint",
31
+ "lint:fix": "oxlint --fix",
32
+ "fmt": "oxfmt",
33
+ "fmt:check": "oxfmt --check",
34
+ "spellcheck": "cspell .",
35
+ "commit": "git-cz",
36
+ "prepare": "husky",
37
+ "precommit": "lint-staged",
38
+ "test": "vitest",
39
+ "coverage": "vitest run --coverage",
40
+ "lintall": "pnpm run lint && pnpm run fmt && pnpm run spellcheck"
41
+ },
42
+ "dependencies": {
43
+ "axios": "^1.12.2"
44
+ },
45
+ "devDependencies": {
46
+ "@arethetypeswrong/core": "^0.18.2",
47
+ "@commitlint/cli": "^20.5.0",
48
+ "@commitlint/config-conventional": "^20.5.0",
49
+ "@cspell/dict-lorem-ipsum": "^4.0.5",
50
+ "commitizen": "^4.3.1",
51
+ "cspell": "^9.7.0",
52
+ "cz-git": "^1.12.0",
53
+ "husky": "^9.1.7",
54
+ "lint-staged": "^16.4.0",
55
+ "oxfmt": "^0.41.0",
56
+ "oxlint": "^1.56.0",
57
+ "publint": "^0.3.18",
58
+ "tsdown": "^0.21.4",
59
+ "typescript": "^5.9.3",
60
+ "vitest": "^4.1.0"
61
+ },
62
+ "peerDependencies": {
63
+ "axios": "^1.12.2"
64
+ },
65
+ "lint-staged": {
66
+ "*.{js,jsx,ts,tsx,mjs,cjs}": [
67
+ "pnpm run lint:fix",
68
+ "pnpm run fmt --no-error-on-unmatched-pattern"
69
+ ]
70
+ },
71
+ "config": {
72
+ "commitizen": {
73
+ "path": "node_modules/cz-git"
74
+ }
75
+ },
76
+ "engines": {
77
+ "node": ">=22.18.0",
78
+ "npm": ">=11.4.2",
79
+ "pnpm": ">=10.11.0"
80
+ },
81
+ "packageManager": "pnpm@10.11.0"
82
+ }
package/src/axios.ts DELETED
@@ -1,52 +0,0 @@
1
- import axios, {
2
- AxiosError,
3
- type AxiosRequestConfig,
4
- type AxiosResponse,
5
- type InternalAxiosRequestConfig,
6
- } from 'axios';
7
-
8
- type CreateAxiosRequestOptions = AxiosRequestConfig & {
9
- handleRequestError?: (error: AxiosError) => Promise<AxiosError>;
10
- handleResponseError?: (error: AxiosError) => Promise<AxiosError>;
11
- handleRequestSuccess?: (
12
- config: InternalAxiosRequestConfig,
13
- ) => InternalAxiosRequestConfig;
14
- handleResponseSuccess?: (response: AxiosResponse) => AxiosResponse;
15
- };
16
-
17
- /**
18
- * 创建 axios 基础实例
19
- * @param options 配置选项
20
- * @returns axios 实例
21
- */
22
- export function createAxiosRequest(options: CreateAxiosRequestOptions) {
23
- // 创建 axios 实例
24
- const instance = axios.create({
25
- baseURL: options.baseURL || '/api',
26
- timeout: options.timeout || 10000,
27
- headers: options.headers || {},
28
- ...options,
29
- });
30
-
31
- // 请求拦截器
32
- instance.interceptors.request.use(
33
- (config) => {
34
- return options.handleRequestSuccess?.(config) || config;
35
- },
36
- (error) => {
37
- return options.handleRequestError?.(error) || Promise.reject(error);
38
- },
39
- );
40
-
41
- // 响应拦截器
42
- instance.interceptors.response.use(
43
- (response) => {
44
- return options.handleResponseSuccess?.(response) || response;
45
- },
46
- (error) => {
47
- return options.handleResponseError?.(error) || Promise.reject(error);
48
- },
49
- );
50
-
51
- return instance;
52
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './axios';