@alemonjs/kook 0.2.2 → 0.2.5

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.
@@ -2,44 +2,45 @@
2
2
  * 基础配置结构
3
3
  */
4
4
  class BaseConfig {
5
- #data = null
6
- constructor(val) {
7
- this.#data = val
8
- }
9
- /**
10
- * 设置配置
11
- * @param key
12
- * @param val
13
- */
14
- set(key, val) {
15
- if (val !== undefined) this.#data[key] = val
16
- return this
17
- }
18
- /**
19
- *
20
- * @param key
21
- * @returns
22
- */
23
- has(key) {
24
- if (Object.prototype.hasOwnProperty.call(this.#data, key));
25
- return false
26
- }
27
- /**
28
- * 读取配置
29
- * @param key
30
- * @returns
31
- */
32
- all() {
33
- return this.#data
34
- }
35
- /**
36
- * 读取配置
37
- * @param key
38
- * @returns
39
- */
40
- get(key) {
41
- return this.#data[key]
42
- }
5
+ #data = null;
6
+ constructor(val) {
7
+ this.#data = val;
8
+ }
9
+ /**
10
+ * 设置配置
11
+ * @param key
12
+ * @param val
13
+ */
14
+ set(key, val) {
15
+ if (val !== undefined)
16
+ this.#data[key] = val;
17
+ return this;
18
+ }
19
+ /**
20
+ *
21
+ * @param key
22
+ * @returns
23
+ */
24
+ has(key) {
25
+ if (Object.prototype.hasOwnProperty.call(this.#data, key)) ;
26
+ return false;
27
+ }
28
+ /**
29
+ * 读取配置
30
+ * @param key
31
+ * @returns
32
+ */
33
+ all() {
34
+ return this.#data;
35
+ }
36
+ /**
37
+ * 读取配置
38
+ * @param key
39
+ * @returns
40
+ */
41
+ get(key) {
42
+ return this.#data[key];
43
+ }
43
44
  }
44
45
 
45
- export { BaseConfig }
46
+ export { BaseConfig };
@@ -1,7 +1,7 @@
1
- import { existsSync, createReadStream } from 'fs'
2
- import { Readable, isReadable } from 'stream'
3
- import { basename } from 'path'
4
- import { fileTypeFromBuffer, fileTypeFromStream } from 'file-type'
1
+ import { existsSync, createReadStream } from 'fs';
2
+ import { Readable, isReadable } from 'stream';
3
+ import { basename } from 'path';
4
+ import { fileTypeFromBuffer, fileTypeFromStream } from 'file-type';
5
5
 
6
6
  /**
7
7
  * 创建form
@@ -10,26 +10,33 @@ import { fileTypeFromBuffer, fileTypeFromStream } from 'file-type'
10
10
  * @returns
11
11
  */
12
12
  async function createPicFrom(image, name = 'image.jpg') {
13
- let picData
14
- // 是 string
15
- if (typeof image === 'string') {
16
- if (!existsSync(image)) return false
17
- if (!name) name = basename(image)
18
- picData = createReadStream(image)
19
- // buffer
20
- } else if (Buffer.isBuffer(image)) {
21
- if (!name) name = 'file.' + (await fileTypeFromBuffer(image)).ext
22
- picData = new Readable()
23
- picData.push(image)
24
- picData.push(null)
25
- // 文件流
26
- } else if (isReadable(image)) {
27
- if (!name) name = 'file.' + (await fileTypeFromStream(image)).ext
28
- picData = image
29
- } else {
30
- return false
31
- }
32
- return { picData, image, name }
13
+ let picData;
14
+ // 是 string
15
+ if (typeof image === 'string') {
16
+ if (!existsSync(image))
17
+ return false;
18
+ if (!name)
19
+ name = basename(image);
20
+ picData = createReadStream(image);
21
+ // buffer
22
+ }
23
+ else if (Buffer.isBuffer(image)) {
24
+ if (!name)
25
+ name = 'file.' + (await fileTypeFromBuffer(image)).ext;
26
+ picData = new Readable();
27
+ picData.push(image);
28
+ picData.push(null);
29
+ // 文件流
30
+ }
31
+ else if (isReadable(image)) {
32
+ if (!name)
33
+ name = 'file.' + (await fileTypeFromStream(image)).ext;
34
+ picData = image;
35
+ }
36
+ else {
37
+ return false;
38
+ }
39
+ return { picData, image, name };
33
40
  }
34
41
 
35
- export { createPicFrom }
42
+ export { createPicFrom };