@cclr/lang 0.1.2 → 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 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:"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;
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),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};
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};
@@ -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;
@@ -67,6 +68,33 @@ declare const noop: () => void;
67
68
  */
68
69
  declare const defaultValue: Partial<Record<TVal, TAny>>;
69
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;
97
+
70
98
  /**
71
99
  * Check if an object has a property.
72
100
  */
@@ -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$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 };
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.2",
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": "361f93f5ddccff3c90ee52b0698e289dd7c699a2"
31
+ "gitHead": "060e2cfbf8d6f933f431d54b528332f08af20b60"
31
32
  }