@cclr/lang 0.0.9 → 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 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 t(t){return e[typeof t]||e[Object.prototype.toString.call(t)]||(t?"object":"null")}function r(e){return null===e}function o(e){return void 0===e}function n(e){return"object"==typeof e&&null!==e&&"[object Object]"===Object.prototype.toString.call(e)}function c(e){return"object"===t(e)}function i(e){return Array.isArray(e)}const s=(e,[t,...r])=>(e=e[t],r.length&&e?s(e,r):e),u=(e,[t,...r],o)=>{if(e=e[t]=r.length?e[t]||{}:o,r.length){if(!n(e)||i(e))throw new Error(`path node ['.${t}'] must be plain object {}!`);u(e,r,o)}};var l=Object.freeze({__proto__:null,extend:(e,t)=>{c(e)&&Object.keys(t).forEach((r=>{e[r]=t[r]}))},filter:(e,t)=>{const r={};return n(e)&&Object.keys(e).forEach((o=>{const n=e[o];t(e[o],o)&&(r[o]=n)})),r},forEach:(e,t)=>{Object.keys(e).forEach((r=>{t(e[r],r)}))},pick:(e,t)=>t.reduce(((t,r)=>(r in e&&(t[r]=e[r]),t)),{})});exports.VAL_TYPE=e,exports.enumToArray=e=>n(e)?[Object.keys(e)]:[],exports.get=(e,t,n)=>{const c=s(e||{},t.split("."));return o(c)||r(c)?n:c},exports.getParamType=t,exports.isArray=i,exports.isBoolean=function(e){return"boolean"===t(e)},exports.isFunction=function(e){return"function"===t(e)},exports.isNull=r,exports.isObject=c,exports.isPlainObject=n,exports.isString=function(e){return"string"===t(e)},exports.isSymbol=function(e){return"symbol"===t(e)},exports.isType=function(e,r){return t(e)===r},exports.isUndefined=o,exports.isUndefinedOrNull=function(e){return r(e)||o(e)},exports.obj=l,exports.set=(e,t,r)=>(u(e=e||{},t.split("."),r),e),exports.uuid=()=>{const e=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],t=[];for(let r=0;r<36;r++)t[r]=8===r||13===r||18===r||23===r?"-":e[Math.ceil(Math.random()*e.length-1)];return t.join("")};
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 e(e){return t[typeof e]||t[Object.prototype.toString.call(e)]||(e?"object":"null")}function n(t,n){return e(t)===n}function r(t){return"string"===e(t)}function o(t){return"boolean"===e(t)}function c(t){return"symbol"===e(t)}function u(t){return null===t}function i(t){return void 0===t}function b(t){return u(t)||i(t)}function l(t){return"function"===e(t)}function f(t){return"object"==typeof t&&null!==t&&"[object Object]"===Object.prototype.toString.call(t)}function a(t){return"object"===e(t)}function j(t){return Array.isArray(t)}const s=t=>f(t)?[Object.keys(t)]:[],y=(t,[e,...n])=>(t=t[e],n.length&&t?y(t,n):t),p=(t,e,n)=>{const r=y(t||{},e.split("."));return i(r)||u(r)?n:r},d=(t,[e,...n],r)=>{if(t=t[e]=n.length?t[e]||{}:r,n.length){if(!f(t)||j(t))throw new Error(`path node ['.${e}'] must be plain object {}!`);d(t,n,r)}},h=(t,e,n)=>(d(t=t||{},e.split("."),n),t),g=()=>{const t=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],e=[];for(let n=0;n<36;n++)e[n]=8===n||13===n||18===n||23===n?"-":t[Math.ceil(Math.random()*t.length-1)];return e.join("")};var O=Object.freeze({__proto__:null,extend:(t,e)=>{a(t)&&Object.keys(e).forEach((n=>{t[n]=e[n]}))},filter:(t,e)=>{const n={};return f(t)&&Object.keys(t).forEach((r=>{const o=t[r];e(t[r],r)&&(n[r]=o)})),n},forEach:(t,e)=>{Object.keys(t).forEach((n=>{e(t[n],n)}))},pick:(t,e)=>e.reduce(((e,n)=>(n in t&&(e[n]=t[n]),e)),{})});export{t as VAL_TYPE,s as enumToArray,p as get,e as getParamType,j as isArray,o as isBoolean,l as isFunction,u as isNull,a as isObject,f as isPlainObject,r as isString,c as isSymbol,n as isType,i as isUndefined,b as isUndefinedOrNull,O as obj,h as set,g as uuid};
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,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 "[object Object]": "object";
9
- readonly "[object Function]": "function";
10
- readonly "[object RegExp]": "regexp";
11
- readonly "[object Array]": "array";
12
- readonly "[object Date]": "date";
13
- readonly "[object Error]": "error";
14
- readonly "[object Blob]": "blob";
15
- readonly "[object File]": "file";
16
- readonly "[object ArrayBuffer]": "arrayBuffer";
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 Function;
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 any[];
48
+ declare function isArray(a: unknown): a is TAny[];
37
49
 
38
- type TAny = any;
39
- type TPlainObject = Record<string, TAny>;
50
+ /**
51
+ * Check if an object has a property.
52
+ */
53
+ declare const hasOwn: any;
40
54
 
41
- declare const enumToArray: (e: TPlainObject) => string[][];
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.
@@ -49,23 +66,17 @@ declare const enumToArray: (e: TPlainObject) => string[][];
49
66
  declare const get: <T>(source: T, path: string, defaultValue?: any) => any;
50
67
 
51
68
  /**
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.
69
+ * 过滤属性
70
+ * @param sourceObj
71
+ * @param filter
72
+ * @returns
56
73
  */
57
- declare const set: (source: object | null | undefined, path: string, value: any) => object;
58
-
74
+ declare const filter: (sourceObj: any, filter: any) => {};
59
75
  /**
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)
76
+ * 拓展对象
77
+ * @param sourceObj
78
+ * @param injectObj
65
79
  */
66
- declare const uuid: () => string;
67
-
68
- declare const filter: (sourceObj: any, filter: any) => {};
69
80
  declare const extend: (sourceObj: any, injectObj: any) => void;
70
81
  /**
71
82
  * 对象挑选
@@ -89,4 +100,12 @@ declare namespace obj {
89
100
  export { obj_extend as extend, obj_filter as filter, obj_forEach as forEach, obj_pick as pick };
90
101
  }
91
102
 
92
- export { type TAny, type TPlainObject, type TVal, VAL_TYPE, enumToArray, get, getParamType, isArray, isBoolean, isFunction, isNull, isObject, isPlainObject, isString, isSymbol, isType, isUndefined, isUndefinedOrNull, obj, set, uuid };
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.9",
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": "node ./__tests__/lang.test.js"
25
+ "test": "vitest",
26
+ "relese": "npm run test && npm publish"
25
27
  },
26
- "gitHead": "ad2e0a50411f99a529d84eb5901748d9c3cf5f3a"
28
+ "gitHead": "e2f8a819dfe7c5953186303d603fb8f6395d4042"
27
29
  }