@cclr/lang 0.1.0 → 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 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:"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;
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:"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};
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,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: "undefined";
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: any, filter: any) => {};
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 sourceObj
78
- * @param injectObj
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 extend: (sourceObj: any, injectObj: any) => void;
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 obj_extend: typeof extend;
96
- declare const obj_filter: typeof filter;
97
- declare const obj_forEach: typeof forEach;
98
- declare const obj_pick: typeof pick;
99
- declare namespace obj {
100
- export { obj_extend as extend, obj_filter as filter, obj_forEach as forEach, obj_pick as pick };
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,9 +1,8 @@
1
1
  {
2
2
  "name": "@cclr/lang",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "js语言基础工具",
5
5
  "author": "cclr <18843152354@163.com>",
6
- "type": "module",
7
6
  "homepage": "",
8
7
  "license": "MIT",
9
8
  "main": "lib/cjs/index.js",
@@ -23,7 +22,10 @@
23
22
  },
24
23
  "scripts": {
25
24
  "test": "vitest",
26
- "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"
27
29
  },
28
- "gitHead": "e2f8a819dfe7c5953186303d603fb8f6395d4042"
30
+ "gitHead": "361f93f5ddccff3c90ee52b0698e289dd7c699a2"
29
31
  }