@base-web-kits/base-tools-ts 1.3.10 → 1.3.11

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.
@@ -8,7 +8,8 @@ export * from './index.d';
8
8
  * @returns 处理后的图片URL(格式: `{src}?x-oss-process=image/xx`)
9
9
  * @example
10
10
  * 缩放: getOSSImg('xx.jpg', { resize: { w: 100, h: 100 } })
11
- * 水印: getOSSImg('xx.jpg', { watermark: { text: '水印' } });
11
+ * 文本水印: getOSSImg('xx.jpg', { watermark: { text: '水印' } });
12
+ * 图片水印: getOSSImg('xx.jpg', { watermark: { image: 'https://xx.png' } });
12
13
  * 翻转: getOSSImg('xx.jpg', { flip: 1 });
13
14
  * 裁剪: getOSSImg('xx.jpg', { crop: { w: 100, h: 100 } });
14
15
  * 质量: getOSSImg('xx.jpg', { quality: { q: 80 } });
@@ -34,13 +35,11 @@ export declare function getOSSImg(src: string, option: OSSImgOption): string;
34
35
  * @param option 视频处理选项
35
36
  * @returns 处理后的URL(格式: `{src}?x-oss-process=video/xx`)
36
37
  * @example
37
- * 视频转码: getOSSVideo('xx.mp4', { convert: { format: 'mp4' } })
38
- * 转为动图: getOSSVideo('xx.mp4', { animation: { format: 'gif' } })
39
- * 雪碧图: getOSSVideo('xx.mp4', { sprite: { format: 'png' } })
40
- * 多帧截取: getOSSVideo('xx.mp4', { snapshots: { count: 3 } })
41
- * 视频拼接: getOSSVideo('xx.mp4', { concat: { list: 'a.mp4,b.mp4' } })
42
- * 信息查询: getOSSVideo('xx.mp4', { info: true })
43
- * 组合操作: getOSSVideo('xx.mp4', { convert: { format: 'mp4' }, snapshots: { count: 3 } })
38
+ * 单帧截取: getOSSVideo('xx.mp4', { snapshot: { t: 0, f: 'jpg', w: 800 } })
39
+ * 多帧截取: getOSSVideo('xx.mp4', { snapshots: { f: 'jpg' } })
40
+ * 转为动图: getOSSVideo('xx.mp4', { animation: { f: 'gif' } })
41
+ * 视频转码: getOSSVideo('xx.mp4', { convert: { f: 'mp4' } })
42
+ * 信息提取: getOSSVideo('xx.mp4', { info: true })
44
43
  */
45
44
  export declare function getOSSVideo(src: string, option: OSSVideoOption): string;
46
45
  /**
@@ -50,8 +49,7 @@ export declare function getOSSVideo(src: string, option: OSSVideoOption): string
50
49
  * @param option 音频处理选项
51
50
  * @returns 处理后的URL(格式: `{src}?x-oss-process=audio/xx`)
52
51
  * @example
53
- * 音频转码: getOSSAudio('xx.mp3', { 'convert': { format: 'mp3' } })
54
- * 音频拼接: getOSSAudio('xx.mp3', { 'concat': { list: 'a.mp3,b.mp3' } })
52
+ * 音频转码: getOSSAudio('xx.mp3', { 'convert': { f: 'mp3' } })
55
53
  * 信息查询: getOSSAudio('xx.mp3', { 'info': true })
56
54
  */
57
55
  export declare function getOSSAudio(src: string, option: OSSAudioOption): string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ts/url/oss/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,cAAc,EAEf,MAAM,WAAW,CAAC;AAEnB,cAAc,WAAW,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,UAE1D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,UAE9D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,UAE9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,UAE1D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,UAkBvE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ts/url/oss/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,cAAc,EAEf,MAAM,WAAW,CAAC;AAEnB,cAAc,WAAW,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,UAE1D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,UAE9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,UAE9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,UAE1D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,UAkBvE"}
package/package.json CHANGED
@@ -1,39 +1,39 @@
1
- {
2
- "name": "@base-web-kits/base-tools-ts",
3
- "version": "1.3.10",
4
- "sideEffects": false,
5
- "description": "Independent TS utilities package built from src/ts.",
6
- "keywords": [
7
- "base-tools",
8
- "ts",
9
- "utilities"
10
- ],
11
- "license": "MIT",
12
- "main": "./dist/index.cjs",
13
- "module": "./dist/index.mjs",
14
- "types": "./dist/index.d.ts",
15
- "exports": {
16
- ".": {
17
- "types": "./dist/index.d.ts",
18
- "import": "./dist/index.mjs",
19
- "require": "./dist/index.cjs"
20
- }
21
- },
22
- "files": [
23
- "dist",
24
- "README.md",
25
- "src"
26
- ],
27
- "dependencies": {
28
- "es-toolkit": "^1.44.0",
29
- "bignumber.js": "^9.1.2",
30
- "dayjs": "^1.11.19",
31
- "mitt": "^3.0.1"
32
- },
33
- "peerDependencies": {
34
- "dayjs": "^1.0.0"
35
- },
36
- "publishConfig": {
37
- "registry": "https://registry.npmjs.org"
38
- }
39
- }
1
+ {
2
+ "name": "@base-web-kits/base-tools-ts",
3
+ "version": "1.3.11",
4
+ "sideEffects": false,
5
+ "description": "Independent TS utilities package built from src/ts.",
6
+ "keywords": [
7
+ "base-tools",
8
+ "ts",
9
+ "utilities"
10
+ ],
11
+ "license": "MIT",
12
+ "main": "./dist/index.cjs",
13
+ "module": "./dist/index.mjs",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.mjs",
19
+ "require": "./dist/index.cjs"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md",
25
+ "src"
26
+ ],
27
+ "dependencies": {
28
+ "es-toolkit": "^1.44.0",
29
+ "bignumber.js": "^9.1.2",
30
+ "dayjs": "^1.11.19",
31
+ "mitt": "^3.0.1"
32
+ },
33
+ "peerDependencies": {
34
+ "dayjs": "^1.0.0"
35
+ },
36
+ "publishConfig": {
37
+ "registry": "https://registry.npmjs.org"
38
+ }
39
+ }
@@ -71,6 +71,21 @@ export function toDayjs(t?: BaseTime, fmt?: dayjs.OptionType) {
71
71
  return dayjs(t, fmt);
72
72
  }
73
73
 
74
+ /**
75
+ * 格式时间
76
+ * @param t 时间
77
+ * @param fmt 日期格式,默认 `YYYY-MM-DD HH:mm:ss`
78
+ * @returns 格式化后的日期字符串
79
+ * @example
80
+ * dateFormat(1765337596913) // "2025-12-10 11:33:16"
81
+ * dateFormat(1765337596913, 'YYYY-MM-DD HH:mm:ss.SSS') // "2025-12-10 11:33:16.913"
82
+ * dateFormat('2025-12-10 11:33:16', 'YYYY年MM月DD日') // "2025年12月10日"
83
+ */
84
+ export function dateFormat(t?: BaseTime, fmt = 'YYYY-MM-DD HH:mm:ss') {
85
+ if (!t) return '';
86
+ return toDayjs(t).format(fmt);
87
+ }
88
+
74
89
  /**
75
90
  * 获取“前几天”的日期范围
76
91
  * @param offset 正整数天数
@@ -17,7 +17,8 @@ export * from './index.d';
17
17
  * @returns 处理后的图片URL(格式: `{src}?x-oss-process=image/xx`)
18
18
  * @example
19
19
  * 缩放: getOSSImg('xx.jpg', { resize: { w: 100, h: 100 } })
20
- * 水印: getOSSImg('xx.jpg', { watermark: { text: '水印' } });
20
+ * 文本水印: getOSSImg('xx.jpg', { watermark: { text: '水印' } });
21
+ * 图片水印: getOSSImg('xx.jpg', { watermark: { image: 'https://xx.png' } });
21
22
  * 翻转: getOSSImg('xx.jpg', { flip: 1 });
22
23
  * 裁剪: getOSSImg('xx.jpg', { crop: { w: 100, h: 100 } });
23
24
  * 质量: getOSSImg('xx.jpg', { quality: { q: 80 } });
@@ -46,13 +47,11 @@ export function getOSSImg(src: string, option: OSSImgOption) {
46
47
  * @param option 视频处理选项
47
48
  * @returns 处理后的URL(格式: `{src}?x-oss-process=video/xx`)
48
49
  * @example
49
- * 视频转码: getOSSVideo('xx.mp4', { convert: { format: 'mp4' } })
50
- * 转为动图: getOSSVideo('xx.mp4', { animation: { format: 'gif' } })
51
- * 雪碧图: getOSSVideo('xx.mp4', { sprite: { format: 'png' } })
52
- * 多帧截取: getOSSVideo('xx.mp4', { snapshots: { count: 3 } })
53
- * 视频拼接: getOSSVideo('xx.mp4', { concat: { list: 'a.mp4,b.mp4' } })
54
- * 信息查询: getOSSVideo('xx.mp4', { info: true })
55
- * 组合操作: getOSSVideo('xx.mp4', { convert: { format: 'mp4' }, snapshots: { count: 3 } })
50
+ * 单帧截取: getOSSVideo('xx.mp4', { snapshot: { t: 0, f: 'jpg', w: 800 } })
51
+ * 多帧截取: getOSSVideo('xx.mp4', { snapshots: { f: 'jpg' } })
52
+ * 转为动图: getOSSVideo('xx.mp4', { animation: { f: 'gif' } })
53
+ * 视频转码: getOSSVideo('xx.mp4', { convert: { f: 'mp4' } })
54
+ * 信息提取: getOSSVideo('xx.mp4', { info: true })
56
55
  */
57
56
  export function getOSSVideo(src: string, option: OSSVideoOption) {
58
57
  return buildOSSUrl(src, 'video', option);
@@ -65,8 +64,7 @@ export function getOSSVideo(src: string, option: OSSVideoOption) {
65
64
  * @param option 音频处理选项
66
65
  * @returns 处理后的URL(格式: `{src}?x-oss-process=audio/xx`)
67
66
  * @example
68
- * 音频转码: getOSSAudio('xx.mp3', { 'convert': { format: 'mp3' } })
69
- * 音频拼接: getOSSAudio('xx.mp3', { 'concat': { list: 'a.mp3,b.mp3' } })
67
+ * 音频转码: getOSSAudio('xx.mp3', { 'convert': { f: 'mp3' } })
70
68
  * 信息查询: getOSSAudio('xx.mp3', { 'info': true })
71
69
  */
72
70
  export function getOSSAudio(src: string, option: OSSAudioOption) {
@@ -120,7 +118,7 @@ export function buildOSSUrl(src: string, type: string, option: OSSOption) {
120
118
  * @param option 图片处理选项
121
119
  * @returns `object`返回格式为`resize,w_100,h_100`
122
120
  * @returns `number`返回格式为`flip,1`
123
- * @returns `string`返回格式为`format,jpg`
121
+ * @returns `string`返回格式为`f,jpg`
124
122
  * @returns `true`返回格式为`info`, `false`返回空字符串
125
123
  */
126
124
  function getOSSSegs(type: string, option?: Record<string, unknown> | number | string | boolean) {