tools_dj 1.0.54 → 1.0.59
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/lib/date.d.ts +41 -0
- package/lib/date.js +1 -0
- package/lib/request.d.ts +47 -0
- package/lib/request.js +1 -0
- package/package.json +1 -1
package/lib/date.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** 2025/4/11 11:26 User: DJ
|
|
2
|
+
* content: 时间比较类
|
|
3
|
+
*/
|
|
4
|
+
declare class contrast {
|
|
5
|
+
date: number;
|
|
6
|
+
constructor(date: Date);
|
|
7
|
+
/** 2025/4/11 14:10 User: DJ
|
|
8
|
+
* content: 大于
|
|
9
|
+
*/
|
|
10
|
+
Gt(date: Date): boolean;
|
|
11
|
+
/** 2025/4/11 14:10 User: DJ
|
|
12
|
+
* content: 小于
|
|
13
|
+
*/
|
|
14
|
+
Lt(date: Date): boolean;
|
|
15
|
+
/** 2025/4/11 14:10 User: DJ
|
|
16
|
+
* content: 等于
|
|
17
|
+
*/
|
|
18
|
+
Eq(date: Date): boolean;
|
|
19
|
+
/** 2025/4/11 14:10 User: DJ
|
|
20
|
+
* content: 不等于
|
|
21
|
+
*/
|
|
22
|
+
Ne(date: Date): boolean;
|
|
23
|
+
/** 2025/4/11 14:11 User: DJ
|
|
24
|
+
* content: 大于等于
|
|
25
|
+
*/
|
|
26
|
+
Gte(date: Date): boolean;
|
|
27
|
+
/** 2025/4/11 14:11 User: DJ
|
|
28
|
+
* content: 小于等于
|
|
29
|
+
*/
|
|
30
|
+
Lte(date: Date): boolean;
|
|
31
|
+
/** 2025/4/11 14:11 User: DJ
|
|
32
|
+
* content: 是否在某个时间段
|
|
33
|
+
*/
|
|
34
|
+
Between(date1: Date, date2: Date): boolean;
|
|
35
|
+
}
|
|
36
|
+
declare function carbon(date: Date): contrast;
|
|
37
|
+
declare const _default: {
|
|
38
|
+
carbon: typeof carbon;
|
|
39
|
+
contrast: typeof contrast;
|
|
40
|
+
};
|
|
41
|
+
export default _default;
|
package/lib/date.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});const e=require("./index");class t{constructor(t){if("Date"!==(0,e.is)(t))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");this.date=t.getTime()}Gt(t){if("Date"!==(0,e.is)(t))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=t.getTime();return this.date>r}Lt(t){if("Date"!==(0,e.is)(t))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=t.getTime();return this.date<r}Eq(t){if("Date"!==(0,e.is)(t))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=t.getTime();return this.date==r}Ne(t){if("Date"!==(0,e.is)(t))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=t.getTime();return this.date!=r}Gte(t){if("Date"!==(0,e.is)(t))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=t.getTime();return this.date>=r}Lte(t){if("Date"!==(0,e.is)(t))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let r=t.getTime();return this.date<=r}Between(t,r){if("Date"!==(0,e.is)(t))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");if("Date"!==(0,e.is)(r))throw new Error("Invalid date: 必须提供一个有效的 Date 对象");let a=t.getTime(),i=r.getTime();return this.date>=a&&this.date<=i||this.date>=i&&this.date<=a}}exports.default={carbon:function(e){return new t(e)},contrast:t};
|
package/lib/request.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
interface conf {
|
|
2
|
+
baseUrl?: string;
|
|
3
|
+
timeout?: number;
|
|
4
|
+
callback?: any;
|
|
5
|
+
abController?: any;
|
|
6
|
+
}
|
|
7
|
+
/** 2025/3/31 15:54 User: DJ
|
|
8
|
+
* content: fetch请求
|
|
9
|
+
* method: "POST"
|
|
10
|
+
* 指定 HTTP 请求方法。在这里是 POST,意味着客户端请求是为了向服务器发送数据。与之相对的还有 GET、PUT、DELETE 等方法。
|
|
11
|
+
* mode: "cors"
|
|
12
|
+
* 这个设置指定请求的跨域策略。cors 是跨源资源共享(Cross-Origin Resource Sharing)的缩写。当使用 cors 时,浏览器允许在不同域之间发起请求。如果不设置,默认值通常是 same-origin,即只允许发起同源请求(即 URL 与当前页面相同的请求)。
|
|
13
|
+
* cache: "no-cache"
|
|
14
|
+
* 缓存策略,设置为 no-cache 时,意味着不使用缓存,每次请求都会从服务器获取最新的数据。其他常见的值有 default(默认策略)、reload(重新加载)、force-cache(强制使用缓存)等。
|
|
15
|
+
* credentials: "same-origin"
|
|
16
|
+
* 这个设置决定了请求是否包含凭证信息(如 Cookies)。same-origin 表示仅在同源请求中发送凭证信息。如果设置为 include,即使是跨域请求,也会发送凭证。如果设置为 omit,则无论请求是否跨域,均不会发送凭证。
|
|
17
|
+
* headers: { "Content-Type": "application/json" }
|
|
18
|
+
* 请求头,Content-Type 表示请求体的内容类型。在这里,我们将其设置为 application/json,表示请求体的数据是 JSON 格式。其他常见的类型包括 application/x-www-form-urlencoded、multipart/form-data 等。
|
|
19
|
+
* redirect: "follow"
|
|
20
|
+
* 这个设置指定如何处理 HTTP 重定向。follow 表示如果服务器返回重定向响应(如 301 或 302),浏览器会自动跟随该重定向。其他选项包括 manual(需要手动处理重定向)和 error(遇到重定向直接报错)。
|
|
21
|
+
* referrerPolicy: "no-referrer"
|
|
22
|
+
* 这个设置控制请求的引用来源信息(Referrer)的处理方式。no-referrer 表示不发送任何引用来源信息。其他常见的选项有:
|
|
23
|
+
* no-referrer-when-downgrade(只有在从 HTTPS 到 HTTP 的情况下才不发送引用信息)
|
|
24
|
+
* origin(仅发送源信息)
|
|
25
|
+
* strict-origin(仅在 HTTPS 请求中发送完整的引用信息)
|
|
26
|
+
* body: JSON.stringify(data)
|
|
27
|
+
* 请求的主体内容。我们将 data 对象转化为 JSON 字符串发送到服务器。body 是 POST 请求的主要部分,用来发送需要提交的数据。在这里,我们通过 JSON.stringify(data) 将 JavaScript 对象转换为 JSON 字符串。
|
|
28
|
+
*/
|
|
29
|
+
export default class {
|
|
30
|
+
options: any;
|
|
31
|
+
conf: conf;
|
|
32
|
+
/** 2024/12/24 10:07 User: DJ
|
|
33
|
+
* content: 请求处理
|
|
34
|
+
* @param option 请求头配置参数
|
|
35
|
+
* @param conf 配置
|
|
36
|
+
* @param conf.callback 成功回调
|
|
37
|
+
* @param conf.abController 配置中断控制
|
|
38
|
+
* @param conf.timeout 超时
|
|
39
|
+
* @param conf.baseUrl 前缀
|
|
40
|
+
*/
|
|
41
|
+
constructor(option?: any, conf?: conf);
|
|
42
|
+
/** 2025/3/28 15:55 User: DJ
|
|
43
|
+
* content: 创建服务
|
|
44
|
+
*/
|
|
45
|
+
serve(url?: string, options?: any, conf?: conf): Promise<any>;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
package/lib/request.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});exports.default=class{constructor(t={},e={}){this.options={},this.conf={baseUrl:"",timeout:6e3},this.options=t,Object.assign(this.conf,e)}serve(t="",e={},s={}){const o=Object.assign(Object.assign({},this.conf),s),c=Object.assign(Object.assign({},this.options),e),{timeout:n=6e3,baseUrl:i}=o;t=i+t;const a=new AbortController,r=a.signal;o.abController&&o.abController(a);const l=setTimeout((()=>{a.abort()}),n);return fetch(t,Object.assign(Object.assign({},c),{signal:r})).then((t=>(clearTimeout(l),o.callback?o.callback(t):t))).catch((t=>(clearTimeout(l),Promise.reject(t))))}};
|