@vope/utils 1.2.1 → 1.3.1

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/cjs/encoding.js CHANGED
@@ -2,13 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utf8_first_prefix = /^1{2,}/g;
4
4
  const utf8_other_prefix = /^10/;
5
- var Encodes;
6
- (function (Encodes) {
7
- Encodes["UTF_8"] = "utf-8";
8
- Encodes["UTF_16LE"] = "utf-16le";
9
- Encodes["UTF_16BE"] = "utf-16be";
10
- Encodes["GBK"] = "gbk";
11
- })(Encodes || (Encodes = {}));
5
+ const Encodes = {
6
+ UTF_8: 'utf-8',
7
+ UTF_16LE: 'utf-16le',
8
+ UTF_16BE: 'utf-16be',
9
+ GBK: 'gbk'
10
+ };
12
11
  const defaults = {
13
12
  utf8: [0xef, 0xbb, 0xbf],
14
13
  };
@@ -65,7 +65,7 @@ class MemoryBasic {
65
65
  * 检测存储是否包含某种类型
66
66
  */
67
67
  includes(type) {
68
- return type in this.memorys;
68
+ return this.memorys.has(type);
69
69
  }
70
70
  /**
71
71
  * 获取指定类型存储数据
package/cjs/union.js CHANGED
@@ -2,24 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /**
4
4
  * 数据联合(用于需要对加入的数据进行智能提示)
5
- * @description 如果设置了formatter,则可以通过设置泛型R来变化Union.value的类型
6
5
  */
7
6
  class Union {
8
7
  key;
9
8
  formatter;
10
- #map = {};
11
- get value() {
12
- return this.#map;
9
+ #data = {};
10
+ #options = {};
11
+ get data() {
12
+ return this.#data;
13
+ }
14
+ get options() {
15
+ return this.#options;
13
16
  }
14
17
  constructor(key, formatter) {
15
18
  this.key = key;
16
19
  this.formatter = formatter;
17
20
  }
18
21
  add(data) {
19
- const { formatter } = this;
20
- this.#map[data[this.key]] = formatter
21
- ? formatter(data)
22
- : data;
22
+ const key = data[this.key];
23
+ const result = this.formatter(data);
24
+ this.#data[key] = result.data;
25
+ this.#options[key] = result.option;
23
26
  return this;
24
27
  }
25
28
  }
package/lib/encoding.js CHANGED
@@ -1,12 +1,11 @@
1
1
  const utf8_first_prefix = /^1{2,}/g;
2
2
  const utf8_other_prefix = /^10/;
3
- var Encodes;
4
- (function (Encodes) {
5
- Encodes["UTF_8"] = "utf-8";
6
- Encodes["UTF_16LE"] = "utf-16le";
7
- Encodes["UTF_16BE"] = "utf-16be";
8
- Encodes["GBK"] = "gbk";
9
- })(Encodes || (Encodes = {}));
3
+ const Encodes = {
4
+ UTF_8: 'utf-8',
5
+ UTF_16LE: 'utf-16le',
6
+ UTF_16BE: 'utf-16be',
7
+ GBK: 'gbk'
8
+ };
10
9
  const defaults = {
11
10
  utf8: [0xef, 0xbb, 0xbf],
12
11
  };
@@ -60,7 +60,7 @@ export default class MemoryBasic {
60
60
  * 检测存储是否包含某种类型
61
61
  */
62
62
  includes(type) {
63
- return type in this.memorys;
63
+ return this.memorys.has(type);
64
64
  }
65
65
  /**
66
66
  * 获取指定类型存储数据
package/lib/union.js CHANGED
@@ -1,23 +1,26 @@
1
1
  /**
2
2
  * 数据联合(用于需要对加入的数据进行智能提示)
3
- * @description 如果设置了formatter,则可以通过设置泛型R来变化Union.value的类型
4
3
  */
5
4
  export default class Union {
6
5
  key;
7
6
  formatter;
8
- #map = {};
9
- get value() {
10
- return this.#map;
7
+ #data = {};
8
+ #options = {};
9
+ get data() {
10
+ return this.#data;
11
+ }
12
+ get options() {
13
+ return this.#options;
11
14
  }
12
15
  constructor(key, formatter) {
13
16
  this.key = key;
14
17
  this.formatter = formatter;
15
18
  }
16
19
  add(data) {
17
- const { formatter } = this;
18
- this.#map[data[this.key]] = formatter
19
- ? formatter(data)
20
- : data;
20
+ const key = data[this.key];
21
+ const result = this.formatter(data);
22
+ this.#data[key] = result.data;
23
+ this.#options[key] = result.option;
21
24
  return this;
22
25
  }
23
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vope/utils",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,16 +1,10 @@
1
- declare enum Encodes {
2
- UTF_8 = "utf-8",
3
- UTF_16LE = "utf-16le",
4
- UTF_16BE = "utf-16be",
5
- GBK = "gbk"
6
- }
7
1
  /**
8
2
  * 根据文件内容判断文件的编码
9
3
  * @param uint 文件内容Uint8Array格式
10
4
  * @param limit 用于约束GBK和utf_8的判定上限
11
5
  */
12
6
  declare const getEncoding: (uint: Uint8Array, limit?: number) => {
13
- encoding: Encodes;
7
+ encoding: "utf-8" | "utf-16le" | "utf-16be" | "gbk";
14
8
  offset: number;
15
9
  };
16
10
  export default getEncoding;
package/types/union.d.ts CHANGED
@@ -1,21 +1,20 @@
1
1
  import { Revise } from '@vope/types';
2
- type IMap<K extends string, VV extends string, T extends {
3
- [key in K]: string;
4
- }> = {
5
- [key in VV]?: T;
6
- };
2
+ interface Result<Data, Option> {
3
+ data: Data;
4
+ option: Option;
5
+ }
7
6
  /**
8
7
  * 数据联合(用于需要对加入的数据进行智能提示)
9
- * @description 如果设置了formatter,则可以通过设置泛型R来变化Union.value的类型
10
8
  */
11
- export default class Union<K extends string, VV extends string, T extends {
12
- [key in K]: string;
13
- }, R extends T = T, L extends VV | never = never> {
9
+ export default class Union<Primary extends string, Member extends string, Origin extends {
10
+ [key in Primary]: string;
11
+ }, Data extends unknown, Option extends unknown, Status extends Member | never = never> {
14
12
  #private;
15
13
  private key;
16
- private formatter?;
17
- get value(): Required<IMap<K, L, R>>;
18
- constructor(key: K, formatter?: ((data: T) => R) | undefined);
19
- add<V extends Exclude<VV, L>>(data: Revise<T, K, V>): Union<K, VV, T, R, L | V>;
14
+ private formatter;
15
+ get data(): Required<Record<Status, Data>>;
16
+ get options(): Required<Record<Status, Option>>;
17
+ constructor(key: Primary, formatter: (data: Origin) => Result<Data, Option>);
18
+ add<V extends Exclude<Member, Status>>(data: Revise<Origin, Primary, V>): Union<Primary, Member, Origin, Data, Option, Status | V> & Omit<this, keyof Union<Primary, Member, Origin, Data, Option, Status | V>>;
20
19
  }
21
20
  export {};