obj-lite 1.0.0 → 1.0.1
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/index.d.ts +4 -4
- package/index.js +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -2,17 +2,17 @@ declare module "obj-lite" {
|
|
|
2
2
|
/**
|
|
3
3
|
* 检查值是否为对象
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
function isObject(value: any): boolean;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* 检查值是否为纯对象 ({})
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
function isPlainObject(value: any): boolean;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* 深度克隆对象
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
function deepClone<T>(obj: T): T;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* 从对象中排除指定的属性路径
|
|
@@ -49,7 +49,7 @@ declare module "obj-lite" {
|
|
|
49
49
|
): T | undefined;
|
|
50
50
|
|
|
51
51
|
// 定义工具函数类型
|
|
52
|
-
const utils: {
|
|
52
|
+
export const utils: {
|
|
53
53
|
deepClone: typeof deepClone;
|
|
54
54
|
isObject: typeof isObject;
|
|
55
55
|
isPlainObject: typeof isPlainObject;
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t){const n=typeof t;return null!=t&&("object"===n||"function"===n)}function n(t,n){const o=typeof t;return!!(n=null==n?Number.MAX_SAFE_INTEGER:n)&&("number"===o||"symbol"!==o&&/^[0-9]+$/.test(t))&&t>-1&&t%1==0&&n>t}function o(t,n){if(Array.isArray(t))return t;const o=[];if("string"==typeof t){let n="";for(let e=0;t.length>e;e++)if("["===t[e]||"."===t[e]){if(""!==n&&(o.push(n),n=""),"["===t[e]){let n=e+1;for(;t.length>n&&"]"!==t[n];)n++;o.push(t.substring(e+1,n)),e=n}}else"]"!==t[e]&&(n+=t[e]);""!==n&&o.push(n)}else o.push(t);return o}function e(n,e){if(!t(n))return;const r=o(e);let f=0,u=r.length;for(;null!=n&&u>f;)n=n[r[f++]];return f&&f===u?n:void 0}function r(e,r,f){if(!t(e))return e;const u=o(r);let c=0;const i=u.length,l=i-1;let s=e;for(;i>c;){const t=u[c];if(c===l)s[t]=f;else{if(null==s[t]||"object"!=typeof s[t]){s[t]=n(u[c+1])?[]:{}}s=s[t]}c++}return e}function f(t){if(null===t||"object"!=typeof t)return t;if(Array.isArray(t))return t.map(t=>f(t));const n={};for(const o in t)Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=f(t[o]));return n}
|
|
1
|
+
function t(t){const n=typeof t;return null!=t&&("object"===n||"function"===n)}function n(t,n){const o=typeof t;return!!(n=null==n?Number.MAX_SAFE_INTEGER:n)&&("number"===o||"symbol"!==o&&/^[0-9]+$/.test(t))&&t>-1&&t%1==0&&n>t}function o(t,n){if(Array.isArray(t))return t;const o=[];if("string"==typeof t){let n="";for(let e=0;t.length>e;e++)if("["===t[e]||"."===t[e]){if(""!==n&&(o.push(n),n=""),"["===t[e]){let n=e+1;for(;t.length>n&&"]"!==t[n];)n++;o.push(t.substring(e+1,n)),e=n}}else"]"!==t[e]&&(n+=t[e]);""!==n&&o.push(n)}else o.push(t);return o}function e(n,e){if(!t(n))return;const r=o(e);let f=0,u=r.length;for(;null!=n&&u>f;)n=n[r[f++]];return f&&f===u?n:void 0}function r(e,r,f){if(!t(e))return e;const u=o(r);let c=0;const i=u.length,l=i-1;let s=e;for(;i>c;){const t=u[c];if(c===l)s[t]=f;else{if(null==s[t]||"object"!=typeof s[t]){s[t]=n(u[c+1])?[]:{}}s=s[t]}c++}return e}function f(t){if(null===t||"object"!=typeof t)return t;if(Array.isArray(t))return t.map(t=>f(t));const n={};for(const o in t)Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=f(t[o]));return n}function u(n,e){if(null==n||"object"!=typeof n)return{};const r=new Set;for(const t of e){const n=o(t);r.add(n.join("."))}return function n(o,e=""){if(!t(o))return o;const f=Array.isArray(o)?[]:{};for(const u in o)if(Object.prototype.hasOwnProperty.call(o,u)){const c=e?`${e}.${u}`:u;if(r.has(c))continue;let i=!1;for(const t of r)if(t.startsWith(c+".")){i=!0;break}i||(f[u]=t(o[u])?n(o[u],c):o[u])}return f}(n)}function c(t,n){if(null==t||"object"!=typeof t)return{};const f={};for(const u of n){o(u);const n=e(t,u);void 0!==n&&r(f,u,n)}return f}function i(t,n,o){return null==t&&(t={}),r(f(t),n,o)}function l(t,n,o){if(null==t)return o;const r=e(t,n);return void 0===r?o:r}const s={deepClone:f,isObject:t,isPlainObject:function(n){return!(!t(n)||!n.constructor||"Object"!==n.constructor.name)}},b={omit:u,pick:c,set:i,get:l,utils:s};export{b as default,l as get,u as omit,c as pick,i as set,s as utils};
|