@cclr/lang 0.0.8 → 0.0.10
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/lib/cjs/index.js +1 -194
- package/lib/esm/index.js +1 -176
- package/lib/type/index.d.ts +24 -11
- package/package.json +2 -2
package/lib/cjs/index.js
CHANGED
|
@@ -1,194 +1 @@
|
|
|
1
|
-
|
|
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;
|
|
1
|
+
"use strict";const e={boolean:"boolean",undefined:"undefined",number:"undefined",string:"string",symbol:"symbol",null:"null","[object Object]":"object","[object Function]":"function","[object RegExp]":"regexp","[object Array]":"array","[object Date]":"date","[object Error]":"error","[object Blob]":"blob","[object File]":"file","[object ArrayBuffer]":"arrayBuffer"};function t(t){return e[typeof t]||e[Object.prototype.toString.call(t)]||(t?"object":"null")}function r(e){return null===e}function o(e){return void 0===e}function n(e){return"object"==typeof e&&null!==e&&"[object Object]"===Object.prototype.toString.call(e)}function c(e){return"object"===t(e)}function i(e){return Array.isArray(e)}const s=(e,[t,...r])=>(e=e[t],r.length&&e?s(e,r):e),u=(e,[t,...r],o)=>{if(e=e[t]=r.length?e[t]||{}:o,r.length){if(!n(e)||i(e))throw new Error(`path node ['.${t}'] must be plain object {}!`);u(e,r,o)}};var l=Object.freeze({__proto__:null,extend:(e,t)=>{c(e)&&Object.keys(t).forEach((r=>{e[r]=t[r]}))},filter:(e,t)=>{const r={};return n(e)&&Object.keys(e).forEach((o=>{const n=e[o];t(e[o],o)&&(r[o]=n)})),r},forEach:(e,t)=>{Object.keys(e).forEach((r=>{t(e[r],r)}))},pick:(e,t)=>t.reduce(((t,r)=>(r in e&&(t[r]=e[r]),t)),{})});exports.VAL_TYPE=e,exports.enumToArray=e=>n(e)?[Object.keys(e)]:[],exports.get=(e,t,n)=>{const c=s(e||{},t.split("."));return o(c)||r(c)?n:c},exports.getParamType=t,exports.isArray=i,exports.isBoolean=function(e){return"boolean"===t(e)},exports.isFunction=function(e){return"function"===t(e)},exports.isNull=r,exports.isObject=c,exports.isPlainObject=n,exports.isString=function(e){return"string"===t(e)},exports.isSymbol=function(e){return"symbol"===t(e)},exports.isType=function(e,r){return t(e)===r},exports.isUndefined=o,exports.isUndefinedOrNull=function(e){return r(e)||o(e)},exports.obj=l,exports.set=(e,t,r)=>(u(e=e||{},t.split("."),r),e),exports.uuid=()=>{const e=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],t=[];for(let r=0;r<36;r++)t[r]=8===r||13===r||18===r||23===r?"-":e[Math.ceil(Math.random()*e.length-1)];return t.join("")};
|
package/lib/esm/index.js
CHANGED
|
@@ -1,176 +1 @@
|
|
|
1
|
-
const
|
|
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 };
|
|
1
|
+
const t={boolean:"boolean",undefined:"undefined",number:"undefined",string:"string",symbol:"symbol",null:"null","[object Object]":"object","[object Function]":"function","[object RegExp]":"regexp","[object Array]":"array","[object Date]":"date","[object Error]":"error","[object Blob]":"blob","[object File]":"file","[object ArrayBuffer]":"arrayBuffer"};function e(e){return t[typeof e]||t[Object.prototype.toString.call(e)]||(e?"object":"null")}function n(t,n){return e(t)===n}function r(t){return"string"===e(t)}function o(t){return"boolean"===e(t)}function c(t){return"symbol"===e(t)}function u(t){return null===t}function i(t){return void 0===t}function b(t){return u(t)||i(t)}function l(t){return"function"===e(t)}function f(t){return"object"==typeof t&&null!==t&&"[object Object]"===Object.prototype.toString.call(t)}function a(t){return"object"===e(t)}function j(t){return Array.isArray(t)}const s=t=>f(t)?[Object.keys(t)]:[],y=(t,[e,...n])=>(t=t[e],n.length&&t?y(t,n):t),p=(t,e,n)=>{const r=y(t||{},e.split("."));return i(r)||u(r)?n:r},d=(t,[e,...n],r)=>{if(t=t[e]=n.length?t[e]||{}:r,n.length){if(!f(t)||j(t))throw new Error(`path node ['.${e}'] must be plain object {}!`);d(t,n,r)}},h=(t,e,n)=>(d(t=t||{},e.split("."),n),t),g=()=>{const t=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],e=[];for(let n=0;n<36;n++)e[n]=8===n||13===n||18===n||23===n?"-":t[Math.ceil(Math.random()*t.length-1)];return e.join("")};var O=Object.freeze({__proto__:null,extend:(t,e)=>{a(t)&&Object.keys(e).forEach((n=>{t[n]=e[n]}))},filter:(t,e)=>{const n={};return f(t)&&Object.keys(t).forEach((r=>{const o=t[r];e(t[r],r)&&(n[r]=o)})),n},forEach:(t,e)=>{Object.keys(t).forEach((n=>{e(t[n],n)}))},pick:(t,e)=>e.reduce(((e,n)=>(n in t&&(e[n]=t[n]),e)),{})});export{t as VAL_TYPE,s as enumToArray,p as get,e as getParamType,j as isArray,o as isBoolean,l as isFunction,u as isNull,a as isObject,f as isPlainObject,r as isString,c as isSymbol,n as isType,i as isUndefined,b as isUndefinedOrNull,O as obj,h as set,g as uuid};
|
package/lib/type/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ declare const VAL_TYPE: {
|
|
|
3
3
|
readonly undefined: "undefined";
|
|
4
4
|
readonly number: "undefined";
|
|
5
5
|
readonly string: "string";
|
|
6
|
+
readonly symbol: "symbol";
|
|
6
7
|
readonly null: "null";
|
|
7
8
|
readonly "[object Object]": "object";
|
|
8
9
|
readonly "[object Function]": "function";
|
|
@@ -22,16 +23,17 @@ type TVal = (typeof VAL_TYPE)[keyof typeof VAL_TYPE];
|
|
|
22
23
|
* @returns
|
|
23
24
|
*/
|
|
24
25
|
declare function getParamType(p: unknown): TVal;
|
|
25
|
-
declare function isType(params:
|
|
26
|
-
declare function isString(s:
|
|
27
|
-
declare function isBoolean(b:
|
|
28
|
-
declare function
|
|
29
|
-
declare function
|
|
30
|
-
declare function
|
|
31
|
-
declare function
|
|
32
|
-
declare function
|
|
33
|
-
declare function
|
|
34
|
-
declare function
|
|
26
|
+
declare function isType(params: unknown, type: TVal): boolean;
|
|
27
|
+
declare function isString(s: unknown): s is string;
|
|
28
|
+
declare function isBoolean(b: unknown): b is boolean;
|
|
29
|
+
declare function isSymbol(b: unknown): b is symbol;
|
|
30
|
+
declare function isNull(v: unknown): v is null;
|
|
31
|
+
declare function isUndefined(v: unknown): v is undefined;
|
|
32
|
+
declare function isUndefinedOrNull(v: unknown): v is undefined | null;
|
|
33
|
+
declare function isFunction(b: unknown): b is Function;
|
|
34
|
+
declare function isPlainObject(b: unknown): b is Record<string, unknown>;
|
|
35
|
+
declare function isObject(b: unknown): b is Record<string, unknown>;
|
|
36
|
+
declare function isArray(a: unknown): a is any[];
|
|
35
37
|
|
|
36
38
|
type TAny = any;
|
|
37
39
|
type TPlainObject = Record<string, TAny>;
|
|
@@ -63,7 +65,18 @@ declare const set: (source: object | null | undefined, path: string, value: any)
|
|
|
63
65
|
*/
|
|
64
66
|
declare const uuid: () => string;
|
|
65
67
|
|
|
68
|
+
/**
|
|
69
|
+
* 过滤属性
|
|
70
|
+
* @param sourceObj
|
|
71
|
+
* @param filter
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
66
74
|
declare const filter: (sourceObj: any, filter: any) => {};
|
|
75
|
+
/**
|
|
76
|
+
* 拓展对象
|
|
77
|
+
* @param sourceObj
|
|
78
|
+
* @param injectObj
|
|
79
|
+
*/
|
|
67
80
|
declare const extend: (sourceObj: any, injectObj: any) => void;
|
|
68
81
|
/**
|
|
69
82
|
* 对象挑选
|
|
@@ -87,4 +100,4 @@ declare namespace obj {
|
|
|
87
100
|
export { obj_extend as extend, obj_filter as filter, obj_forEach as forEach, obj_pick as pick };
|
|
88
101
|
}
|
|
89
102
|
|
|
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 };
|
|
103
|
+
export { type TAny, type TPlainObject, type TVal, VAL_TYPE, enumToArray, get, getParamType, isArray, isBoolean, isFunction, isNull, isObject, isPlainObject, isString, isSymbol, isType, isUndefined, isUndefinedOrNull, obj, set, uuid };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cclr/lang",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "js语言基础工具",
|
|
5
5
|
"author": "cclr <18843152354@163.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"test": "node ./__tests__/lang.test.js"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "d58e3b15266c99cfe0938671a0de64bcc19e0b3f"
|
|
27
27
|
}
|