@cclr/lang 0.1.1 → 0.1.2
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 +56 -23
- package/package.json +6 -3
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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:"
|
|
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:"number",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 n(t)||c(t)}function s(t){return u(t)&&Object.getPrototypeOf(t)===Object.prototype}function u(t){return"object"===o(t)}function l(t){return Array.isArray(t)}const p=()=>{},b={string:"",number:0,boolean:!1,undefined:void 0,null:null,object:{},array:[],function:p,regexp:/(?:)/},f=(t,[e,...r])=>(t=t[e],r.length&&t?f(t,r):t);var a=Object.freeze({__proto__:null,extend:(t,e)=>(u(t)&&Object.keys(e).forEach((r=>{t[r]=e[r]})),t),filter:(t,e=i)=>{const r={};return s(t)&&Object.entries(t).forEach((([o,n])=>{e(t[o],o)&&(r[o]=n)})),r},forEach:(t,e)=>{Object.keys(t).forEach((r=>{e(t[r],r)}))},format:(t,e)=>{for(const r of e){const[e,n,c]=r;o(t[e])!==n&&(3!==r.length?t[e]=b[n]:t[e]=c)}return t},pick:(t,e)=>e.reduce(((e,r)=>(r in t&&(e[r]=t[r]),e)),{})});const j=(t,[e,...r],o)=>{if(t=t[e]=r.length?t[e]||{}:o,r.length){if(!s(t)||l(t))throw new Error(`path node ['.${e}'] must be plain object {}!`);j(t,r,o)}};exports.VAL_TYPE=r,exports.defaultValue=b,exports.get=(t,e,r)=>{const o=f(t||{},e.split("."));return c(o)||n(o)?r:o},exports.getParamType=o,exports.hasOwn=t,exports.isArray=l,exports.isBoolean=function(t){return"boolean"===o(t)},exports.isFunction=function(t){return"function"===o(t)},exports.isNull=n,exports.isObject=u,exports.isPlainObject=s,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=i,exports.noop=p,exports.obj=a,exports.set=(t,e,r)=>(j(t=t||{},e.split("."),r),t),exports.toString=e;
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=Function.prototype.call.bind(Object.prototype.hasOwnProperty),n=Function.prototype.call.bind(Object.prototype.toString),e={boolean:"boolean",undefined:"undefined",number:"
|
|
1
|
+
const t=Function.prototype.call.bind(Object.prototype.hasOwnProperty),n=Function.prototype.call.bind(Object.prototype.toString),e={boolean:"boolean",undefined:"undefined",number:"number",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 l(t){return void 0===t}function f(t){return b(t)||l(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=()=>{},d={string:"",number:0,boolean:!1,undefined:void 0,null:null,object:{},array:[],function:y,regexp:/(?:)/},g=(t,[n,...e])=>(t=t[n],e.length&&t?g(t,e):t),h=(t,n,e)=>{const r=g(t||{},n.split("."));return l(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]})),t),filter:(t,n=f)=>{const e={};return j(t)&&Object.entries(t).forEach((([r,o])=>{n(t[r],r)&&(e[r]=o)})),e},forEach:(t,n)=>{Object.keys(t).forEach((e=>{n(t[e],e)}))},format:(t,n)=>{for(const e of n){const[n,o,c]=e;r(t[n])!==o&&(3!==e.length?t[n]=d[o]:t[n]=c)}return t},pick:(t,n)=>n.reduce(((n,e)=>(e in t&&(n[e]=t[e]),n)),{})});const m=(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 {}!`);m(t,e,r)}},E=(t,n,e)=>(m(t=t||{},n.split("."),e),t);export{e as VAL_TYPE,d as defaultValue,h 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,l as isUndefined,f as isUndefinedOrNull,y as noop,O as obj,E as set,n as toString};
|
package/lib/type/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
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;
|
|
2
|
+
type TAny$1 = any;
|
|
3
|
+
type TPlainObject = Record<string, TAny$1>;
|
|
4
|
+
type TPlainFunction = (...args: TAny$1[]) => TAny$1;
|
|
5
5
|
|
|
6
6
|
declare const VAL_TYPE: {
|
|
7
7
|
readonly boolean: "boolean";
|
|
8
8
|
readonly undefined: "undefined";
|
|
9
|
-
readonly number: "
|
|
9
|
+
readonly number: "number";
|
|
10
10
|
readonly string: "string";
|
|
11
11
|
readonly symbol: "symbol";
|
|
12
12
|
readonly null: "null";
|
|
@@ -45,7 +45,27 @@ declare function isFunction(b: unknown): b is TPlainFunction;
|
|
|
45
45
|
*/
|
|
46
46
|
declare function isPlainObject(b: unknown): b is Record<string, unknown>;
|
|
47
47
|
declare function isObject(b: unknown): b is Record<string, unknown>;
|
|
48
|
-
declare function isArray(a: unknown): a is TAny[];
|
|
48
|
+
declare function isArray(a: unknown): a is TAny$1[];
|
|
49
|
+
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
type TAny = any;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* () => {};
|
|
55
|
+
*/
|
|
56
|
+
declare const noop: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* string: '',
|
|
59
|
+
* number: 0,
|
|
60
|
+
* boolean: false,
|
|
61
|
+
* undefined: undefined,
|
|
62
|
+
* null: null,
|
|
63
|
+
* object: {},
|
|
64
|
+
* array: [],
|
|
65
|
+
* function: noop,
|
|
66
|
+
* regexp: /(?:)/,
|
|
67
|
+
*/
|
|
68
|
+
declare const defaultValue: Partial<Record<TVal, TAny>>;
|
|
49
69
|
|
|
50
70
|
/**
|
|
51
71
|
* Check if an object has a property.
|
|
@@ -65,19 +85,37 @@ declare const toString: any;
|
|
|
65
85
|
*/
|
|
66
86
|
declare const get: <T>(source: T, path: string, defaultValue?: any) => any;
|
|
67
87
|
|
|
88
|
+
/**
|
|
89
|
+
* 拓展对象
|
|
90
|
+
* @param sourceObj
|
|
91
|
+
* @param injectObj
|
|
92
|
+
*/
|
|
93
|
+
declare const extend: <T extends object, J extends object>(sourceObj: T & Partial<J>, injectObj: J) => T & Partial<J>;
|
|
94
|
+
|
|
68
95
|
/**
|
|
69
96
|
* 过滤属性
|
|
70
97
|
* @param sourceObj
|
|
71
98
|
* @param filter
|
|
72
99
|
* @returns
|
|
73
100
|
*/
|
|
74
|
-
declare const filter: (sourceObj:
|
|
101
|
+
declare const filter: <T extends object, K extends keyof T>(sourceObj: T, filter?: (val: TAny$1, key: K) => boolean) => Partial<T>;
|
|
102
|
+
|
|
75
103
|
/**
|
|
76
|
-
*
|
|
77
|
-
* @param
|
|
78
|
-
* @param
|
|
104
|
+
* 遍历对象
|
|
105
|
+
* @param obj
|
|
106
|
+
* @param callback
|
|
107
|
+
*/
|
|
108
|
+
declare const forEach: <T extends object, K extends keyof T>(obj: T, callback: (val: T[K], key: K) => void) => void;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 格式化对象 (原对象修改)
|
|
112
|
+
* formatOptionList 不存在,但是原始对象中存在的属性,会保留,且不做处理
|
|
113
|
+
* @param object 原始对象
|
|
114
|
+
* @param formatOptionList [ key, 类型, 默认值? ]
|
|
115
|
+
* @returns 格式化之后的原对象
|
|
79
116
|
*/
|
|
80
|
-
declare const
|
|
117
|
+
declare const format: <T extends object, K extends keyof T>(object: T, formatOptionList: ([K, TVal, TAny$1] | [K, TVal])[]) => T;
|
|
118
|
+
|
|
81
119
|
/**
|
|
82
120
|
* 对象挑选
|
|
83
121
|
* @param obj
|
|
@@ -85,19 +123,14 @@ declare const extend: (sourceObj: any, injectObj: any) => void;
|
|
|
85
123
|
* @returns
|
|
86
124
|
*/
|
|
87
125
|
declare const pick: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>;
|
|
88
|
-
/**
|
|
89
|
-
* 遍历对象
|
|
90
|
-
* @param obj
|
|
91
|
-
* @param callback
|
|
92
|
-
*/
|
|
93
|
-
declare const forEach: <T extends object, K extends keyof T>(obj: T, callback: (val: T[K], key: K) => void) => void;
|
|
94
126
|
|
|
95
|
-
declare const
|
|
96
|
-
declare const
|
|
97
|
-
declare const
|
|
98
|
-
declare const
|
|
99
|
-
declare
|
|
100
|
-
|
|
127
|
+
declare const index_extend: typeof extend;
|
|
128
|
+
declare const index_filter: typeof filter;
|
|
129
|
+
declare const index_forEach: typeof forEach;
|
|
130
|
+
declare const index_format: typeof format;
|
|
131
|
+
declare const index_pick: typeof pick;
|
|
132
|
+
declare namespace index {
|
|
133
|
+
export { index_extend as extend, index_filter as filter, index_forEach as forEach, index_format as format, index_pick as pick };
|
|
101
134
|
}
|
|
102
135
|
|
|
103
136
|
/**
|
|
@@ -108,4 +141,4 @@ declare namespace obj {
|
|
|
108
141
|
*/
|
|
109
142
|
declare const set: (source: object | null | undefined, path: string, value: any) => object;
|
|
110
143
|
|
|
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 };
|
|
144
|
+
export { type TAny$1 as TAny, type TPlainFunction, type TPlainObject, type TVal, VAL_TYPE, defaultValue, get, getParamType, hasOwn, isArray, isBoolean, isFunction, isNull, isObject, isPlainObject, isString, isSymbol, isType, isUndefined, isUndefinedOrNull, noop, index as obj, set, toString };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cclr/lang",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "js语言基础工具",
|
|
5
5
|
"author": "cclr <18843152354@163.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -22,7 +22,10 @@
|
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"test": "vitest",
|
|
25
|
-
"relese": "npm run test && npm publish"
|
|
25
|
+
"relese": "npm run test && npm publish",
|
|
26
|
+
"build": "ccf build",
|
|
27
|
+
"g:test": "vitest run",
|
|
28
|
+
"g:build": "ccf build"
|
|
26
29
|
},
|
|
27
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "361f93f5ddccff3c90ee52b0698e289dd7c699a2"
|
|
28
31
|
}
|