@d-matrix/utils 1.3.0 → 1.4.0
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/dist/file.d.ts +7 -0
- package/dist/file.js +22 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/support.d.ts +12 -0
- package/dist/support.js +18 -0
- package/dist/types.d.ts +6 -0
- package/package.json +9 -4
- package/readme.md +53 -1
package/dist/file.d.ts
CHANGED
|
@@ -20,4 +20,11 @@ export declare const validateImageSize: (file: BlobPart | FileURL, limitSize: {
|
|
|
20
20
|
width: number;
|
|
21
21
|
height: number;
|
|
22
22
|
}, options?: BlobPropertyBag | undefined) => Promise<ImageSizeValidationResult>;
|
|
23
|
+
/**
|
|
24
|
+
* 检测图片地址是否可用
|
|
25
|
+
* @param src 图片地址
|
|
26
|
+
* @param img HTMLImageElement
|
|
27
|
+
* @returns Promise<boolean>
|
|
28
|
+
*/
|
|
29
|
+
export declare function isImageExists(src: string, img?: HTMLImageElement): Promise<boolean>;
|
|
23
30
|
export {};
|
package/dist/file.js
CHANGED
|
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.validateImageSize = exports.toImage = void 0;
|
|
39
|
+
exports.isImageExists = exports.validateImageSize = exports.toImage = void 0;
|
|
40
40
|
/**
|
|
41
41
|
* 转换BlobPart或者文件地址为图片对象
|
|
42
42
|
* @param file 传入文件 或者 url
|
|
@@ -87,3 +87,24 @@ var validateImageSize = function (file, limitSize, options) { return __awaiter(v
|
|
|
87
87
|
});
|
|
88
88
|
}); };
|
|
89
89
|
exports.validateImageSize = validateImageSize;
|
|
90
|
+
/**
|
|
91
|
+
* 检测图片地址是否可用
|
|
92
|
+
* @param src 图片地址
|
|
93
|
+
* @param img HTMLImageElement
|
|
94
|
+
* @returns Promise<boolean>
|
|
95
|
+
*/
|
|
96
|
+
function isImageExists(src, img) {
|
|
97
|
+
if (img === void 0) { img = new Image(); }
|
|
98
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
if (!src)
|
|
101
|
+
return [2 /*return*/, false];
|
|
102
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
103
|
+
img.src = src;
|
|
104
|
+
img.onload = function () { return resolve(true); };
|
|
105
|
+
img.onerror = function () { return resolve(false); };
|
|
106
|
+
})];
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
exports.isImageExists = isImageExists;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.file = exports.algorithm = exports.types = exports.date = exports.dom = exports.react = exports.clipboard = void 0;
|
|
22
|
+
exports.support = exports.file = exports.algorithm = exports.types = exports.date = exports.dom = exports.react = exports.clipboard = void 0;
|
|
23
23
|
exports.clipboard = __importStar(require("./clipboard"));
|
|
24
24
|
exports.react = __importStar(require("./react"));
|
|
25
25
|
exports.dom = __importStar(require("./dom"));
|
|
@@ -27,3 +27,4 @@ exports.date = __importStar(require("./date"));
|
|
|
27
27
|
exports.types = __importStar(require("./types"));
|
|
28
28
|
exports.algorithm = __importStar(require("./algorithm"));
|
|
29
29
|
exports.file = __importStar(require("./file"));
|
|
30
|
+
exports.support = __importStar(require("./support"));
|
package/dist/support.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSharedWorker = exports.isWebSocket = exports.isBrowserEnv = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 是否是浏览器环境
|
|
6
|
+
*/
|
|
7
|
+
var isBrowserEnv = function () { return typeof window !== 'undefined'; };
|
|
8
|
+
exports.isBrowserEnv = isBrowserEnv;
|
|
9
|
+
/**
|
|
10
|
+
* 是否支持WebSocket
|
|
11
|
+
*/
|
|
12
|
+
var isWebSocket = function () { return typeof WebSocket !== 'undefined'; };
|
|
13
|
+
exports.isWebSocket = isWebSocket;
|
|
14
|
+
/**
|
|
15
|
+
* 是否支持SharedWorker
|
|
16
|
+
*/
|
|
17
|
+
var isSharedWorker = function () { return typeof SharedWorker !== 'undefined'; };
|
|
18
|
+
exports.isSharedWorker = isSharedWorker;
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/** 指定的属性变为可选 */
|
|
1
2
|
export declare type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
3
|
+
/** 除了 K 的其他属性变成可选 */
|
|
4
|
+
export declare type ExcludePickPartial<T, K extends keyof T> = Partial<Omit<T, K>> & Pick<T, K>;
|
|
5
|
+
export declare type Undefinable<T> = {
|
|
6
|
+
[K in keyof T]: T[K] | undefined;
|
|
7
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-matrix/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "A dozen of utils for Front-End Development",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"prebuild": "npm run clean",
|
|
9
9
|
"clean": "rimraf dist",
|
|
10
10
|
"cy:open": "cypress open",
|
|
11
|
-
"cy:run": "cypress run"
|
|
11
|
+
"cy:run": "cypress run",
|
|
12
|
+
"test:tsd": "tsd"
|
|
12
13
|
},
|
|
13
14
|
"engines": {
|
|
14
15
|
"node": ">=16.20.0"
|
|
@@ -18,9 +19,12 @@
|
|
|
18
19
|
"url": "git+https://github.com/mrdulin/dm-utils.git"
|
|
19
20
|
},
|
|
20
21
|
"files": [
|
|
21
|
-
"dist"
|
|
22
|
+
"dist",
|
|
23
|
+
"readme.md"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [
|
|
26
|
+
"utils"
|
|
22
27
|
],
|
|
23
|
-
"keywords": [],
|
|
24
28
|
"author": "Lin Du",
|
|
25
29
|
"license": "MIT",
|
|
26
30
|
"bugs": {
|
|
@@ -37,6 +41,7 @@
|
|
|
37
41
|
"devDependencies": {
|
|
38
42
|
"@vitejs/plugin-react": "^4.2.1",
|
|
39
43
|
"cypress": "^13.6.6",
|
|
44
|
+
"expect-type": "^0.19.0",
|
|
40
45
|
"rimraf": "^5.0.5",
|
|
41
46
|
"vite": "^4.5.2"
|
|
42
47
|
}
|
package/readme.md
CHANGED
|
@@ -12,7 +12,9 @@ A dozen of utils for Front-End Development
|
|
|
12
12
|
- [dom](#dom)
|
|
13
13
|
- [date](#date)
|
|
14
14
|
- [types](#types)
|
|
15
|
-
- [algorithm](
|
|
15
|
+
- [algorithm](#algorithm)
|
|
16
|
+
- [file](#file)
|
|
17
|
+
- [support](#support)
|
|
16
18
|
|
|
17
19
|
### clipboard
|
|
18
20
|
|
|
@@ -115,6 +117,40 @@ interface ImageSizeValidationResult {
|
|
|
115
117
|
|
|
116
118
|
图片宽,高校验
|
|
117
119
|
|
|
120
|
+
- `isImageExists(src: string, img: HTMLImageElement = new Image()): Promise<boolean>`
|
|
121
|
+
|
|
122
|
+
检测图片地址是否可用
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { file } from '@d-matrix/utils';
|
|
126
|
+
|
|
127
|
+
const url = 'https://picsum.photos/200/300';
|
|
128
|
+
const res = await file.isImageExists(url);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
传入HTML中已经存在的`img`元素
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
import { file } from '@d-matrix/utils';
|
|
135
|
+
|
|
136
|
+
const $img = document.getElementById('img');
|
|
137
|
+
const res = await file.isImageExists(url, $img);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## support
|
|
141
|
+
|
|
142
|
+
- `isBrowserEnv(): boolean`
|
|
143
|
+
|
|
144
|
+
是否是浏览器环境
|
|
145
|
+
|
|
146
|
+
- `isWebSocket(): boolean`
|
|
147
|
+
|
|
148
|
+
是否支持WebSocket
|
|
149
|
+
|
|
150
|
+
- `isSharedWorker(): boolean`
|
|
151
|
+
|
|
152
|
+
是否支持SharedWorker
|
|
153
|
+
|
|
118
154
|
## 测试
|
|
119
155
|
|
|
120
156
|
运行全部组件测试
|
|
@@ -143,6 +179,22 @@ npm version <minor> or <major>...
|
|
|
143
179
|
npm build
|
|
144
180
|
```
|
|
145
181
|
|
|
182
|
+
发布:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
npm publish --access public
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
镜像站查询版本与手动同步:
|
|
189
|
+
|
|
190
|
+
[npm镜像站](https://npmmirror.com/package/@d-matrix/utils)
|
|
191
|
+
|
|
192
|
+
通过`git log`命令获取changelogs,用于填写GitHub Release内容:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
git log --oneline --decorate
|
|
196
|
+
```
|
|
197
|
+
|
|
146
198
|
## 注意事项
|
|
147
199
|
|
|
148
200
|
- [Before Publishing: Make Sure Your Package Installs and Works](https://docs.npmjs.com/cli/v10/using-npm/developers/#before-publishing-make-sure-your-package-installs-and-works)
|