@cclr/lang 0.1.3 → 0.1.4
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 +37 -9
- package/package.json +3 -2
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const e=Function.prototype.call.bind(Object.prototype.hasOwnProperty),t=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 n(e){return r[typeof e]||r[t(e)]||(e?"object":"null")}function o(e){return null===e}function i(e){return void 0===e}function s(e){return o(e)||i(e)}function c(e){return u(e)&&Object.getPrototypeOf(e)===Object.prototype}function u(e){return"object"===n(e)}function l(e){return Array.isArray(e)}const p=()=>{},b={string:"",number:0,boolean:!1,undefined:void 0,null:null,object:{},array:[],function:p,regexp:/(?:)/},f=(e,t)=>{if(n(e)!==n(t))return!1;if(l(e))return e.length===t.length&&e.every(((e,r)=>f(e,t[r])));if(u(e)){const r=Object.keys(e),n=Object.keys(t);return r.length===n.length&&r.every((r=>f(e[r],t[r])))}return e===t},a=(e,[t,...r])=>(e=e[t],r.length&&e?a(e,r):e);var y=Object.freeze({__proto__:null,extend:(e,t)=>(u(e)&&Object.keys(t).forEach((r=>{e[r]=t[r]})),e),filter:(e,t=s)=>{const r={};return c(e)&&Object.entries(e).forEach((([n,o])=>{t(e[n],n)&&(r[n]=o)})),r},forEach:(e,t)=>{Object.keys(e).forEach((r=>{t(e[r],r)}))},format:(e,t)=>{for(const r of t){const[t,o,i]=r;n(e[t])!==o&&(3!==r.length?e[t]=b[o]:e[t]=i)}return e},pick:(e,t)=>t.reduce(((t,r)=>(r in e&&(t[r]=e[r]),t)),{})});const j=(e,[t,...r],n)=>{if(e=e[t]=r.length?e[t]||{}:n,r.length){if(!c(e)||l(e))throw new Error(`path node ['.${t}'] must be plain object {}!`);j(e,r,n)}};exports.VAL_TYPE=r,exports.defaultValue=b,exports.get=(e,t,r)=>{const n=a(e||{},t.split("."));return i(n)||o(n)?r:n},exports.getParamType=n,exports.hasOwn=e,exports.isArray=l,exports.isBoolean=function(e){return"boolean"===n(e)},exports.isEmpty=e=>!!s(e)||(u(e)?Object.keys(e).length<=0:!String(e)),exports.isEqual=f,exports.isFunction=function(e){return"function"===n(e)},exports.isNull=o,exports.isNumber=e=>"number"===n(e)&&isFinite(e),exports.isObject=u,exports.isPlainObject=c,exports.isString=function(e){return"string"===n(e)},exports.isSymbol=function(e){return"symbol"===n(e)},exports.isType=function(e,t){return n(e)===t},exports.isUndefined=i,exports.isUndefinedOrNull=s,exports.noop=p,exports.obj=y,exports.set=(e,t,r)=>(j(e=e||{},t.split("."),r),e),exports.toString=t;
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=Function.prototype.call.bind(Object.prototype.hasOwnProperty),
|
|
1
|
+
const t=Function.prototype.call.bind(Object.prototype.hasOwnProperty),e=Function.prototype.call.bind(Object.prototype.toString),n={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 n[typeof t]||n[e(t)]||(t?"object":"null")}function o(t,e){return r(t)===e}function c(t){return"string"===r(t)}const u=t=>"number"===r(t)&&isFinite(t);function i(t){return"boolean"===r(t)}function b(t){return"symbol"===r(t)}function l(t){return null===t}function f(t){return void 0===t}function s(t){return l(t)||f(t)}function a(t){return"function"===r(t)}function j(t){return y(t)&&Object.getPrototypeOf(t)===Object.prototype}function y(t){return"object"===r(t)}function p(t){return Array.isArray(t)}const g=()=>{},h={string:"",number:0,boolean:!1,undefined:void 0,null:null,object:{},array:[],function:g,regexp:/(?:)/},d=t=>!!s(t)||(y(t)?Object.keys(t).length<=0:!String(t)),O=(t,e)=>{if(r(t)!==r(e))return!1;if(p(t))return t.length===e.length&&t.every(((t,n)=>O(t,e[n])));if(y(t)){const n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every((n=>O(t[n],e[n])))}return t===e},m=(t,[e,...n])=>(t=t[e],n.length&&t?m(t,n):t),E=(t,e,n)=>{const r=m(t||{},e.split("."));return f(r)||l(r)?n:r};var k=Object.freeze({__proto__:null,extend:(t,e)=>(y(t)&&Object.keys(e).forEach((n=>{t[n]=e[n]})),t),filter:(t,e=s)=>{const n={};return j(t)&&Object.entries(t).forEach((([r,o])=>{e(t[r],r)&&(n[r]=o)})),n},forEach:(t,e)=>{Object.keys(t).forEach((n=>{e(t[n],n)}))},format:(t,e)=>{for(const n of e){const[e,o,c]=n;r(t[e])!==o&&(3!==n.length?t[e]=h[o]:t[e]=c)}return t},pick:(t,e)=>e.reduce(((e,n)=>(n in t&&(e[n]=t[n]),e)),{})});const v=(t,[e,...n],r)=>{if(t=t[e]=n.length?t[e]||{}:r,n.length){if(!j(t)||p(t))throw new Error(`path node ['.${e}'] must be plain object {}!`);v(t,n,r)}},x=(t,e,n)=>(v(t=t||{},e.split("."),n),t);export{n as VAL_TYPE,h as defaultValue,E as get,r as getParamType,t as hasOwn,p as isArray,i as isBoolean,d as isEmpty,O as isEqual,a as isFunction,l as isNull,u as isNumber,y as isObject,j as isPlainObject,c as isString,b as isSymbol,o as isType,f as isUndefined,s as isUndefinedOrNull,g as noop,k as obj,x as set,e as toString};
|
package/lib/type/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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";
|
|
@@ -30,6 +30,7 @@ type TVal = (typeof VAL_TYPE)[keyof typeof VAL_TYPE];
|
|
|
30
30
|
declare function getParamType(p: unknown): TVal;
|
|
31
31
|
declare function isType(params: unknown, type: TVal): boolean;
|
|
32
32
|
declare function isString(s: unknown): s is string;
|
|
33
|
+
declare const isNumber: (s: unknown) => s is number;
|
|
33
34
|
declare function isBoolean(b: unknown): b is boolean;
|
|
34
35
|
declare function isSymbol(b: unknown): b is symbol;
|
|
35
36
|
declare function isNull(v: unknown): v is null;
|
|
@@ -45,10 +46,10 @@ declare function isFunction(b: unknown): b is TPlainFunction;
|
|
|
45
46
|
*/
|
|
46
47
|
declare function isPlainObject(b: unknown): b is Record<string, unknown>;
|
|
47
48
|
declare function isObject(b: unknown): b is Record<string, unknown>;
|
|
48
|
-
declare function isArray(a: unknown): a is TAny[];
|
|
49
|
+
declare function isArray(a: unknown): a is TAny$1[];
|
|
49
50
|
|
|
50
51
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
-
type TAny
|
|
52
|
+
type TAny = any;
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
55
|
* () => {};
|
|
@@ -65,7 +66,34 @@ declare const noop: () => void;
|
|
|
65
66
|
* function: noop,
|
|
66
67
|
* regexp: /(?:)/,
|
|
67
68
|
*/
|
|
68
|
-
declare const defaultValue: Partial<Record<TVal, TAny
|
|
69
|
+
declare const defaultValue: Partial<Record<TVal, TAny>>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 校验一个值是否为空
|
|
73
|
+
* @example
|
|
74
|
+
* [] => true
|
|
75
|
+
* {} => true
|
|
76
|
+
* '' => true
|
|
77
|
+
* null => true
|
|
78
|
+
* undefined => true
|
|
79
|
+
* 0 => false
|
|
80
|
+
* @param v
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
declare const isEmpty: (v: unknown) => boolean;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 校验两个值是否相等,深度比较
|
|
87
|
+
* @example
|
|
88
|
+
* isEqual(1, 1) => true
|
|
89
|
+
* isEqual('1', '1') => true
|
|
90
|
+
* isEqual([1, 2], [1, 2]) => true
|
|
91
|
+
* isEqual({ a: 1 }, { a: 1 }) => true
|
|
92
|
+
* @param sourceValue
|
|
93
|
+
* @param targetValue
|
|
94
|
+
* @returns boolean
|
|
95
|
+
*/
|
|
96
|
+
declare const isEqual: (sourceValue: TAny$1, targetValue: TAny$1) => any;
|
|
69
97
|
|
|
70
98
|
/**
|
|
71
99
|
* Check if an object has a property.
|
|
@@ -98,7 +126,7 @@ declare const extend: <T extends object, J extends object>(sourceObj: T & Partia
|
|
|
98
126
|
* @param filter
|
|
99
127
|
* @returns
|
|
100
128
|
*/
|
|
101
|
-
declare const filter: <T extends object, K extends keyof T>(sourceObj: T, filter?: (val: TAny, key: K) => boolean) => Partial<T>;
|
|
129
|
+
declare const filter: <T extends object, K extends keyof T>(sourceObj: T, filter?: (val: TAny$1, key: K) => boolean) => Partial<T>;
|
|
102
130
|
|
|
103
131
|
/**
|
|
104
132
|
* 遍历对象
|
|
@@ -114,7 +142,7 @@ declare const forEach: <T extends object, K extends keyof T>(obj: T, callback: (
|
|
|
114
142
|
* @param formatOptionList [ key, 类型, 默认值? ]
|
|
115
143
|
* @returns 格式化之后的原对象
|
|
116
144
|
*/
|
|
117
|
-
declare const format: <T extends object, K extends keyof T>(object: T, formatOptionList: ([K, TVal, TAny] | [K, TVal])[]) => T;
|
|
145
|
+
declare const format: <T extends object, K extends keyof T>(object: T, formatOptionList: ([K, TVal, TAny$1] | [K, TVal])[]) => T;
|
|
118
146
|
|
|
119
147
|
/**
|
|
120
148
|
* 对象挑选
|
|
@@ -141,4 +169,4 @@ declare namespace index {
|
|
|
141
169
|
*/
|
|
142
170
|
declare const set: (source: object | null | undefined, path: string, value: any) => object;
|
|
143
171
|
|
|
144
|
-
export { type 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 };
|
|
172
|
+
export { type TAny$1 as TAny, type TPlainFunction, type TPlainObject, type TVal, VAL_TYPE, defaultValue, get, getParamType, hasOwn, isArray, isBoolean, isEmpty, isEqual, isFunction, isNull, isNumber, isObject, isPlainObject, isString, isSymbol, isType, isUndefined, isUndefinedOrNull, noop, index as obj, set, toString };
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cclr/lang",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "js语言基础工具",
|
|
5
5
|
"author": "cclr <18843152354@163.com>",
|
|
6
6
|
"homepage": "",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"main": "lib/cjs/index.js",
|
|
9
10
|
"module": "lib/esm/index.js",
|
|
10
11
|
"types": "lib/type/index.d.ts",
|
|
@@ -27,5 +28,5 @@
|
|
|
27
28
|
"g:test": "vitest run",
|
|
28
29
|
"g:build": "ccf build"
|
|
29
30
|
},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "060e2cfbf8d6f933f431d54b528332f08af20b60"
|
|
31
32
|
}
|