@cclr/lang 0.0.10 → 0.1.0
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 -1
- package/lib/esm/index.js +1 -1
- package/lib/type/index.d.ts +40 -32
- package/package.json +5 -3
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
"use strict";const t=Function.prototype.call.bind(Object.prototype.hasOwnProperty),e=Function.prototype.call.bind(Object.prototype.toString),r={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 o(t){return r[typeof t]||r[e(t)]||(t?"object":"null")}function n(t){return null===t}function c(t){return void 0===t}function i(t){return s(t)&&Object.getPrototypeOf(t)===Object.prototype}function s(t){return"object"===o(t)}function u(t){return Array.isArray(t)}const p=(t,[e,...r])=>(t=t[e],r.length&&t?p(t,r):t);var b=Object.freeze({__proto__:null,extend:(t,e)=>{s(t)&&Object.keys(e).forEach((r=>{t[r]=e[r]}))},filter:(t,e)=>{const r={};return i(t)&&Object.keys(t).forEach((o=>{const n=t[o];e(t[o],o)&&(r[o]=n)})),r},forEach:(t,e)=>{Object.keys(t).forEach((r=>{e(t[r],r)}))},pick:(t,e)=>e.reduce(((e,r)=>(r in t&&(e[r]=t[r]),e)),{})});const l=(t,[e,...r],o)=>{if(t=t[e]=r.length?t[e]||{}:o,r.length){if(!i(t)||u(t))throw new Error(`path node ['.${e}'] must be plain object {}!`);l(t,r,o)}};exports.VAL_TYPE=r,exports.get=(t,e,r)=>{const o=p(t||{},e.split("."));return c(o)||n(o)?r:o},exports.getParamType=o,exports.hasOwn=t,exports.isArray=u,exports.isBoolean=function(t){return"boolean"===o(t)},exports.isFunction=function(t){return"function"===o(t)},exports.isNull=n,exports.isObject=s,exports.isPlainObject=i,exports.isString=function(t){return"string"===o(t)},exports.isSymbol=function(t){return"symbol"===o(t)},exports.isType=function(t,e){return o(t)===e},exports.isUndefined=c,exports.isUndefinedOrNull=function(t){return n(t)||c(t)},exports.obj=b,exports.set=(t,e,r)=>(l(t=t||{},e.split("."),r),t),exports.toString=e;
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
1
|
+
const t=Function.prototype.call.bind(Object.prototype.hasOwnProperty),n=Function.prototype.call.bind(Object.prototype.toString),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 r(t){return e[typeof t]||e[n(t)]||(t?"object":"null")}function o(t,n){return r(t)===n}function c(t){return"string"===r(t)}function u(t){return"boolean"===r(t)}function i(t){return"symbol"===r(t)}function b(t){return null===t}function f(t){return void 0===t}function l(t){return b(t)||f(t)}function a(t){return"function"===r(t)}function j(t){return p(t)&&Object.getPrototypeOf(t)===Object.prototype}function p(t){return"object"===r(t)}function s(t){return Array.isArray(t)}const y=(t,[n,...e])=>(t=t[n],e.length&&t?y(t,e):t),d=(t,n,e)=>{const r=y(t||{},n.split("."));return f(r)||b(r)?e:r};var O=Object.freeze({__proto__:null,extend:(t,n)=>{p(t)&&Object.keys(n).forEach((e=>{t[e]=n[e]}))},filter:(t,n)=>{const e={};return j(t)&&Object.keys(t).forEach((r=>{const o=t[r];n(t[r],r)&&(e[r]=o)})),e},forEach:(t,n)=>{Object.keys(t).forEach((e=>{n(t[e],e)}))},pick:(t,n)=>n.reduce(((n,e)=>(e in t&&(n[e]=t[e]),n)),{})});const g=(t,[n,...e],r)=>{if(t=t[n]=e.length?t[n]||{}:r,e.length){if(!j(t)||s(t))throw new Error(`path node ['.${n}'] must be plain object {}!`);g(t,e,r)}},h=(t,n,e)=>(g(t=t||{},n.split("."),e),t);export{e as VAL_TYPE,d as get,r as getParamType,t as hasOwn,s as isArray,u as isBoolean,a as isFunction,b as isNull,p as isObject,j as isPlainObject,c as isString,i as isSymbol,o as isType,f as isUndefined,l as isUndefinedOrNull,O as obj,h as set,n as toString};
|
package/lib/type/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
type TAny = any;
|
|
3
|
+
type TPlainObject = Record<string, TAny>;
|
|
4
|
+
type TPlainFunction = (...args: TAny[]) => TAny;
|
|
5
|
+
|
|
1
6
|
declare const VAL_TYPE: {
|
|
2
7
|
readonly boolean: "boolean";
|
|
3
8
|
readonly undefined: "undefined";
|
|
@@ -5,15 +10,15 @@ declare const VAL_TYPE: {
|
|
|
5
10
|
readonly string: "string";
|
|
6
11
|
readonly symbol: "symbol";
|
|
7
12
|
readonly null: "null";
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
10
|
-
readonly
|
|
11
|
-
readonly
|
|
12
|
-
readonly
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
16
|
-
readonly
|
|
13
|
+
readonly '[object Object]': "object";
|
|
14
|
+
readonly '[object Function]': "function";
|
|
15
|
+
readonly '[object RegExp]': "regexp";
|
|
16
|
+
readonly '[object Array]': "array";
|
|
17
|
+
readonly '[object Date]': "date";
|
|
18
|
+
readonly '[object Error]': "error";
|
|
19
|
+
readonly '[object Blob]': "blob";
|
|
20
|
+
readonly '[object File]': "file";
|
|
21
|
+
readonly '[object ArrayBuffer]': "arrayBuffer";
|
|
17
22
|
};
|
|
18
23
|
type TVal = (typeof VAL_TYPE)[keyof typeof VAL_TYPE];
|
|
19
24
|
|
|
@@ -30,15 +35,27 @@ declare function isSymbol(b: unknown): b is symbol;
|
|
|
30
35
|
declare function isNull(v: unknown): v is null;
|
|
31
36
|
declare function isUndefined(v: unknown): v is undefined;
|
|
32
37
|
declare function isUndefinedOrNull(v: unknown): v is undefined | null;
|
|
33
|
-
declare function isFunction(b: unknown): b is
|
|
38
|
+
declare function isFunction(b: unknown): b is TPlainFunction;
|
|
39
|
+
/**
|
|
40
|
+
* check if the value is a plain object
|
|
41
|
+
* create by Object
|
|
42
|
+
* different from Object.create(null) or new Class()
|
|
43
|
+
* @param b
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
34
46
|
declare function isPlainObject(b: unknown): b is Record<string, unknown>;
|
|
35
47
|
declare function isObject(b: unknown): b is Record<string, unknown>;
|
|
36
|
-
declare function isArray(a: unknown): a is
|
|
48
|
+
declare function isArray(a: unknown): a is TAny[];
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Check if an object has a property.
|
|
52
|
+
*/
|
|
53
|
+
declare const hasOwn: any;
|
|
40
54
|
|
|
41
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Convert a value to a string.
|
|
57
|
+
*/
|
|
58
|
+
declare const toString: any;
|
|
42
59
|
|
|
43
60
|
/**
|
|
44
61
|
* Gets the value at path of object. TODO: typings.
|
|
@@ -48,23 +65,6 @@ declare const enumToArray: (e: TPlainObject) => string[][];
|
|
|
48
65
|
*/
|
|
49
66
|
declare const get: <T>(source: T, path: string, defaultValue?: any) => any;
|
|
50
67
|
|
|
51
|
-
/**
|
|
52
|
-
* Sets the value at path of object. If a portion of path doesn't exist, it's created.
|
|
53
|
-
* @param source The object to modify.
|
|
54
|
-
* @param path The path of the property to set.
|
|
55
|
-
* @param value The value to set.
|
|
56
|
-
*/
|
|
57
|
-
declare const set: (source: object | null | undefined, path: string, value: any) => object;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* A function that returns a universally unique identifier (uuid).
|
|
61
|
-
* Note: If used in long period data storage it is best to add a time stamp (e.g. logging)
|
|
62
|
-
* @example
|
|
63
|
-
* 1b83fd69-abe7-468c-bea1-306a8aa1c81d
|
|
64
|
-
* @returns `string` : 32 character uuid (see example)
|
|
65
|
-
*/
|
|
66
|
-
declare const uuid: () => string;
|
|
67
|
-
|
|
68
68
|
/**
|
|
69
69
|
* 过滤属性
|
|
70
70
|
* @param sourceObj
|
|
@@ -100,4 +100,12 @@ declare namespace obj {
|
|
|
100
100
|
export { obj_extend as extend, obj_filter as filter, obj_forEach as forEach, obj_pick as pick };
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Sets the value at path of object. If a portion of path doesn't exist, it's created.
|
|
105
|
+
* @param source The object to modify.
|
|
106
|
+
* @param path The path of the property to set.
|
|
107
|
+
* @param value The value to set.
|
|
108
|
+
*/
|
|
109
|
+
declare const set: (source: object | null | undefined, path: string, value: any) => object;
|
|
110
|
+
|
|
111
|
+
export { type TAny, type TPlainFunction, type TPlainObject, type TVal, VAL_TYPE, get, getParamType, hasOwn, isArray, isBoolean, isFunction, isNull, isObject, isPlainObject, isString, isSymbol, isType, isUndefined, isUndefinedOrNull, obj, set, toString };
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cclr/lang",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "js语言基础工具",
|
|
5
5
|
"author": "cclr <18843152354@163.com>",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"homepage": "",
|
|
7
8
|
"license": "MIT",
|
|
8
9
|
"main": "lib/cjs/index.js",
|
|
@@ -21,7 +22,8 @@
|
|
|
21
22
|
"registry": "https://registry.npmjs.org/"
|
|
22
23
|
},
|
|
23
24
|
"scripts": {
|
|
24
|
-
"test": "
|
|
25
|
+
"test": "vitest",
|
|
26
|
+
"relese": "npm run test && npm publish"
|
|
25
27
|
},
|
|
26
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "e2f8a819dfe7c5953186303d603fb8f6395d4042"
|
|
27
29
|
}
|