@cclr/lang 0.0.3 → 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 +194 -0
- package/lib/esm/index.js +176 -0
- package/lib/type/index.d.ts +90 -0
- package/package.json +8 -10
- package/cjs/index.js +0 -56
- package/cjs/src/common-type.d.ts +0 -2
- package/cjs/src/index.d.ts +0 -3
- package/cjs/src/type-asserts.d.ts +0 -14
- package/cjs/src/value-type.d.ts +0 -17
- package/esm/index.js +0 -47
- package/esm/src/common-type.d.ts +0 -2
- package/esm/src/index.d.ts +0 -3
- package/esm/src/type-asserts.d.ts +0 -14
- package/esm/src/value-type.d.ts +0 -17
- package/index.d.ts +0 -1
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
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const VAL_TYPE = {
|
|
4
|
+
boolean: "boolean",
|
|
5
|
+
undefined: "undefined",
|
|
6
|
+
number: "undefined",
|
|
7
|
+
string: "string",
|
|
8
|
+
null: "null",
|
|
9
|
+
"[object Object]": "object",
|
|
10
|
+
"[object Function]": "function",
|
|
11
|
+
"[object RegExp]": "regexp",
|
|
12
|
+
"[object Array]": "array",
|
|
13
|
+
"[object Date]": "date",
|
|
14
|
+
"[object Error]": "error",
|
|
15
|
+
"[object Blob]": "blob",
|
|
16
|
+
"[object File]": "file",
|
|
17
|
+
"[object ArrayBuffer]": "arrayBuffer",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 获取参数类型
|
|
22
|
+
* @param p 参数
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
function getParamType(p) {
|
|
26
|
+
return (VAL_TYPE[typeof p] ||
|
|
27
|
+
VAL_TYPE[Object.prototype.toString.call(p)] ||
|
|
28
|
+
(p ? "object" : "null"));
|
|
29
|
+
}
|
|
30
|
+
function isType(params, type) {
|
|
31
|
+
return getParamType(params) === type;
|
|
32
|
+
}
|
|
33
|
+
function isString(s) {
|
|
34
|
+
return getParamType(s) === "string";
|
|
35
|
+
}
|
|
36
|
+
function isBoolean(b) {
|
|
37
|
+
return getParamType(b) === "boolean";
|
|
38
|
+
}
|
|
39
|
+
function isFunction(b) {
|
|
40
|
+
return getParamType(b) === "function";
|
|
41
|
+
}
|
|
42
|
+
function isPlainObject(b) {
|
|
43
|
+
return Object.prototype.toString.call(b) === "[object Object]";
|
|
44
|
+
}
|
|
45
|
+
function isObject(b) {
|
|
46
|
+
return getParamType(b) === "object";
|
|
47
|
+
}
|
|
48
|
+
function isArray(a) {
|
|
49
|
+
return Array.isArray(a);
|
|
50
|
+
}
|
|
51
|
+
function isNull(v) {
|
|
52
|
+
return v === null;
|
|
53
|
+
}
|
|
54
|
+
function isUndefined(v) {
|
|
55
|
+
return v === undefined;
|
|
56
|
+
}
|
|
57
|
+
function isUndefinedOrNull(v) {
|
|
58
|
+
return isNull(v) || isUndefined(v);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const enumToArray = (e) => {
|
|
62
|
+
if (isPlainObject(e)) {
|
|
63
|
+
return [Object.keys(e)];
|
|
64
|
+
}
|
|
65
|
+
return [];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const loopObjectRead = (source, [head, ...tail]) => {
|
|
69
|
+
source = source[head];
|
|
70
|
+
return tail.length && source ? loopObjectRead(source, tail) : source;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Gets the value at path of object. TODO: typings.
|
|
74
|
+
* @param source The object to query.
|
|
75
|
+
* @param path The path of the property to get.
|
|
76
|
+
* @param [defaultValue] The value returned for undefined resolved values.
|
|
77
|
+
*/
|
|
78
|
+
const get = (source, path, defaultValue) => {
|
|
79
|
+
const result = loopObjectRead(source || {}, path.split("."));
|
|
80
|
+
return isUndefined(result) || isNull(result) ? defaultValue : result;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const loopObjectSet = (source, [head, ...tail], value) => {
|
|
84
|
+
source = source[head] = tail.length ? source[head] || {} : value;
|
|
85
|
+
if (tail.length) {
|
|
86
|
+
if (isPlainObject(source) && !isArray(source)) {
|
|
87
|
+
loopObjectSet(source, tail, value);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
throw new Error(`path node ['.${head}'] must be plain object {}!`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Sets the value at path of object. If a portion of path doesn't exist, it's created.
|
|
96
|
+
* @param source The object to modify.
|
|
97
|
+
* @param path The path of the property to set.
|
|
98
|
+
* @param value The value to set.
|
|
99
|
+
*/
|
|
100
|
+
const set = (source, path, value) => {
|
|
101
|
+
source = source || {};
|
|
102
|
+
loopObjectSet(source, path.split("."), value);
|
|
103
|
+
return source;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A function that returns a universally unique identifier (uuid).
|
|
108
|
+
* Note: If used in long period data storage it is best to add a time stamp (e.g. logging)
|
|
109
|
+
* @example
|
|
110
|
+
* 1b83fd69-abe7-468c-bea1-306a8aa1c81d
|
|
111
|
+
* @returns `string` : 32 character uuid (see example)
|
|
112
|
+
*/
|
|
113
|
+
const uuid = () => {
|
|
114
|
+
const hashTable = ['a', 'b', 'c', 'd', 'e', 'f', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|
115
|
+
const uuid = [];
|
|
116
|
+
for (let i = 0; i < 36; i++) {
|
|
117
|
+
if (i === 8 || i === 13 || i === 18 || i === 23) {
|
|
118
|
+
uuid[i] = '-';
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
uuid[i] = hashTable[Math.ceil(Math.random() * hashTable.length - 1)];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return uuid.join('');
|
|
125
|
+
};
|
|
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
|
+
|
|
178
|
+
exports.VAL_TYPE = VAL_TYPE;
|
|
179
|
+
exports.enumToArray = enumToArray;
|
|
180
|
+
exports.get = get;
|
|
181
|
+
exports.getParamType = getParamType;
|
|
182
|
+
exports.isArray = isArray;
|
|
183
|
+
exports.isBoolean = isBoolean;
|
|
184
|
+
exports.isFunction = isFunction;
|
|
185
|
+
exports.isNull = isNull;
|
|
186
|
+
exports.isObject = isObject;
|
|
187
|
+
exports.isPlainObject = isPlainObject;
|
|
188
|
+
exports.isString = isString;
|
|
189
|
+
exports.isType = isType;
|
|
190
|
+
exports.isUndefined = isUndefined;
|
|
191
|
+
exports.isUndefinedOrNull = isUndefinedOrNull;
|
|
192
|
+
exports.obj = obj;
|
|
193
|
+
exports.set = set;
|
|
194
|
+
exports.uuid = uuid;
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
const VAL_TYPE = {
|
|
2
|
+
boolean: "boolean",
|
|
3
|
+
undefined: "undefined",
|
|
4
|
+
number: "undefined",
|
|
5
|
+
string: "string",
|
|
6
|
+
null: "null",
|
|
7
|
+
"[object Object]": "object",
|
|
8
|
+
"[object Function]": "function",
|
|
9
|
+
"[object RegExp]": "regexp",
|
|
10
|
+
"[object Array]": "array",
|
|
11
|
+
"[object Date]": "date",
|
|
12
|
+
"[object Error]": "error",
|
|
13
|
+
"[object Blob]": "blob",
|
|
14
|
+
"[object File]": "file",
|
|
15
|
+
"[object ArrayBuffer]": "arrayBuffer",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 获取参数类型
|
|
20
|
+
* @param p 参数
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
function getParamType(p) {
|
|
24
|
+
return (VAL_TYPE[typeof p] ||
|
|
25
|
+
VAL_TYPE[Object.prototype.toString.call(p)] ||
|
|
26
|
+
(p ? "object" : "null"));
|
|
27
|
+
}
|
|
28
|
+
function isType(params, type) {
|
|
29
|
+
return getParamType(params) === type;
|
|
30
|
+
}
|
|
31
|
+
function isString(s) {
|
|
32
|
+
return getParamType(s) === "string";
|
|
33
|
+
}
|
|
34
|
+
function isBoolean(b) {
|
|
35
|
+
return getParamType(b) === "boolean";
|
|
36
|
+
}
|
|
37
|
+
function isFunction(b) {
|
|
38
|
+
return getParamType(b) === "function";
|
|
39
|
+
}
|
|
40
|
+
function isPlainObject(b) {
|
|
41
|
+
return Object.prototype.toString.call(b) === "[object Object]";
|
|
42
|
+
}
|
|
43
|
+
function isObject(b) {
|
|
44
|
+
return getParamType(b) === "object";
|
|
45
|
+
}
|
|
46
|
+
function isArray(a) {
|
|
47
|
+
return Array.isArray(a);
|
|
48
|
+
}
|
|
49
|
+
function isNull(v) {
|
|
50
|
+
return v === null;
|
|
51
|
+
}
|
|
52
|
+
function isUndefined(v) {
|
|
53
|
+
return v === undefined;
|
|
54
|
+
}
|
|
55
|
+
function isUndefinedOrNull(v) {
|
|
56
|
+
return isNull(v) || isUndefined(v);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const enumToArray = (e) => {
|
|
60
|
+
if (isPlainObject(e)) {
|
|
61
|
+
return [Object.keys(e)];
|
|
62
|
+
}
|
|
63
|
+
return [];
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const loopObjectRead = (source, [head, ...tail]) => {
|
|
67
|
+
source = source[head];
|
|
68
|
+
return tail.length && source ? loopObjectRead(source, tail) : source;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Gets the value at path of object. TODO: typings.
|
|
72
|
+
* @param source The object to query.
|
|
73
|
+
* @param path The path of the property to get.
|
|
74
|
+
* @param [defaultValue] The value returned for undefined resolved values.
|
|
75
|
+
*/
|
|
76
|
+
const get = (source, path, defaultValue) => {
|
|
77
|
+
const result = loopObjectRead(source || {}, path.split("."));
|
|
78
|
+
return isUndefined(result) || isNull(result) ? defaultValue : result;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const loopObjectSet = (source, [head, ...tail], value) => {
|
|
82
|
+
source = source[head] = tail.length ? source[head] || {} : value;
|
|
83
|
+
if (tail.length) {
|
|
84
|
+
if (isPlainObject(source) && !isArray(source)) {
|
|
85
|
+
loopObjectSet(source, tail, value);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
throw new Error(`path node ['.${head}'] must be plain object {}!`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Sets the value at path of object. If a portion of path doesn't exist, it's created.
|
|
94
|
+
* @param source The object to modify.
|
|
95
|
+
* @param path The path of the property to set.
|
|
96
|
+
* @param value The value to set.
|
|
97
|
+
*/
|
|
98
|
+
const set = (source, path, value) => {
|
|
99
|
+
source = source || {};
|
|
100
|
+
loopObjectSet(source, path.split("."), value);
|
|
101
|
+
return source;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A function that returns a universally unique identifier (uuid).
|
|
106
|
+
* Note: If used in long period data storage it is best to add a time stamp (e.g. logging)
|
|
107
|
+
* @example
|
|
108
|
+
* 1b83fd69-abe7-468c-bea1-306a8aa1c81d
|
|
109
|
+
* @returns `string` : 32 character uuid (see example)
|
|
110
|
+
*/
|
|
111
|
+
const uuid = () => {
|
|
112
|
+
const hashTable = ['a', 'b', 'c', 'd', 'e', 'f', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|
113
|
+
const uuid = [];
|
|
114
|
+
for (let i = 0; i < 36; i++) {
|
|
115
|
+
if (i === 8 || i === 13 || i === 18 || i === 23) {
|
|
116
|
+
uuid[i] = '-';
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
uuid[i] = hashTable[Math.ceil(Math.random() * hashTable.length - 1)];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return uuid.join('');
|
|
123
|
+
};
|
|
124
|
+
|
|
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 };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
declare const VAL_TYPE: {
|
|
2
|
+
readonly boolean: "boolean";
|
|
3
|
+
readonly undefined: "undefined";
|
|
4
|
+
readonly number: "undefined";
|
|
5
|
+
readonly string: "string";
|
|
6
|
+
readonly null: "null";
|
|
7
|
+
readonly "[object Object]": "object";
|
|
8
|
+
readonly "[object Function]": "function";
|
|
9
|
+
readonly "[object RegExp]": "regexp";
|
|
10
|
+
readonly "[object Array]": "array";
|
|
11
|
+
readonly "[object Date]": "date";
|
|
12
|
+
readonly "[object Error]": "error";
|
|
13
|
+
readonly "[object Blob]": "blob";
|
|
14
|
+
readonly "[object File]": "file";
|
|
15
|
+
readonly "[object ArrayBuffer]": "arrayBuffer";
|
|
16
|
+
};
|
|
17
|
+
type TVal = (typeof VAL_TYPE)[keyof typeof VAL_TYPE];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 获取参数类型
|
|
21
|
+
* @param p 参数
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
declare function getParamType(p: unknown): TVal;
|
|
25
|
+
declare function isType(params: any, type: TVal): boolean;
|
|
26
|
+
declare function isString(s: any): s is String;
|
|
27
|
+
declare function isBoolean(b: any): b is Boolean;
|
|
28
|
+
declare function isFunction(b: any): b is Function;
|
|
29
|
+
declare function isPlainObject(b: any): b is Record<string, unknown>;
|
|
30
|
+
declare function isObject(b: any): b is Record<string, unknown>;
|
|
31
|
+
declare function isArray(a: any): a is any[];
|
|
32
|
+
declare function isNull(v: any): v is null;
|
|
33
|
+
declare function isUndefined(v: any): v is undefined;
|
|
34
|
+
declare function isUndefinedOrNull(v: any): v is undefined | null;
|
|
35
|
+
|
|
36
|
+
type TAny = any;
|
|
37
|
+
type TPlainObject = Record<string, TAny>;
|
|
38
|
+
|
|
39
|
+
declare const enumToArray: (e: TPlainObject) => string[][];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Gets the value at path of object. TODO: typings.
|
|
43
|
+
* @param source The object to query.
|
|
44
|
+
* @param path The path of the property to get.
|
|
45
|
+
* @param [defaultValue] The value returned for undefined resolved values.
|
|
46
|
+
*/
|
|
47
|
+
declare const get: <T>(source: T, path: string, defaultValue?: any) => any;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Sets the value at path of object. If a portion of path doesn't exist, it's created.
|
|
51
|
+
* @param source The object to modify.
|
|
52
|
+
* @param path The path of the property to set.
|
|
53
|
+
* @param value The value to set.
|
|
54
|
+
*/
|
|
55
|
+
declare const set: (source: object | null | undefined, path: string, value: any) => object;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A function that returns a universally unique identifier (uuid).
|
|
59
|
+
* Note: If used in long period data storage it is best to add a time stamp (e.g. logging)
|
|
60
|
+
* @example
|
|
61
|
+
* 1b83fd69-abe7-468c-bea1-306a8aa1c81d
|
|
62
|
+
* @returns `string` : 32 character uuid (see example)
|
|
63
|
+
*/
|
|
64
|
+
declare const uuid: () => string;
|
|
65
|
+
|
|
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,21 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cclr/lang",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"description": "js语言基础工具",
|
|
5
5
|
"author": "cclr <18843152354@163.com>",
|
|
6
6
|
"homepage": "",
|
|
7
|
-
"license": "
|
|
8
|
-
"main": "cjs/
|
|
9
|
-
"module": "esm/index.js",
|
|
10
|
-
"types": "
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "lib/cjs/index.js",
|
|
9
|
+
"module": "lib/esm/index.js",
|
|
10
|
+
"types": "lib/type/index.d.ts",
|
|
11
11
|
"directories": {
|
|
12
12
|
"lib": "lib",
|
|
13
13
|
"test": "__tests__"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
|
-
"
|
|
17
|
-
"esm",
|
|
18
|
-
"index.d.ts",
|
|
16
|
+
"lib",
|
|
19
17
|
"README.md"
|
|
20
18
|
],
|
|
21
19
|
"publishConfig": {
|
|
@@ -25,5 +23,5 @@
|
|
|
25
23
|
"scripts": {
|
|
26
24
|
"test": "node ./__tests__/lang.test.js"
|
|
27
25
|
},
|
|
28
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "0777e471605045ae87d1fd5e7ebe4f0e748d5035"
|
|
29
27
|
}
|
package/cjs/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const VAL_TYPE = {
|
|
4
|
-
boolean: "boolean",
|
|
5
|
-
undefined: "undefined",
|
|
6
|
-
number: "undefined",
|
|
7
|
-
string: "string",
|
|
8
|
-
null: "null",
|
|
9
|
-
"[object Object]": "object",
|
|
10
|
-
"[object Function]": "function",
|
|
11
|
-
"[object RegExp]": "regexp",
|
|
12
|
-
"[object Array]": "array",
|
|
13
|
-
"[object Date]": "date",
|
|
14
|
-
"[object Error]": "error",
|
|
15
|
-
"[object Blob]": "blob",
|
|
16
|
-
"[object File]": "file",
|
|
17
|
-
"[object ArrayBuffer]": "arrayBuffer",
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 获取参数类型
|
|
22
|
-
* @param p 参数
|
|
23
|
-
* @returns
|
|
24
|
-
*/
|
|
25
|
-
function getParamType(p) {
|
|
26
|
-
return (VAL_TYPE[typeof p] ||
|
|
27
|
-
VAL_TYPE[Object.prototype.toString.call(p)] ||
|
|
28
|
-
(p ? "object" : "null"));
|
|
29
|
-
}
|
|
30
|
-
function isType(params, type) {
|
|
31
|
-
return getParamType(params) === type;
|
|
32
|
-
}
|
|
33
|
-
function isString(s) {
|
|
34
|
-
return getParamType(s) === "string";
|
|
35
|
-
}
|
|
36
|
-
function isBoolean(b) {
|
|
37
|
-
return getParamType(b) === "boolean";
|
|
38
|
-
}
|
|
39
|
-
function isFunction(b) {
|
|
40
|
-
return getParamType(b) === "function";
|
|
41
|
-
}
|
|
42
|
-
function isPlainObject(b) {
|
|
43
|
-
return getParamType(b) === "object";
|
|
44
|
-
}
|
|
45
|
-
function isArray(a) {
|
|
46
|
-
return Array.isArray(a);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
exports.VAL_TYPE = VAL_TYPE;
|
|
50
|
-
exports.getParamType = getParamType;
|
|
51
|
-
exports.isArray = isArray;
|
|
52
|
-
exports.isBoolean = isBoolean;
|
|
53
|
-
exports.isFunction = isFunction;
|
|
54
|
-
exports.isPlainObject = isPlainObject;
|
|
55
|
-
exports.isString = isString;
|
|
56
|
-
exports.isType = isType;
|
package/cjs/src/common-type.d.ts
DELETED
package/cjs/src/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { TVal } from "./value-type";
|
|
2
|
-
/**
|
|
3
|
-
* 获取参数类型
|
|
4
|
-
* @param p 参数
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
declare function getParamType(p: unknown): TVal;
|
|
8
|
-
declare function isType(params: any, type: TVal): boolean;
|
|
9
|
-
declare function isString(s: any): s is String;
|
|
10
|
-
declare function isBoolean(b: any): b is Boolean;
|
|
11
|
-
declare function isFunction(b: any): b is Function;
|
|
12
|
-
declare function isPlainObject(b: any): b is Record<string, unknown>;
|
|
13
|
-
declare function isArray(a: any): a is any[];
|
|
14
|
-
export { getParamType, isType, isString, isBoolean, isFunction, isArray, isPlainObject, };
|
package/cjs/src/value-type.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const VAL_TYPE: {
|
|
2
|
-
readonly boolean: "boolean";
|
|
3
|
-
readonly undefined: "undefined";
|
|
4
|
-
readonly number: "undefined";
|
|
5
|
-
readonly string: "string";
|
|
6
|
-
readonly null: "null";
|
|
7
|
-
readonly "[object Object]": "object";
|
|
8
|
-
readonly "[object Function]": "function";
|
|
9
|
-
readonly "[object RegExp]": "regexp";
|
|
10
|
-
readonly "[object Array]": "array";
|
|
11
|
-
readonly "[object Date]": "date";
|
|
12
|
-
readonly "[object Error]": "error";
|
|
13
|
-
readonly "[object Blob]": "blob";
|
|
14
|
-
readonly "[object File]": "file";
|
|
15
|
-
readonly "[object ArrayBuffer]": "arrayBuffer";
|
|
16
|
-
};
|
|
17
|
-
export type TVal = typeof VAL_TYPE[keyof typeof VAL_TYPE];
|
package/esm/index.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const VAL_TYPE = {
|
|
2
|
-
boolean: "boolean",
|
|
3
|
-
undefined: "undefined",
|
|
4
|
-
number: "undefined",
|
|
5
|
-
string: "string",
|
|
6
|
-
null: "null",
|
|
7
|
-
"[object Object]": "object",
|
|
8
|
-
"[object Function]": "function",
|
|
9
|
-
"[object RegExp]": "regexp",
|
|
10
|
-
"[object Array]": "array",
|
|
11
|
-
"[object Date]": "date",
|
|
12
|
-
"[object Error]": "error",
|
|
13
|
-
"[object Blob]": "blob",
|
|
14
|
-
"[object File]": "file",
|
|
15
|
-
"[object ArrayBuffer]": "arrayBuffer",
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 获取参数类型
|
|
20
|
-
* @param p 参数
|
|
21
|
-
* @returns
|
|
22
|
-
*/
|
|
23
|
-
function getParamType(p) {
|
|
24
|
-
return (VAL_TYPE[typeof p] ||
|
|
25
|
-
VAL_TYPE[Object.prototype.toString.call(p)] ||
|
|
26
|
-
(p ? "object" : "null"));
|
|
27
|
-
}
|
|
28
|
-
function isType(params, type) {
|
|
29
|
-
return getParamType(params) === type;
|
|
30
|
-
}
|
|
31
|
-
function isString(s) {
|
|
32
|
-
return getParamType(s) === "string";
|
|
33
|
-
}
|
|
34
|
-
function isBoolean(b) {
|
|
35
|
-
return getParamType(b) === "boolean";
|
|
36
|
-
}
|
|
37
|
-
function isFunction(b) {
|
|
38
|
-
return getParamType(b) === "function";
|
|
39
|
-
}
|
|
40
|
-
function isPlainObject(b) {
|
|
41
|
-
return getParamType(b) === "object";
|
|
42
|
-
}
|
|
43
|
-
function isArray(a) {
|
|
44
|
-
return Array.isArray(a);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export { VAL_TYPE, getParamType, isArray, isBoolean, isFunction, isPlainObject, isString, isType };
|
package/esm/src/common-type.d.ts
DELETED
package/esm/src/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { TVal } from "./value-type";
|
|
2
|
-
/**
|
|
3
|
-
* 获取参数类型
|
|
4
|
-
* @param p 参数
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
declare function getParamType(p: unknown): TVal;
|
|
8
|
-
declare function isType(params: any, type: TVal): boolean;
|
|
9
|
-
declare function isString(s: any): s is String;
|
|
10
|
-
declare function isBoolean(b: any): b is Boolean;
|
|
11
|
-
declare function isFunction(b: any): b is Function;
|
|
12
|
-
declare function isPlainObject(b: any): b is Record<string, unknown>;
|
|
13
|
-
declare function isArray(a: any): a is any[];
|
|
14
|
-
export { getParamType, isType, isString, isBoolean, isFunction, isArray, isPlainObject, };
|
package/esm/src/value-type.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const VAL_TYPE: {
|
|
2
|
-
readonly boolean: "boolean";
|
|
3
|
-
readonly undefined: "undefined";
|
|
4
|
-
readonly number: "undefined";
|
|
5
|
-
readonly string: "string";
|
|
6
|
-
readonly null: "null";
|
|
7
|
-
readonly "[object Object]": "object";
|
|
8
|
-
readonly "[object Function]": "function";
|
|
9
|
-
readonly "[object RegExp]": "regexp";
|
|
10
|
-
readonly "[object Array]": "array";
|
|
11
|
-
readonly "[object Date]": "date";
|
|
12
|
-
readonly "[object Error]": "error";
|
|
13
|
-
readonly "[object Blob]": "blob";
|
|
14
|
-
readonly "[object File]": "file";
|
|
15
|
-
readonly "[object ArrayBuffer]": "arrayBuffer";
|
|
16
|
-
};
|
|
17
|
-
export type TVal = typeof VAL_TYPE[keyof typeof VAL_TYPE];
|
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './esm/src';
|