@stacksjs/objects 0.75.422 → 0.75.423

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/dist/index.d.ts CHANGED
@@ -51,6 +51,17 @@ export declare function objectEntries<T extends object>(obj: T): boolean;
51
51
  /**
52
52
  * Deep merge :P
53
53
  *
54
+ * A `"__proto__"` key in a source is skipped. `JSON.parse`, and the router's
55
+ * request input, keep one as an ordinary own key, and following it walked into
56
+ * `Object.prototype`: `deepMerge({}, JSON.parse('{"__proto__":{"isAdmin":true}}'))`
57
+ * made `isAdmin` true on every object in the process. Only the target's own
58
+ * properties are merged into, so an inherited one is never followed either.
59
+ *
60
+ * Only plain objects are merged key by key. A Date, Map, Set or class instance
61
+ * in a source is a value and is assigned; it used to be merged into a fresh
62
+ * `{}` and arrive empty. A string, array or number in the target gives way to
63
+ * a source's object; one that was truthy used to stay.
64
+ *
54
65
  * @category Object
55
66
  */
56
67
  export declare function deepMerge<T extends object = object, S extends object = T>(target: T, ...sources: S[]): DeepMerge<T, S>;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{notNullish as O}from"@stacksjs/utils";import{isObject as p}from"@stacksjs/validation";function k(e,n){let t=new Set(n),r={};for(let[o,s]of Object.entries(e))if(!t.has(o))r[o]=s;return r}function a(e,n){let t={};for(let[r,o]of Object.entries(e))if(n(o,r))t[r]=o;return t}function l(e,n){return a(e,(t,r)=>!n(t,r))}function x(e,n){let t={};for(let[r,o]of Object.entries(e))t[r]=n(o,r);return t}function b(e,n){let t={};for(let[r,o]of Object.entries(e))t[n(r,o)]=o;return t}function j(e){let n={};for(let[t,r]of Object.entries(e))n[String(r)]=t;return n}function K(e){for(let n in e)if(Object.hasOwn(e,n))return!1;return!0}function T(e,n,t){let r=e;for(let o of n){if(r===null||r===void 0)return t;r=r[o]}return r===void 0?t:r}function y(e,n,t){if(n.length===0)return t;let[r,...o]=n,s=Array.isArray(e)?[...e]:{...e};if(o.length===0)return s[r]=t,s;let i=s[r],u=i===null||typeof i!=="object"?typeof o[0]==="number"?[]:{}:i;return s[r]=y(u,o,t),s}function m(e,n){return Object.fromEntries(Object.entries(e).map(([t,r])=>n(t,r)).filter(O))}function w(e,n){return n in e}function d(e){return Object.keys(e)}function R(e){return Object.entries(e)}function f(e,...n){if(!n.length)return e;let[t,...r]=n;if(t===void 0)return e;if(c(e)&&c(t))d(t).forEach((o)=>{if(c(t[o])){if(!e[o])e[o]={};f(e[o],t[o])}else e[o]=t[o]});return f(e,...r)}function c(e){return p(e)&&!Array.isArray(e)}function S(e,n,t=!1){return n.reduce((r,o)=>{if(o in e){if(!t||e[o]!==void 0)r[o]=e[o]}return r},{})}function V(e){return Object.keys(e).forEach((n)=>e[n]===void 0&&delete e[n]),e}function v(e,n){return e==null?!1:Object.prototype.hasOwnProperty.call(e,n)}export{V as clearUndefined,f as deepMerge,T as getPath,v as hasOwnProperty,j as invert,K as isEmptyObject,w as isKeyOf,b as mapKeys,x as mapValues,R as objectEntries,d as objectKeys,m as objectMap,S as objectPick,k as omit,l as omitBy,a as pickBy,y as setPath};
2
+ import{notNullish as p}from"@stacksjs/utils";import{isObject as d}from"@stacksjs/validation";function k(e,t){let n=new Set(t);return Object.fromEntries(Object.entries(e).filter(([r])=>!n.has(r)))}function O(e,t){return Object.fromEntries(Object.entries(e).filter(([n,r])=>t(r,n)))}function l(e,t){return O(e,(n,r)=>!t(n,r))}function j(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>[n,t(r,n)]))}function x(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>[t(n,r),r]))}function K(e){return Object.fromEntries(Object.entries(e).map(([t,n])=>[String(n),t]))}function P(e){for(let t in e)if(Object.hasOwn(e,t))return!1;return!0}function g(e,t,n){let r=e;for(let o of t){if(r===null||r===void 0)return n;r=r[o]}return r===void 0?n:r}function y(e,t,n){if(t.length===0)return n;let[r,...o]=t,i=Array.isArray(e)?[...e]:{...e};if(o.length===0)return f(i,r,n),i;let s=Object.hasOwn(i,r)?i[r]:void 0,a=s===null||typeof s!=="object"?typeof o[0]==="number"?[]:{}:s;return f(i,r,y(a,o,n)),i}function f(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function h(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>t(n,r)).filter(p))}function R(e,t){return t in e}function S(e){return Object.keys(e)}function V(e){return Object.entries(e)}function u(e,...t){if(!t.length)return e;let[n,...r]=t;if(n===void 0)return e;if(c(e)&&c(n)){let o=e,i=n;for(let s of Object.keys(i)){if(s==="__proto__")continue;if(b(i[s])){if(!Object.hasOwn(o,s)||!c(o[s]))o[s]={};u(o[s],i[s])}else o[s]=i[s]}}return u(e,...r)}function c(e){return d(e)&&!Array.isArray(e)}function b(e){if(typeof e!=="object"||e===null)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype||Object.getPrototypeOf(t)===null}function E(e,t,n=!1){return t.reduce((r,o)=>{if(o in e){if(!n||e[o]!==void 0)r[o]=e[o]}return r},{})}function N(e){return Object.keys(e).forEach((t)=>e[t]===void 0&&delete e[t]),e}function A(e,t){return e==null?!1:Object.prototype.hasOwnProperty.call(e,t)}export{N as clearUndefined,u as deepMerge,g as getPath,A as hasOwnProperty,K as invert,P as isEmptyObject,R as isKeyOf,x as mapKeys,j as mapValues,V as objectEntries,S as objectKeys,h as objectMap,E as objectPick,k as omit,l as omitBy,O as pickBy,y as setPath};
@@ -11,6 +11,12 @@
11
11
  * otherwise. Only an object's own enumerable string keys are visited -
12
12
  * inherited and symbol keys are left alone, which matches `Object.entries` and
13
13
  * is what stops a plain-object helper from wandering into a prototype.
14
+ *
15
+ * Results are built with `Object.fromEntries`, and `setPath` defines its key,
16
+ * because an assignment runs the `__proto__` setter. `JSON.parse` and the
17
+ * router's request input keep a `"__proto__"` key as an ordinary own key, so
18
+ * `omit(body, ['password'])` on `{"__proto__":{"isAdmin":true}}` used to come
19
+ * back with `isAdmin` true, inherited from a prototype the client chose.
14
20
  */
15
21
  /**
16
22
  * A copy without the given keys.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/objects",
3
3
  "type": "module",
4
- "version": "0.75.422",
4
+ "version": "0.75.423",
5
5
  "description": "The Stacks objects.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -56,12 +56,12 @@
56
56
  "prepublishOnly": "bun run build"
57
57
  },
58
58
  "dependencies": {
59
- "@stacksjs/utils": "0.75.422",
60
- "@stacksjs/validation": "0.75.422"
59
+ "@stacksjs/utils": "0.75.423",
60
+ "@stacksjs/validation": "0.75.423"
61
61
  },
62
62
  "devDependencies": {
63
- "@stacksjs/collections": "0.75.422",
64
- "@stacksjs/types": "0.75.422",
63
+ "@stacksjs/collections": "0.75.423",
64
+ "@stacksjs/types": "0.75.423",
65
65
  "better-dx": "^0.2.24"
66
66
  },
67
67
  "sideEffects": false