@whitesev/utils 1.0.0 → 1.0.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/dist/index.esm.js CHANGED
@@ -115,157 +115,6 @@ class ColorConversion {
115
115
  }
116
116
  }
117
117
 
118
- class UtilsDictionary {
119
- items = {};
120
- /**
121
- * 检查是否有某一个键
122
- * @param key 键
123
- */
124
- has(key) {
125
- return this.items.hasOwnProperty(key);
126
- }
127
- /**
128
- * 检查已有的键中是否以xx开头
129
- * @param key 需要匹配的键
130
- */
131
- startsWith(key) {
132
- let allKeys = this.keys();
133
- for (const keyName of allKeys) {
134
- if (keyName.startsWith(key)) {
135
- return true;
136
- }
137
- }
138
- return false;
139
- }
140
- /**
141
- * 获取以xx开头的键的值
142
- * @param key 需要匹配的键
143
- */
144
- getStartsWith(key) {
145
- let allKeys = this.keys();
146
- for (const keyName of allKeys) {
147
- if (keyName.startsWith(key)) {
148
- return this.getItems()[keyName];
149
- }
150
- }
151
- }
152
- /**
153
- * 为字典添加某一个值
154
- * @param key 键
155
- * @param val 值,默认为""
156
- */
157
- set(key, val) {
158
- if (key === void 0) {
159
- throw new Error("Utils.Dictionary().set 参数 key 不能为空");
160
- }
161
- this.items[key] = val;
162
- }
163
- /**
164
- * 删除某一个键
165
- * @param key 键
166
- */
167
- delete(key) {
168
- if (this.has(key)) {
169
- Reflect.deleteProperty(this.items, key);
170
- return true;
171
- }
172
- return false;
173
- }
174
- /**
175
- * 获取某个键的值
176
- * @param key 键
177
- */
178
- get(key) {
179
- return this.getItems()[key];
180
- }
181
- /**
182
- * 返回字典中的所有值
183
- */
184
- values() {
185
- let resultList = [];
186
- for (let prop in this.items) {
187
- if (this.has(prop)) {
188
- resultList.push(this.items[prop]);
189
- }
190
- }
191
- return resultList;
192
- }
193
- /**
194
- * 清空字典
195
- */
196
- clear() {
197
- this.items = void 0;
198
- this.items = {};
199
- }
200
- /**
201
- * 获取字典的长度
202
- */
203
- size() {
204
- return Object.keys(this.items).length;
205
- }
206
- /**
207
- * 获取字典所有的键
208
- */
209
- keys() {
210
- return Object.keys(this.items);
211
- }
212
- /**
213
- * 返回字典本身
214
- * @returns
215
- */
216
- getItems() {
217
- return this.items;
218
- }
219
- /**
220
- * 合并另一个字典
221
- * @param data 需要合并的字典
222
- */
223
- concat(data) {
224
- this.items = utils.assign(this.items, data.getItems());
225
- }
226
- /**
227
- * 循环字典
228
- */
229
- forEach(callbackfn) {
230
- for (const key in this.getItems()) {
231
- callbackfn(this.get(key), key, this.getItems());
232
- }
233
- }
234
- /**
235
- * 获取字典的长度,同this.size
236
- */
237
- get length() {
238
- return this.size();
239
- }
240
- /**
241
- * 迭代器
242
- */
243
- get entries() {
244
- let that = this;
245
- return function* () {
246
- let itemKeys = Object.keys(that.getItems());
247
- for (const keyName of itemKeys) {
248
- yield [keyName, that.get(keyName)];
249
- }
250
- };
251
- }
252
- /**
253
- * 是否可遍历
254
- */
255
- get [Symbol.iterator]() {
256
- let that = this;
257
- return function () {
258
- return that.entries();
259
- };
260
- }
261
- /**
262
- * .toString()和.toLocaleString()输出的字符串
263
- */
264
- get [Symbol.toStringTag]() {
265
- return "UtilsDictionary";
266
- }
267
- }
268
-
269
118
  class GBKEncoder {
270
119
  #data = [];
271
120
  #U2Ghash = {};
@@ -3188,6 +3037,162 @@ const TryCatch = function (...args) {
3188
3037
  return tryCatchObj;
3189
3038
  };
3190
3039
 
3040
+ class UtilsDictionary {
3041
+ items = {};
3042
+ /**
3043
+ * 检查是否有某一个键
3044
+ * @param {string} key 键
3045
+ * @returns {boolean}
3046
+ */
3047
+ has(key) {
3048
+ return this.items.hasOwnProperty(key);
3049
+ }
3050
+ /**
3051
+ * 检查已有的键中是否以xx开头
3052
+ * @param {string} key 需要匹配的键
3053
+ * @returns {boolean}
3054
+ */
3055
+ startsWith(key) {
3056
+ let allKeys = this.keys();
3057
+ for (const keyName of allKeys) {
3058
+ if (keyName.startsWith(key)) {
3059
+ return true;
3060
+ }
3061
+ }
3062
+ return false;
3063
+ }
3064
+ /**
3065
+ * 获取以xx开头的键的值
3066
+ * @param {string} key 需要匹配的键
3067
+ * @returns {any}
3068
+ */
3069
+ getStartsWith(key) {
3070
+ let allKeys = this.keys();
3071
+ for (const keyName of allKeys) {
3072
+ if (keyName.startsWith(key)) {
3073
+ return this.items[keyName];
3074
+ }
3075
+ }
3076
+ }
3077
+ /**
3078
+ * 为字典添加某一个值
3079
+ * @param {string} key 键
3080
+ * @param {any} val 值,默认为""
3081
+ */
3082
+ set(key, val = "") {
3083
+ if (key === void 0) {
3084
+ throw new Error("Utils.Dictionary().set 参数 key 不能为空");
3085
+ }
3086
+ this.items[key] = val;
3087
+ }
3088
+ /**
3089
+ * 删除某一个键
3090
+ * @param {string} key 键
3091
+ * @returns {boolean}
3092
+ */
3093
+ delete(key) {
3094
+ if (this.has(key)) {
3095
+ Reflect.deleteProperty(this.items, key);
3096
+ return true;
3097
+ }
3098
+ return false;
3099
+ }
3100
+ /**
3101
+ * 获取某个键的值
3102
+ * @param {string} key 键
3103
+ * @returns {any}
3104
+ */
3105
+ get(key) {
3106
+ return this.has(key) ? this.items[key] : void 0;
3107
+ }
3108
+ /**
3109
+ * 返回字典中的所有值
3110
+ * @returns {any[]}
3111
+ */
3112
+ values() {
3113
+ let resultList = [];
3114
+ for (let prop in this.items) {
3115
+ if (this.has(prop)) {
3116
+ resultList.push(this.items[prop]);
3117
+ }
3118
+ }
3119
+ return resultList;
3120
+ }
3121
+ /**
3122
+ * 清空字典
3123
+ */
3124
+ clear() {
3125
+ this.items = null;
3126
+ this.items = {};
3127
+ }
3128
+ /**
3129
+ * 获取字典的长度
3130
+ * @returns {number}
3131
+ */
3132
+ size() {
3133
+ return Object.keys(this.items).length;
3134
+ }
3135
+ /**
3136
+ * 获取字典所有的键
3137
+ */
3138
+ keys() {
3139
+ return Object.keys(this.items);
3140
+ }
3141
+ /**
3142
+ * 返回字典本身
3143
+ * @returns {object}
3144
+ */
3145
+ getItems() {
3146
+ return this.items;
3147
+ }
3148
+ /**
3149
+ * 合并另一个字典
3150
+ * @param {object} data 需要合并的字典
3151
+ */
3152
+ concat(data) {
3153
+ this.items = Utils.assign(this.items, data.getItems());
3154
+ }
3155
+ forEach(callbackfn) {
3156
+ for (const key in this.items) {
3157
+ callbackfn(this.get(key), key, this.items);
3158
+ }
3159
+ }
3160
+ /**
3161
+ * 获取字典的长度,同this.size
3162
+ * @returns {number}
3163
+ */
3164
+ get length() {
3165
+ return this.size();
3166
+ }
3167
+ /**
3168
+ * 迭代器
3169
+ */
3170
+ get entries() {
3171
+ let that = this;
3172
+ return function* () {
3173
+ let itemKeys = Object.keys(that.getItems());
3174
+ for (const keyName of itemKeys) {
3175
+ yield [keyName, that.get(keyName)];
3176
+ }
3177
+ };
3178
+ }
3179
+ /**
3180
+ * 是否可遍历
3181
+ */
3182
+ get [Symbol.iterator]() {
3183
+ let that = this;
3184
+ return function () {
3185
+ return that.entries();
3186
+ };
3187
+ }
3188
+ /**
3189
+ * .toString()和.toLocaleString()输出的字符串
3190
+ */
3191
+ get [Symbol.toStringTag]() {
3192
+ return "UtilsDictionary";
3193
+ }
3194
+ }
3195
+
3191
3196
  let Utils$1 = class Utils {
3192
3197
  /** 版本号 */
3193
3198
  version = "2024.5.24";