@cclr/lang 0.0.6 → 0.0.8
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/LICENSE +19 -0
- package/lib/cjs/index.js +52 -1
- package/lib/esm/index.js +52 -2
- package/lib/type/index.d.ts +25 -1
- package/package.json +3 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/lib/cjs/index.js
CHANGED
|
@@ -65,7 +65,6 @@ const enumToArray = (e) => {
|
|
|
65
65
|
return [];
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
69
68
|
const loopObjectRead = (source, [head, ...tail]) => {
|
|
70
69
|
source = source[head];
|
|
71
70
|
return tail.length && source ? loopObjectRead(source, tail) : source;
|
|
@@ -125,6 +124,57 @@ const uuid = () => {
|
|
|
125
124
|
return uuid.join('');
|
|
126
125
|
};
|
|
127
126
|
|
|
127
|
+
const filter = (sourceObj, filter) => {
|
|
128
|
+
const newObj = {};
|
|
129
|
+
isPlainObject(sourceObj) &&
|
|
130
|
+
Object.keys(sourceObj).forEach((key) => {
|
|
131
|
+
const val = sourceObj[key];
|
|
132
|
+
if (filter(sourceObj[key], key)) {
|
|
133
|
+
newObj[key] = val;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return newObj;
|
|
137
|
+
};
|
|
138
|
+
const extend = (sourceObj, injectObj) => {
|
|
139
|
+
if (isObject(sourceObj)) {
|
|
140
|
+
Object.keys(injectObj).forEach((key) => {
|
|
141
|
+
sourceObj[key] = injectObj[key];
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* 对象挑选
|
|
147
|
+
* @param obj
|
|
148
|
+
* @param keys
|
|
149
|
+
* @returns
|
|
150
|
+
*/
|
|
151
|
+
const pick = (obj, keys) => {
|
|
152
|
+
return keys.reduce((pre, key) => {
|
|
153
|
+
if (key in obj) {
|
|
154
|
+
pre[key] = obj[key];
|
|
155
|
+
}
|
|
156
|
+
return pre;
|
|
157
|
+
}, {});
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* 遍历对象
|
|
161
|
+
* @param obj
|
|
162
|
+
* @param callback
|
|
163
|
+
*/
|
|
164
|
+
const forEach = (obj, callback) => {
|
|
165
|
+
Object.keys(obj).forEach((key) => {
|
|
166
|
+
callback(obj[key], key);
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
var obj = /*#__PURE__*/Object.freeze({
|
|
171
|
+
__proto__: null,
|
|
172
|
+
extend: extend,
|
|
173
|
+
filter: filter,
|
|
174
|
+
forEach: forEach,
|
|
175
|
+
pick: pick
|
|
176
|
+
});
|
|
177
|
+
|
|
128
178
|
exports.VAL_TYPE = VAL_TYPE;
|
|
129
179
|
exports.enumToArray = enumToArray;
|
|
130
180
|
exports.get = get;
|
|
@@ -139,5 +189,6 @@ exports.isString = isString;
|
|
|
139
189
|
exports.isType = isType;
|
|
140
190
|
exports.isUndefined = isUndefined;
|
|
141
191
|
exports.isUndefinedOrNull = isUndefinedOrNull;
|
|
192
|
+
exports.obj = obj;
|
|
142
193
|
exports.set = set;
|
|
143
194
|
exports.uuid = uuid;
|
package/lib/esm/index.js
CHANGED
|
@@ -63,7 +63,6 @@ const enumToArray = (e) => {
|
|
|
63
63
|
return [];
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
67
66
|
const loopObjectRead = (source, [head, ...tail]) => {
|
|
68
67
|
source = source[head];
|
|
69
68
|
return tail.length && source ? loopObjectRead(source, tail) : source;
|
|
@@ -123,4 +122,55 @@ const uuid = () => {
|
|
|
123
122
|
return uuid.join('');
|
|
124
123
|
};
|
|
125
124
|
|
|
126
|
-
|
|
125
|
+
const filter = (sourceObj, filter) => {
|
|
126
|
+
const newObj = {};
|
|
127
|
+
isPlainObject(sourceObj) &&
|
|
128
|
+
Object.keys(sourceObj).forEach((key) => {
|
|
129
|
+
const val = sourceObj[key];
|
|
130
|
+
if (filter(sourceObj[key], key)) {
|
|
131
|
+
newObj[key] = val;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
return newObj;
|
|
135
|
+
};
|
|
136
|
+
const extend = (sourceObj, injectObj) => {
|
|
137
|
+
if (isObject(sourceObj)) {
|
|
138
|
+
Object.keys(injectObj).forEach((key) => {
|
|
139
|
+
sourceObj[key] = injectObj[key];
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* 对象挑选
|
|
145
|
+
* @param obj
|
|
146
|
+
* @param keys
|
|
147
|
+
* @returns
|
|
148
|
+
*/
|
|
149
|
+
const pick = (obj, keys) => {
|
|
150
|
+
return keys.reduce((pre, key) => {
|
|
151
|
+
if (key in obj) {
|
|
152
|
+
pre[key] = obj[key];
|
|
153
|
+
}
|
|
154
|
+
return pre;
|
|
155
|
+
}, {});
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* 遍历对象
|
|
159
|
+
* @param obj
|
|
160
|
+
* @param callback
|
|
161
|
+
*/
|
|
162
|
+
const forEach = (obj, callback) => {
|
|
163
|
+
Object.keys(obj).forEach((key) => {
|
|
164
|
+
callback(obj[key], key);
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
var obj = /*#__PURE__*/Object.freeze({
|
|
169
|
+
__proto__: null,
|
|
170
|
+
extend: extend,
|
|
171
|
+
filter: filter,
|
|
172
|
+
forEach: forEach,
|
|
173
|
+
pick: pick
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
export { VAL_TYPE, enumToArray, get, getParamType, isArray, isBoolean, isFunction, isNull, isObject, isPlainObject, isString, isType, isUndefined, isUndefinedOrNull, obj, set, uuid };
|
package/lib/type/index.d.ts
CHANGED
|
@@ -63,4 +63,28 @@ declare const set: (source: object | null | undefined, path: string, value: any)
|
|
|
63
63
|
*/
|
|
64
64
|
declare const uuid: () => string;
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
declare const filter: (sourceObj: any, filter: any) => {};
|
|
67
|
+
declare const extend: (sourceObj: any, injectObj: any) => void;
|
|
68
|
+
/**
|
|
69
|
+
* 对象挑选
|
|
70
|
+
* @param obj
|
|
71
|
+
* @param keys
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
declare const pick: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>;
|
|
75
|
+
/**
|
|
76
|
+
* 遍历对象
|
|
77
|
+
* @param obj
|
|
78
|
+
* @param callback
|
|
79
|
+
*/
|
|
80
|
+
declare const forEach: <T extends object, K extends keyof T>(obj: T, callback: (val: T[K], key: K) => void) => void;
|
|
81
|
+
|
|
82
|
+
declare const obj_extend: typeof extend;
|
|
83
|
+
declare const obj_filter: typeof filter;
|
|
84
|
+
declare const obj_forEach: typeof forEach;
|
|
85
|
+
declare const obj_pick: typeof pick;
|
|
86
|
+
declare namespace obj {
|
|
87
|
+
export { obj_extend as extend, obj_filter as filter, obj_forEach as forEach, obj_pick as pick };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { type TAny, type TPlainObject, type TVal, VAL_TYPE, enumToArray, get, getParamType, isArray, isBoolean, isFunction, isNull, isObject, isPlainObject, isString, isType, isUndefined, isUndefinedOrNull, obj, set, uuid };
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cclr/lang",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "js语言基础工具",
|
|
5
5
|
"author": "cclr <18843152354@163.com>",
|
|
6
6
|
"homepage": "",
|
|
7
|
-
"license": "
|
|
7
|
+
"license": "MIT",
|
|
8
8
|
"main": "lib/cjs/index.js",
|
|
9
9
|
"module": "lib/esm/index.js",
|
|
10
10
|
"types": "lib/type/index.d.ts",
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"test": "node ./__tests__/lang.test.js"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "0777e471605045ae87d1fd5e7ebe4f0e748d5035"
|
|
27
27
|
}
|