import{checkArg as t}from"./checkArg.js";import{parallelEach as e}from"./promise.js";export function isPlainObject(t){return"object"==typeof t&&!Array.isArray(t)&&null!=t&&Object.getPrototypeOf(t)===Object.prototype}export function map(e,r){t("obj",e).isNotMissing(),t("callback",r).isNotMissing();const o={};for(const t of Object.keys(e))o[t]=r(e[t],t,e);return o}export function filter(e,r){t("obj",e).isNotMissing(),t("callback",r).isNotMissing();const o={},n=Object.keys(e);for(const t of n)r(e[t],t,e)&&(o[t]=e[t]);return o}export const objectKeys=Object.keys;export const objectEntries=Object.entries;export function deepAssign(t,...e){return function(t,...e){if(null==t)throw new TypeError("Cannot convert undefined or null to object.");const r=Object(t);return e.forEach((t=>{if(!t)return;const e=Object(t);if("function"!=typeof r.assignProperties)for(const t of Object.keys(e))r[t]&&"object"==typeof r[t]?deepAssign(r[t],e[t]):n(r,t)&&(r[t]=e[t]);else r.assignProperties(e)})),r}(t,...e)}export function isEmpty(t){return!Object.keys(t).length}export function toJSON(t){return JSON.parse(JSON.stringify(t,((t,e)=>e&&"string"==typeof e.declaredClass&&e.declaredClass.includes("Collection")&&"function"==typeof e.toArray?e.toArray():void 0===e?null:e)))}export function deepClone(t){return JSON.parse(JSON.stringify(t))}export function getPropertyDescriptor(t,e){if(null==t)throw new TypeError("Cannot convert undefined or null to object");let r=t;for(;r;){const t=Object.getOwnPropertyDescriptor(r,e);if(t)return t;r=Object.getPrototypeOf(r)}}export function deepSearchAndTransform(t,e,o,n=!0){return r(t,e,o,n)}export async function deepSearchAndTransformAsync(t,e,r,n=!0){return o(t,e,r,n)}function r(t,e,o,n=!0,s=new Set){let c=!1;if(s.has(e))return c;s.add(e);for(const i of objectKeys(e)){("string"==typeof t?i===t:t.test(i.toString()))&&(e[i]=o(e[i]),c=!0,n)||e[i]&&"object"==typeof e[i]&&(c=r(t,e[i],o,n,s)||c)}return c}async function o(t,r,n,s=!0,c=new Set){let i=!1;if(c.has(r))return i;c.add(r);const f=Object.keys(r);return await e(f,(async e=>{("string"==typeof t?e===t:t.test(e.toString()))&&(r[e]=await n(r[e]),i=!0,s)||r[e]&&"object"==typeof r[e]&&(i=await o(t,r[e],n,s,c)||i)})),i}function n(t,e){const r=getPropertyDescriptor(t,e);return!r||(r.writable??!1)&&!(r.get&&!r.set)}