@catbee/utils 0.0.8-next.0 → 0.0.8-rc.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/README.md +1 -2
- package/build/esm/config.d.ts +122 -0
- package/build/esm/config.js +133 -0
- package/build/esm/config.js.map +1 -0
- package/build/esm/index.d.ts +27 -0
- package/build/esm/index.js +50 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/servers/server.builder.d.ts +508 -0
- package/build/esm/servers/server.builder.js +702 -0
- package/build/esm/servers/server.builder.js.map +1 -0
- package/build/esm/servers/server.d.ts +256 -0
- package/build/esm/servers/server.js +1248 -0
- package/build/esm/servers/server.js.map +1 -0
- package/build/esm/types/api-response.d.ts +152 -0
- package/build/esm/types/api-response.js +34 -0
- package/build/esm/types/api-response.js.map +1 -0
- package/build/esm/types/index.d.ts +125 -0
- package/build/esm/types/index.js +25 -0
- package/build/esm/types/index.js.map +1 -0
- package/build/esm/types/server.d.ts +268 -0
- package/build/esm/types/server.js +25 -0
- package/build/esm/types/server.js.map +1 -0
- package/build/esm/utils/array.utils.d.ts +168 -0
- package/build/esm/utils/array.utils.js +382 -0
- package/build/esm/utils/array.utils.js.map +1 -0
- package/build/esm/utils/async.utils.d.ts +265 -0
- package/build/esm/utils/async.utils.js +896 -0
- package/build/esm/utils/async.utils.js.map +1 -0
- package/build/esm/utils/cache.utils.d.ts +153 -0
- package/build/esm/utils/cache.utils.js +499 -0
- package/build/esm/utils/cache.utils.js.map +1 -0
- package/build/esm/utils/context-store.utils.d.ts +189 -0
- package/build/esm/utils/context-store.utils.js +307 -0
- package/build/esm/utils/context-store.utils.js.map +1 -0
- package/build/esm/utils/crypto.utils.d.ts +160 -0
- package/build/esm/utils/crypto.utils.js +375 -0
- package/build/esm/utils/crypto.utils.js.map +1 -0
- package/build/esm/utils/date.utils.d.ts +159 -0
- package/build/esm/utils/date.utils.js +389 -0
- package/build/esm/utils/date.utils.js.map +1 -0
- package/build/esm/utils/decorators.utils.d.ts +508 -0
- package/build/esm/utils/decorators.utils.js +1057 -0
- package/build/esm/utils/decorators.utils.js.map +1 -0
- package/build/esm/utils/dir.utils.d.ts +196 -0
- package/build/esm/utils/dir.utils.js +998 -0
- package/build/esm/utils/dir.utils.js.map +1 -0
- package/build/esm/utils/env.utils.d.ts +377 -0
- package/build/esm/utils/env.utils.js +873 -0
- package/build/esm/utils/env.utils.js.map +1 -0
- package/build/esm/utils/exception.utils.d.ts +230 -0
- package/build/esm/utils/exception.utils.js +559 -0
- package/build/esm/utils/exception.utils.js.map +1 -0
- package/build/esm/utils/fs.utils.d.ts +164 -0
- package/build/esm/utils/fs.utils.js +580 -0
- package/build/esm/utils/fs.utils.js.map +1 -0
- package/build/esm/utils/http-status-codes.d.ts +266 -0
- package/build/esm/utils/http-status-codes.js +295 -0
- package/build/esm/utils/http-status-codes.js.map +1 -0
- package/build/esm/utils/id.utils.d.ts +36 -0
- package/build/esm/utils/id.utils.js +87 -0
- package/build/esm/utils/id.utils.js.map +1 -0
- package/build/esm/utils/logger.utils.d.ts +160 -0
- package/build/esm/utils/logger.utils.js +341 -0
- package/build/esm/utils/logger.utils.js.map +1 -0
- package/build/esm/utils/middleware.utils.d.ts +100 -0
- package/build/esm/utils/middleware.utils.js +325 -0
- package/build/esm/utils/middleware.utils.js.map +1 -0
- package/build/esm/utils/obj.utils.d.ts +124 -0
- package/build/esm/utils/obj.utils.js +519 -0
- package/build/esm/utils/obj.utils.js.map +1 -0
- package/build/esm/utils/performance.utils.d.ts +136 -0
- package/build/esm/utils/performance.utils.js +376 -0
- package/build/esm/utils/performance.utils.js.map +1 -0
- package/build/esm/utils/request.utils.d.ts +86 -0
- package/build/esm/utils/request.utils.js +223 -0
- package/build/esm/utils/request.utils.js.map +1 -0
- package/build/esm/utils/response.utils.d.ts +163 -0
- package/build/esm/utils/response.utils.js +284 -0
- package/build/esm/utils/response.utils.js.map +1 -0
- package/build/esm/utils/stream.utils.d.ts +88 -0
- package/build/esm/utils/stream.utils.js +284 -0
- package/build/esm/utils/stream.utils.js.map +1 -0
- package/build/esm/utils/string.utils.d.ts +93 -0
- package/build/esm/utils/string.utils.js +169 -0
- package/build/esm/utils/string.utils.js.map +1 -0
- package/build/esm/utils/type.utils.d.ts +90 -0
- package/build/esm/utils/type.utils.js +190 -0
- package/build/esm/utils/type.utils.js.map +1 -0
- package/build/esm/utils/url.utils.d.ts +141 -0
- package/build/esm/utils/url.utils.js +381 -0
- package/build/esm/utils/url.utils.js.map +1 -0
- package/build/esm/utils/validate.utils.d.ts +177 -0
- package/build/esm/utils/validate.utils.js +336 -0
- package/build/esm/utils/validate.utils.js.map +1 -0
- package/build/esnext/config.d.ts +122 -0
- package/build/esnext/config.js +133 -0
- package/build/esnext/config.js.map +1 -0
- package/build/esnext/index.d.ts +27 -0
- package/build/esnext/index.js +50 -0
- package/build/esnext/index.js.map +1 -0
- package/build/esnext/servers/server.builder.d.ts +508 -0
- package/build/esnext/servers/server.builder.js +657 -0
- package/build/esnext/servers/server.builder.js.map +1 -0
- package/build/esnext/servers/server.d.ts +256 -0
- package/build/esnext/servers/server.js +955 -0
- package/build/esnext/servers/server.js.map +1 -0
- package/build/esnext/types/api-response.d.ts +152 -0
- package/build/esnext/types/api-response.js +34 -0
- package/build/esnext/types/api-response.js.map +1 -0
- package/build/esnext/types/index.d.ts +125 -0
- package/build/esnext/types/index.js +25 -0
- package/build/esnext/types/index.js.map +1 -0
- package/build/esnext/types/server.d.ts +268 -0
- package/build/esnext/types/server.js +25 -0
- package/build/esnext/types/server.js.map +1 -0
- package/build/esnext/utils/array.utils.d.ts +168 -0
- package/build/esnext/utils/array.utils.js +345 -0
- package/build/esnext/utils/array.utils.js.map +1 -0
- package/build/esnext/utils/async.utils.d.ts +265 -0
- package/build/esnext/utils/async.utils.js +620 -0
- package/build/esnext/utils/async.utils.js.map +1 -0
- package/build/esnext/utils/cache.utils.d.ts +153 -0
- package/build/esnext/utils/cache.utils.js +293 -0
- package/build/esnext/utils/cache.utils.js.map +1 -0
- package/build/esnext/utils/context-store.utils.d.ts +189 -0
- package/build/esnext/utils/context-store.utils.js +289 -0
- package/build/esnext/utils/context-store.utils.js.map +1 -0
- package/build/esnext/utils/crypto.utils.d.ts +160 -0
- package/build/esnext/utils/crypto.utils.js +276 -0
- package/build/esnext/utils/crypto.utils.js.map +1 -0
- package/build/esnext/utils/date.utils.d.ts +159 -0
- package/build/esnext/utils/date.utils.js +384 -0
- package/build/esnext/utils/date.utils.js.map +1 -0
- package/build/esnext/utils/decorators.utils.d.ts +508 -0
- package/build/esnext/utils/decorators.utils.js +877 -0
- package/build/esnext/utils/decorators.utils.js.map +1 -0
- package/build/esnext/utils/dir.utils.d.ts +196 -0
- package/build/esnext/utils/dir.utils.js +477 -0
- package/build/esnext/utils/dir.utils.js.map +1 -0
- package/build/esnext/utils/env.utils.d.ts +377 -0
- package/build/esnext/utils/env.utils.js +785 -0
- package/build/esnext/utils/env.utils.js.map +1 -0
- package/build/esnext/utils/exception.utils.d.ts +230 -0
- package/build/esnext/utils/exception.utils.js +381 -0
- package/build/esnext/utils/exception.utils.js.map +1 -0
- package/build/esnext/utils/fs.utils.d.ts +164 -0
- package/build/esnext/utils/fs.utils.js +349 -0
- package/build/esnext/utils/fs.utils.js.map +1 -0
- package/build/esnext/utils/http-status-codes.d.ts +266 -0
- package/build/esnext/utils/http-status-codes.js +295 -0
- package/build/esnext/utils/http-status-codes.js.map +1 -0
- package/build/esnext/utils/id.utils.d.ts +36 -0
- package/build/esnext/utils/id.utils.js +84 -0
- package/build/esnext/utils/id.utils.js.map +1 -0
- package/build/esnext/utils/logger.utils.d.ts +160 -0
- package/build/esnext/utils/logger.utils.js +300 -0
- package/build/esnext/utils/logger.utils.js.map +1 -0
- package/build/esnext/utils/middleware.utils.d.ts +100 -0
- package/build/esnext/utils/middleware.utils.js +236 -0
- package/build/esnext/utils/middleware.utils.js.map +1 -0
- package/build/esnext/utils/obj.utils.d.ts +124 -0
- package/build/esnext/utils/obj.utils.js +413 -0
- package/build/esnext/utils/obj.utils.js.map +1 -0
- package/build/esnext/utils/performance.utils.d.ts +136 -0
- package/build/esnext/utils/performance.utils.js +271 -0
- package/build/esnext/utils/performance.utils.js.map +1 -0
- package/build/esnext/utils/request.utils.d.ts +86 -0
- package/build/esnext/utils/request.utils.js +186 -0
- package/build/esnext/utils/request.utils.js.map +1 -0
- package/build/esnext/utils/response.utils.d.ts +163 -0
- package/build/esnext/utils/response.utils.js +247 -0
- package/build/esnext/utils/response.utils.js.map +1 -0
- package/build/esnext/utils/stream.utils.d.ts +88 -0
- package/build/esnext/utils/stream.utils.js +210 -0
- package/build/esnext/utils/stream.utils.js.map +1 -0
- package/build/esnext/utils/string.utils.d.ts +93 -0
- package/build/esnext/utils/string.utils.js +165 -0
- package/build/esnext/utils/string.utils.js.map +1 -0
- package/build/esnext/utils/type.utils.d.ts +90 -0
- package/build/esnext/utils/type.utils.js +187 -0
- package/build/esnext/utils/type.utils.js.map +1 -0
- package/build/esnext/utils/url.utils.d.ts +141 -0
- package/build/esnext/utils/url.utils.js +304 -0
- package/build/esnext/utils/url.utils.js.map +1 -0
- package/build/esnext/utils/validate.utils.d.ts +177 -0
- package/build/esnext/utils/validate.utils.js +320 -0
- package/build/esnext/utils/validate.utils.js.map +1 -0
- package/build/src/config.d.ts +122 -0
- package/build/src/config.js +138 -0
- package/build/src/config.js.map +1 -0
- package/build/src/index.d.ts +27 -0
- package/build/src/index.js +69 -0
- package/build/src/index.js.map +1 -0
- package/build/src/servers/server.builder.d.ts +508 -0
- package/build/src/servers/server.builder.js +661 -0
- package/build/src/servers/server.builder.js.map +1 -0
- package/build/src/servers/server.d.ts +256 -0
- package/build/src/servers/server.js +962 -0
- package/build/src/servers/server.js.map +1 -0
- package/build/src/types/api-response.d.ts +152 -0
- package/build/src/types/api-response.js +37 -0
- package/build/src/types/api-response.js.map +1 -0
- package/build/src/types/index.d.ts +125 -0
- package/build/src/types/index.js +26 -0
- package/build/src/types/index.js.map +1 -0
- package/build/src/types/server.d.ts +268 -0
- package/build/src/types/server.js +26 -0
- package/build/src/types/server.js.map +1 -0
- package/build/src/utils/array.utils.d.ts +168 -0
- package/build/src/utils/array.utils.js +364 -0
- package/build/src/utils/array.utils.js.map +1 -0
- package/build/src/utils/async.utils.d.ts +265 -0
- package/build/src/utils/async.utils.js +641 -0
- package/build/src/utils/async.utils.js.map +1 -0
- package/build/src/utils/cache.utils.d.ts +153 -0
- package/build/src/utils/cache.utils.js +297 -0
- package/build/src/utils/cache.utils.js.map +1 -0
- package/build/src/utils/context-store.utils.d.ts +189 -0
- package/build/src/utils/context-store.utils.js +296 -0
- package/build/src/utils/context-store.utils.js.map +1 -0
- package/build/src/utils/crypto.utils.d.ts +160 -0
- package/build/src/utils/crypto.utils.js +293 -0
- package/build/src/utils/crypto.utils.js.map +1 -0
- package/build/src/utils/date.utils.d.ts +159 -0
- package/build/src/utils/date.utils.js +396 -0
- package/build/src/utils/date.utils.js.map +1 -0
- package/build/src/utils/decorators.utils.d.ts +508 -0
- package/build/src/utils/decorators.utils.js +896 -0
- package/build/src/utils/decorators.utils.js.map +1 -0
- package/build/src/utils/dir.utils.d.ts +196 -0
- package/build/src/utils/dir.utils.js +501 -0
- package/build/src/utils/dir.utils.js.map +1 -0
- package/build/src/utils/env.utils.d.ts +377 -0
- package/build/src/utils/env.utils.js +789 -0
- package/build/src/utils/env.utils.js.map +1 -0
- package/build/src/utils/exception.utils.d.ts +230 -0
- package/build/src/utils/exception.utils.js +407 -0
- package/build/src/utils/exception.utils.js.map +1 -0
- package/build/src/utils/fs.utils.d.ts +164 -0
- package/build/src/utils/fs.utils.js +372 -0
- package/build/src/utils/fs.utils.js.map +1 -0
- package/build/src/utils/http-status-codes.d.ts +266 -0
- package/build/src/utils/http-status-codes.js +298 -0
- package/build/src/utils/http-status-codes.js.map +1 -0
- package/build/src/utils/id.utils.d.ts +36 -0
- package/build/src/utils/id.utils.js +91 -0
- package/build/src/utils/id.utils.js.map +1 -0
- package/build/src/utils/logger.utils.d.ts +160 -0
- package/build/src/utils/logger.utils.js +346 -0
- package/build/src/utils/logger.utils.js.map +1 -0
- package/build/src/utils/middleware.utils.d.ts +100 -0
- package/build/src/utils/middleware.utils.js +244 -0
- package/build/src/utils/middleware.utils.js.map +1 -0
- package/build/src/utils/obj.utils.d.ts +124 -0
- package/build/src/utils/obj.utils.js +429 -0
- package/build/src/utils/obj.utils.js.map +1 -0
- package/build/src/utils/performance.utils.d.ts +136 -0
- package/build/src/utils/performance.utils.js +278 -0
- package/build/src/utils/performance.utils.js.map +1 -0
- package/build/src/utils/request.utils.d.ts +86 -0
- package/build/src/utils/request.utils.js +195 -0
- package/build/src/utils/request.utils.js.map +1 -0
- package/build/src/utils/response.utils.d.ts +163 -0
- package/build/src/utils/response.utils.js +260 -0
- package/build/src/utils/response.utils.js.map +1 -0
- package/build/src/utils/stream.utils.d.ts +88 -0
- package/build/src/utils/stream.utils.js +218 -0
- package/build/src/utils/stream.utils.js.map +1 -0
- package/build/src/utils/string.utils.d.ts +93 -0
- package/build/src/utils/string.utils.js +179 -0
- package/build/src/utils/string.utils.js.map +1 -0
- package/build/src/utils/type.utils.d.ts +90 -0
- package/build/src/utils/type.utils.js +196 -0
- package/build/src/utils/type.utils.js.map +1 -0
- package/build/src/utils/url.utils.d.ts +141 -0
- package/build/src/utils/url.utils.js +317 -0
- package/build/src/utils/url.utils.js.map +1 -0
- package/build/src/utils/validate.utils.d.ts +177 -0
- package/build/src/utils/validate.utils.js +345 -0
- package/build/src/utils/validate.utils.js.map +1 -0
- package/package.json +66 -12
- package/build/index.cjs +0 -6888
- package/build/index.d.ts +0 -5242
- package/build/index.mjs +0 -6615
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.utils.js","sourceRoot":"","sources":["../../../src/utils/middleware.utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;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;YAC3B,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;gBACpD,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;gBAC/B,IAAI,CAAC,MAAM;oBAAE,UAAU,GAAG,KAAK,CAAC;YAClC,CAAC;YAAC,WAAM,CAAC;gBACP,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;gBAC5B,UAAU,GAAG,KAAK,CAAC;YACrB,CAAC;QACH,CAAC;QACD,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,mBAAmB,CAAC;QACrF,MAAM,QAAQ,GAAG,QAAQ;YACvB,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE;YACnG,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAChD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { uuid } from './id.utils';\nimport { HttpStatusCodes } from './http-status-codes';\nimport { createFinalErrorResponse, ErrorResponse } from './response.utils';\nimport { getLogger } from './logger.utils';\nimport type { Request, Response, NextFunction } from 'express';\nimport { ContextStore, StoreKeys } from './context-store.utils';\nimport { RequestTimeoutException } from './exception.utils';\nimport { ApiErrorResponse } from '../types/api-response';\n\nexport type Middleware = (req: Request, res: Response, next: NextFunction) => void | Promise<void>;\n\n/**\n * Attaches a unique request ID to each request.\n * Useful for request tracing and correlation between logs.\n *\n * @param {object} [options] - Configuration options\n * @param {string} [options.headerName='X-Request-ID'] - Header name for request ID\n * @param {boolean} [options.exposeHeader=true] - Whether to expose the header in response\n * @param {() => string} [options.generator] - Custom ID generator function\n * @returns {Middleware} Express-compatible middleware\n */\nexport function requestId(options?: {\n headerName?: string;\n exposeHeader?: boolean;\n generator?: () => string;\n}): Middleware {\n const headerName = options?.headerName || 'X-Request-ID';\n const exposeHeader = options?.exposeHeader !== false;\n const generateId = options?.generator || uuid;\n\n return (req, res, next) => {\n // Use existing request ID from header or generate a new one\n const existingId = req.headers[headerName.toLowerCase()];\n const id = (existingId as string) || generateId();\n\n // Attach ID to request object\n req.id = id;\n\n // Add ID to response headers\n if (exposeHeader) {\n res.setHeader(headerName, id);\n }\n\n next();\n };\n}\n\n/**\n * Measures request processing time and logs or adds it to response headers.\n *\n * @param {object} [options] - Configuration options\n * @param {boolean} [options.addHeader=true] - Whether to add X-Response-Time header\n * @param {boolean} [options.logOnComplete=false] - Whether to log timing info\n * @returns {Middleware} Express-compatible middleware\n */\nexport function responseTime(options?: { addHeader?: boolean; logOnComplete?: boolean }) {\n const addHeader = options?.addHeader !== false;\n const logOnComplete = options?.logOnComplete === true;\n\n return (req: Request, res: Response, next: NextFunction) => {\n const start = process.hrtime();\n\n // Function to calculate duration\n const getDuration = () => {\n const diff = process.hrtime(start);\n return (diff[0] * 1e3 + diff[1] * 1e-6).toFixed(2);\n };\n\n if (addHeader) {\n // Ensure header is set before response is sent\n const originalWriteHead = res.writeHead;\n res.writeHead = function (...args: any[]) {\n res.setHeader('X-Response-Time', `${getDuration()}ms`);\n return originalWriteHead.apply(this, args as any);\n };\n }\n\n if (logOnComplete) {\n res.on('finish', () => {\n getLogger().info(`${req.method} ${req.url} - ${getDuration()}ms`);\n });\n }\n\n next();\n };\n}\n\n/**\n * Request timeout middleware.\n * Aborts requests that take too long to process.\n *\n * @param {number} [timeoutMs=30000] - Timeout in milliseconds\n * @returns {Middleware} Express-compatible middleware\n */\nexport function timeout(timeoutMs: number = 30000): Middleware {\n return (_req, res, next) => {\n // Set timeout for the request\n const timer = setTimeout(() => {\n const response = new RequestTimeoutException('Request timed out');\n res.status(HttpStatusCodes.REQUEST_TIMEOUT).json(response);\n }, timeoutMs);\n\n // Clear timeout when response is sent\n res.on('finish', () => {\n clearTimeout(timer);\n });\n\n next();\n };\n}\n\n/**\n * Creates an Express middleware that initializes a per-request context.\n *\n * @param {object} [options] - Optional configuration\n * @param {string} [options.headerName='x-request-id'] - Header to look for request ID\n * @param {boolean} [options.autoLog=true] - Whether to log automatically when context is initialized\n * @returns {(req: Request, res: Response, next: NextFunction) => void} Express middleware function\n */\nexport function setupRequestContext(options: { headerName?: string; autoLog?: boolean } = {}): Middleware {\n const { headerName = 'x-request-id', autoLog = true } = options;\n return (req, _res, next) => {\n // Generate or use existing request ID\n const requestId = (req.headers[headerName] as string) || req?.['id'] || uuid();\n\n ContextStore.run({ [StoreKeys.REQUEST_ID]: requestId }, () => {\n // Create a child logger for this request\n const childLogger = getLogger().child({\n requestId,\n method: req.method,\n url: req.originalUrl || req.url\n });\n\n req.logger = childLogger;\n\n // Store logger in context\n ContextStore.set(StoreKeys.LOGGER, childLogger);\n\n if (autoLog) {\n req.logger.info('Request context initialized');\n }\n\n next();\n });\n };\n}\n\nexport interface ErrorHandlerOptions {\n /** Whether to log errors (default: true) */\n logErrors?: boolean;\n /** Whether to include error details in non-production (default: false) */\n includeDetails?: boolean;\n}\n\n/**\n * Global error handling middleware with enhanced features.\n *\n * @param {ErrorHandlerOptions} options - Error handler options\n * @param {boolean} [options.logErrors=true] - Whether to log errors\n * @param {boolean} [options.includeDetails=false] - Whether to include error details in non-production\n * @returns Error middleware\n *\n * @example\n * import express from 'express';\n * import { errorHandler } from '@catbee/utils';\n *\n * const app = express();\n *\n * // Your routes\n * app.get('/ping', (req, res) => {\n * throw new Error('Something went wrong');\n * });\n *\n * // Error handler (must be last middleware)\n * app.use(errorHandler({ includeDetails: true }));\n *\n * app.listen(3000, () => {\n * console.log('Server running on port 3000');\n * });\n */\nexport function errorHandler(options?: ErrorHandlerOptions) {\n const logErrors = options?.logErrors !== false;\n const includeDetails = options?.includeDetails === true;\n\n return (err: any, req: Request, res: Response, _next: NextFunction) => {\n // Determine status code\n const status = err?.status || err?.statusCode || HttpStatusCodes.INTERNAL_SERVER_ERROR;\n\n // Log error if enabled\n if (logErrors) {\n getLogger().error({ err }, `${err.message || 'Unknown error'}`);\n }\n\n // Handle ErrorResponse instances (our custom error class)\n if (err instanceof ErrorResponse) {\n const result: ApiErrorResponse = {\n error: true,\n message: err.message,\n timestamp: err.timestamp,\n requestId: err?.requestId || req?.id || uuid(),\n status,\n path: req.originalUrl || req.url\n };\n\n if (includeDetails && err?.stack) {\n result.stack = err.stack.split('\\n').map((line: string) => line.trim());\n }\n return res.status(status).json(result);\n }\n\n // Handle any other errors\n return res\n .status(status)\n .json(createFinalErrorResponse(req, status, err?.message || 'Internal Server Error', err, { includeDetails }));\n };\n}\n\n/**\n * Health check middleware for service status and custom checks.\n *\n * @param {object} [options] - Health check options\n * @param {string} [options.path='/healthz'] - Health check endpoint path\n * @param {Array<{name: string; check: () => Promise<boolean> | boolean}>} [options.checks] - Custom health checks\n * @param {boolean} [options.detailed=true] - Show detailed check results\n * @returns {Middleware} Express-compatible middleware\n */\nexport function healthCheck(options?: {\n path?: string;\n checks?: Array<{ name: string; check: () => Promise<boolean> | boolean }>;\n detailed?: boolean;\n}): Middleware {\n const path = options?.path || '/healthz';\n const checks = options?.checks || [];\n const detailed = options?.detailed !== false;\n\n return async (req, res, next) => {\n if (req.path !== path) return next();\n const results: Record<string, boolean> = {};\n let allHealthy = true;\n for (const check of checks) {\n try {\n const result = await Promise.resolve(check.check());\n results[check.name] = !!result;\n if (!result) allHealthy = false;\n } catch {\n results[check.name] = false;\n allHealthy = false;\n }\n }\n const status = allHealthy ? HttpStatusCodes.OK : HttpStatusCodes.SERVICE_UNAVAILABLE;\n const response = detailed\n ? { status: allHealthy ? 'ok' : 'unhealthy', checks: results, timestamp: new Date().toISOString() }\n : { status: allHealthy ? 'ok' : 'unhealthy' };\n res.status(status).json(response);\n };\n}\n"]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether the object has no own enumerable properties.
|
|
3
|
+
*
|
|
4
|
+
* @param {Record<any, any>} obj - The object to check.
|
|
5
|
+
* @returns {boolean} True if the object is empty, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isObjEmpty(obj: Record<any, any>): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Returns a new object with only the specified keys picked.
|
|
10
|
+
*
|
|
11
|
+
* @template T
|
|
12
|
+
* @template K
|
|
13
|
+
* @param {T} obj - The source object.
|
|
14
|
+
* @param {K[]} keys - Keys to pick from the object.
|
|
15
|
+
* @returns {Pick<T, K>} New object with picked keys.
|
|
16
|
+
*/
|
|
17
|
+
export declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
18
|
+
/**
|
|
19
|
+
* Returns a new object with the specified keys omitted.
|
|
20
|
+
*
|
|
21
|
+
* @template T
|
|
22
|
+
* @template K
|
|
23
|
+
* @param {T} obj - The source object.
|
|
24
|
+
* @param {K[]} keys - Keys to omit from the object.
|
|
25
|
+
* @returns {Omit<T, K>} New object without omitted keys.
|
|
26
|
+
*/
|
|
27
|
+
export declare function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
28
|
+
/**
|
|
29
|
+
* Deeply merges multiple objects into the target object (mutates and returns the target object, not pure).
|
|
30
|
+
*
|
|
31
|
+
* @template T
|
|
32
|
+
* @param {T} target - The object to merge into (will be mutated).
|
|
33
|
+
* @param {...any[]} sources - The objects to merge from.
|
|
34
|
+
* @returns {T} The merged object (same as target).
|
|
35
|
+
*/
|
|
36
|
+
export declare function deepObjMerge<T extends object>(target: T, ...sources: any[]): T;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if a value is a plain object (i.e., not an array, null, or a built-in object).
|
|
39
|
+
*
|
|
40
|
+
* @param value - The value to check.
|
|
41
|
+
* @returns True if the value is a plain object, false otherwise.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isPlainObject(value: any): value is Record<string, any>;
|
|
44
|
+
/**
|
|
45
|
+
* Flattens a nested object using dot notation for keys (e.g., `{a: {b: 1}}` → `{ "a.b": 1 }`).
|
|
46
|
+
*
|
|
47
|
+
* @template T
|
|
48
|
+
* @param {T} obj - The object to flatten.
|
|
49
|
+
* @param {string} [prefix=""] - Optional prefix for nested keys (used internally).
|
|
50
|
+
* @returns {Record<string, any>} A new object with flattened keys.
|
|
51
|
+
*/
|
|
52
|
+
export declare function flattenObject<T extends Record<string, any>>(obj: T, prefix?: string): Record<string, any>;
|
|
53
|
+
/**
|
|
54
|
+
* Safely gets the value of a deeply nested key in an object using dot/bracket notation path.
|
|
55
|
+
*
|
|
56
|
+
* @template T
|
|
57
|
+
* @param {T} obj - The object to extract from.
|
|
58
|
+
* @param {string} path - String path using dot and/or bracket notation (e.g., 'user.friends[0].name').
|
|
59
|
+
* @returns {any} The value at the given path, or undefined if not found.
|
|
60
|
+
*/
|
|
61
|
+
export declare function getValueByPath<T extends object>(obj: T, path: string): any;
|
|
62
|
+
/**
|
|
63
|
+
* Sets a value at a deeply nested key in an object using dot/bracket notation path.
|
|
64
|
+
* Creates intermediate objects and arrays as needed.
|
|
65
|
+
*
|
|
66
|
+
* @template T
|
|
67
|
+
* @param {T} obj - The object to modify.
|
|
68
|
+
* @param {string} path - String path using dot and/or bracket notation (e.g., 'user.friends[0].name').
|
|
69
|
+
* @param {any} value - The value to set at the path.
|
|
70
|
+
* @returns {T} The modified object.
|
|
71
|
+
*/
|
|
72
|
+
export declare function setValueByPath<T extends object>(obj: T, path: string, value: any): T;
|
|
73
|
+
/**
|
|
74
|
+
* Performs a deep equality check between two objects.
|
|
75
|
+
*
|
|
76
|
+
* @param {any} a - First value to compare.
|
|
77
|
+
* @param {any} b - Second value to compare.
|
|
78
|
+
* @returns {boolean} True if values are deeply equal.
|
|
79
|
+
*/
|
|
80
|
+
export declare function isEqual(a: any, b: any): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Filters object properties based on a predicate function.
|
|
83
|
+
*
|
|
84
|
+
* @template T
|
|
85
|
+
* @param {T} obj - The source object.
|
|
86
|
+
* @param {(value: any, key: string, obj: T) => boolean} predicate - Filter function.
|
|
87
|
+
* @returns {Partial<T>} New object with filtered properties.
|
|
88
|
+
*/
|
|
89
|
+
export declare function filterObject<T extends object>(obj: T, predicate: (value: any, key: string, obj: T) => boolean): Partial<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Maps object values to new values using a mapping function.
|
|
92
|
+
*
|
|
93
|
+
* @template T
|
|
94
|
+
* @template U
|
|
95
|
+
* @param {T} obj - The source object.
|
|
96
|
+
* @param {(value: any, key: string, obj: T) => U} mapFn - Mapping function.
|
|
97
|
+
* @returns {Record<keyof T, U>} New object with mapped values.
|
|
98
|
+
*/
|
|
99
|
+
export declare function mapObject<T extends object, U>(obj: T, mapFn: (value: any, key: string, obj: T) => U): Record<keyof T, U>;
|
|
100
|
+
/**
|
|
101
|
+
* Recursively freezes an object and all its properties.
|
|
102
|
+
* Makes an object immutable.
|
|
103
|
+
*
|
|
104
|
+
* @template T
|
|
105
|
+
* @param {T} obj - The object to freeze.
|
|
106
|
+
* @returns {Readonly<T>} The frozen object.
|
|
107
|
+
*/
|
|
108
|
+
export declare function deepFreeze<T extends object>(obj: T): Readonly<T>;
|
|
109
|
+
/**
|
|
110
|
+
* Safely checks if a value is an object (not null, not array).
|
|
111
|
+
*
|
|
112
|
+
* @param {unknown} value - Value to check.
|
|
113
|
+
* @returns {boolean} True if value is a non-null, non-array object.
|
|
114
|
+
*/
|
|
115
|
+
export declare function isObject(value: unknown): value is Record<string, any>;
|
|
116
|
+
/**
|
|
117
|
+
* Gets all paths in an object using dot notation.
|
|
118
|
+
*
|
|
119
|
+
* @param {Record<string, any>} obj - Object to analyze.
|
|
120
|
+
* @param {string} [parentPath=""] - Internal param for recursion.
|
|
121
|
+
* @returns {string[]} Array of all paths in dot notation.
|
|
122
|
+
*/
|
|
123
|
+
export declare function getAllPaths(obj: Record<string, any>, parentPath?: string): string[];
|
|
124
|
+
//# sourceMappingURL=obj.utils.d.ts.map
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Checks whether the object has no own enumerable properties.
|
|
26
|
+
*
|
|
27
|
+
* @param {Record<any, any>} obj - The object to check.
|
|
28
|
+
* @returns {boolean} True if the object is empty, false otherwise.
|
|
29
|
+
*/
|
|
30
|
+
export function isObjEmpty(obj) {
|
|
31
|
+
return !!obj && typeof obj === 'object' && Object.keys(obj).length === 0;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns a new object with only the specified keys picked.
|
|
35
|
+
*
|
|
36
|
+
* @template T
|
|
37
|
+
* @template K
|
|
38
|
+
* @param {T} obj - The source object.
|
|
39
|
+
* @param {K[]} keys - Keys to pick from the object.
|
|
40
|
+
* @returns {Pick<T, K>} New object with picked keys.
|
|
41
|
+
*/
|
|
42
|
+
export function pick(obj, keys) {
|
|
43
|
+
return Object.fromEntries(keys.map(key => [key, obj[key]]));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns a new object with the specified keys omitted.
|
|
47
|
+
*
|
|
48
|
+
* @template T
|
|
49
|
+
* @template K
|
|
50
|
+
* @param {T} obj - The source object.
|
|
51
|
+
* @param {K[]} keys - Keys to omit from the object.
|
|
52
|
+
* @returns {Omit<T, K>} New object without omitted keys.
|
|
53
|
+
*/
|
|
54
|
+
export function omit(obj, keys) {
|
|
55
|
+
return Object.fromEntries(Object.entries(obj).filter(([key]) => !keys.includes(key)));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Deeply merges multiple objects into the target object (mutates and returns the target object, not pure).
|
|
59
|
+
*
|
|
60
|
+
* @template T
|
|
61
|
+
* @param {T} target - The object to merge into (will be mutated).
|
|
62
|
+
* @param {...any[]} sources - The objects to merge from.
|
|
63
|
+
* @returns {T} The merged object (same as target).
|
|
64
|
+
*/
|
|
65
|
+
export function deepObjMerge(target, ...sources) {
|
|
66
|
+
if (!sources.length)
|
|
67
|
+
return target;
|
|
68
|
+
const seen = new WeakMap();
|
|
69
|
+
seen.set(target, target);
|
|
70
|
+
for (const s of sources) {
|
|
71
|
+
if (s && typeof s === 'object') {
|
|
72
|
+
seen.set(s, target);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function deepClone(value) {
|
|
76
|
+
if (value === null || typeof value !== 'object')
|
|
77
|
+
return value;
|
|
78
|
+
if (seen.has(value))
|
|
79
|
+
return seen.get(value);
|
|
80
|
+
// Date
|
|
81
|
+
if (value instanceof Date) {
|
|
82
|
+
return new Date(value.getTime());
|
|
83
|
+
}
|
|
84
|
+
// Array
|
|
85
|
+
if (Array.isArray(value)) {
|
|
86
|
+
const clone = [];
|
|
87
|
+
seen.set(value, clone);
|
|
88
|
+
value.forEach((item, i) => (clone[i] = deepClone(item)));
|
|
89
|
+
return clone;
|
|
90
|
+
}
|
|
91
|
+
// Set
|
|
92
|
+
if (value instanceof Set) {
|
|
93
|
+
const clone = new Set();
|
|
94
|
+
seen.set(value, clone);
|
|
95
|
+
value.forEach(item => clone.add(deepClone(item)));
|
|
96
|
+
return clone;
|
|
97
|
+
}
|
|
98
|
+
// Map
|
|
99
|
+
if (value instanceof Map) {
|
|
100
|
+
const clone = new Map();
|
|
101
|
+
seen.set(value, clone);
|
|
102
|
+
value.forEach((val, key) => clone.set(key, deepClone(val)));
|
|
103
|
+
return clone;
|
|
104
|
+
}
|
|
105
|
+
// RegExp
|
|
106
|
+
if (value instanceof RegExp) {
|
|
107
|
+
return new RegExp(value.source, value.flags);
|
|
108
|
+
}
|
|
109
|
+
// ArrayBuffer
|
|
110
|
+
if (value instanceof ArrayBuffer) {
|
|
111
|
+
return value.slice(0);
|
|
112
|
+
}
|
|
113
|
+
// TypedArrays
|
|
114
|
+
if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
|
|
115
|
+
const typed = value; // cast for TS
|
|
116
|
+
const ctor = typed.constructor;
|
|
117
|
+
// List of standard TypedArray constructors
|
|
118
|
+
const typedArrayCtors = [
|
|
119
|
+
Int8Array,
|
|
120
|
+
Uint8Array,
|
|
121
|
+
Uint8ClampedArray,
|
|
122
|
+
Int16Array,
|
|
123
|
+
Uint16Array,
|
|
124
|
+
Int32Array,
|
|
125
|
+
Uint32Array,
|
|
126
|
+
Float32Array,
|
|
127
|
+
Float64Array,
|
|
128
|
+
BigInt64Array,
|
|
129
|
+
BigUint64Array
|
|
130
|
+
].filter(Boolean); // filter out undefined (for environments without BigInt)
|
|
131
|
+
const typedArrayCtorSet = new Set(typedArrayCtors);
|
|
132
|
+
if (typeof ctor === 'function' && typedArrayCtorSet.has(ctor)) {
|
|
133
|
+
// Defensive: ensure buffer is an ArrayBuffer and slice is available
|
|
134
|
+
const buffer = typed.buffer && typeof typed.buffer.slice === 'function' ? typed.buffer.slice(0) : typed.buffer;
|
|
135
|
+
const clone = new ctor(buffer, typed.byteOffset, typed.length);
|
|
136
|
+
seen.set(value, clone);
|
|
137
|
+
return clone;
|
|
138
|
+
}
|
|
139
|
+
else if (typeof typed.slice === 'function') {
|
|
140
|
+
// Fallback: try using slice if available (e.g., Node.js Buffer)
|
|
141
|
+
const clone = typed.slice();
|
|
142
|
+
seen.set(value, clone);
|
|
143
|
+
return clone;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
// Could not safely clone, throw an error for better debugging
|
|
147
|
+
throw new Error('Cannot deep clone unknown TypedArray type: ' + (typed && typed.constructor && typed.constructor.name));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const clone = Object.create(Object.getPrototypeOf(value));
|
|
151
|
+
seen.set(value, clone);
|
|
152
|
+
Reflect.ownKeys(value).forEach(key => {
|
|
153
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
154
|
+
if (descriptor.get || descriptor.set) {
|
|
155
|
+
Object.defineProperty(clone, key, descriptor);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
clone[key] = deepClone(value[key]);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
return clone;
|
|
162
|
+
}
|
|
163
|
+
function mergeProp(target, source, key) {
|
|
164
|
+
const targetValue = target[key];
|
|
165
|
+
const sourceValue = source[key];
|
|
166
|
+
// Ignore undefined in source
|
|
167
|
+
if (sourceValue === undefined)
|
|
168
|
+
return;
|
|
169
|
+
// Primitives → overwrite directly
|
|
170
|
+
if (sourceValue === null || typeof sourceValue !== 'object') {
|
|
171
|
+
target[key] = sourceValue;
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// Arrays → replace (lodash behavior)
|
|
175
|
+
if (Array.isArray(sourceValue)) {
|
|
176
|
+
target[key] = deepClone(sourceValue);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
// Special cloneable objects
|
|
180
|
+
if (sourceValue instanceof Date ||
|
|
181
|
+
sourceValue instanceof RegExp ||
|
|
182
|
+
sourceValue instanceof Set ||
|
|
183
|
+
sourceValue instanceof Map ||
|
|
184
|
+
sourceValue instanceof ArrayBuffer ||
|
|
185
|
+
(ArrayBuffer.isView(sourceValue) && !(sourceValue instanceof DataView))) {
|
|
186
|
+
target[key] = deepClone(sourceValue);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
// Plain objects → recursive merge
|
|
190
|
+
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
191
|
+
for (const k of Reflect.ownKeys(sourceValue)) {
|
|
192
|
+
mergeProp(targetValue, sourceValue, k);
|
|
193
|
+
}
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
// Default → overwrite with clone
|
|
197
|
+
target[key] = deepClone(sourceValue);
|
|
198
|
+
}
|
|
199
|
+
for (const source of sources) {
|
|
200
|
+
if (source == null)
|
|
201
|
+
continue;
|
|
202
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
203
|
+
mergeProp(target, source, key);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return target;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Checks if a value is a plain object (i.e., not an array, null, or a built-in object).
|
|
210
|
+
*
|
|
211
|
+
* @param value - The value to check.
|
|
212
|
+
* @returns True if the value is a plain object, false otherwise.
|
|
213
|
+
*/
|
|
214
|
+
export function isPlainObject(value) {
|
|
215
|
+
if (typeof value !== 'object' || value === null)
|
|
216
|
+
return false;
|
|
217
|
+
if (Array.isArray(value))
|
|
218
|
+
return false;
|
|
219
|
+
const proto = Object.getPrototypeOf(value);
|
|
220
|
+
return proto === Object.prototype || proto === null;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Flattens a nested object using dot notation for keys (e.g., `{a: {b: 1}}` → `{ "a.b": 1 }`).
|
|
224
|
+
*
|
|
225
|
+
* @template T
|
|
226
|
+
* @param {T} obj - The object to flatten.
|
|
227
|
+
* @param {string} [prefix=""] - Optional prefix for nested keys (used internally).
|
|
228
|
+
* @returns {Record<string, any>} A new object with flattened keys.
|
|
229
|
+
*/
|
|
230
|
+
export function flattenObject(obj, prefix = '') {
|
|
231
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
232
|
+
const newKey = prefix ? `${prefix}.${key}` : key;
|
|
233
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
234
|
+
Object.assign(acc, flattenObject(value, newKey));
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
acc[newKey] = value;
|
|
238
|
+
}
|
|
239
|
+
return acc;
|
|
240
|
+
}, {});
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Safely gets the value of a deeply nested key in an object using dot/bracket notation path.
|
|
244
|
+
*
|
|
245
|
+
* @template T
|
|
246
|
+
* @param {T} obj - The object to extract from.
|
|
247
|
+
* @param {string} path - String path using dot and/or bracket notation (e.g., 'user.friends[0].name').
|
|
248
|
+
* @returns {any} The value at the given path, or undefined if not found.
|
|
249
|
+
*/
|
|
250
|
+
export function getValueByPath(obj, path) {
|
|
251
|
+
if (!obj || typeof obj !== 'object')
|
|
252
|
+
return undefined;
|
|
253
|
+
// Convert path like "a.b[0].c" into ["a", "b", "0", "c"]
|
|
254
|
+
const parts = path
|
|
255
|
+
.replace(/\[(\d+)\]/g, '.$1') // convert [0] to .0
|
|
256
|
+
.split('.')
|
|
257
|
+
.filter(Boolean); // remove empty strings
|
|
258
|
+
return parts.reduce((acc, key) => acc === null || acc === void 0 ? void 0 : acc[key], obj);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Sets a value at a deeply nested key in an object using dot/bracket notation path.
|
|
262
|
+
* Creates intermediate objects and arrays as needed.
|
|
263
|
+
*
|
|
264
|
+
* @template T
|
|
265
|
+
* @param {T} obj - The object to modify.
|
|
266
|
+
* @param {string} path - String path using dot and/or bracket notation (e.g., 'user.friends[0].name').
|
|
267
|
+
* @param {any} value - The value to set at the path.
|
|
268
|
+
* @returns {T} The modified object.
|
|
269
|
+
*/
|
|
270
|
+
export function setValueByPath(obj, path, value) {
|
|
271
|
+
if (!obj || typeof obj !== 'object')
|
|
272
|
+
return obj;
|
|
273
|
+
// Convert path like "a.b[0].c" into ["a", "b", "0", "c"]
|
|
274
|
+
const parts = path
|
|
275
|
+
.replace(/\[(\d+)\]/g, '.$1') // convert [0] to .0
|
|
276
|
+
.split('.')
|
|
277
|
+
.filter(Boolean); // remove empty strings
|
|
278
|
+
// Handle empty path
|
|
279
|
+
if (parts.length === 0)
|
|
280
|
+
return obj;
|
|
281
|
+
let current = obj;
|
|
282
|
+
// Navigate to the parent of the target property
|
|
283
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
284
|
+
const key = parts[i];
|
|
285
|
+
const isArrayIndex = !isNaN(Number(parts[i + 1]));
|
|
286
|
+
if (current[key] === undefined) {
|
|
287
|
+
// Create intermediate object or array based on next key type
|
|
288
|
+
current[key] = isArrayIndex ? [] : {};
|
|
289
|
+
}
|
|
290
|
+
current = current[key];
|
|
291
|
+
}
|
|
292
|
+
// Set the value at the final key
|
|
293
|
+
const finalKey = parts[parts.length - 1];
|
|
294
|
+
current[finalKey] = value;
|
|
295
|
+
return obj;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Performs a deep equality check between two objects.
|
|
299
|
+
*
|
|
300
|
+
* @param {any} a - First value to compare.
|
|
301
|
+
* @param {any} b - Second value to compare.
|
|
302
|
+
* @returns {boolean} True if values are deeply equal.
|
|
303
|
+
*/
|
|
304
|
+
export function isEqual(a, b) {
|
|
305
|
+
// Check if primitives or references to the same object
|
|
306
|
+
if (a === b)
|
|
307
|
+
return true;
|
|
308
|
+
// Check if either is null/undefined or not an object
|
|
309
|
+
if (a == null || b == null || typeof a !== 'object' || typeof b !== 'object') {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
// Handle Date objects
|
|
313
|
+
if (a instanceof Date && b instanceof Date) {
|
|
314
|
+
return a.getTime() === b.getTime();
|
|
315
|
+
}
|
|
316
|
+
// If one is Date but the other isn't
|
|
317
|
+
if (a instanceof Date || b instanceof Date) {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
// Handle arrays
|
|
321
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
322
|
+
if (a.length !== b.length)
|
|
323
|
+
return false;
|
|
324
|
+
// Check each element
|
|
325
|
+
for (let i = 0; i < a.length; i++) {
|
|
326
|
+
if (!isEqual(a[i], b[i]))
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
// If one is Array but the other isn't
|
|
332
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
// Compare object keys
|
|
336
|
+
const keysA = Object.keys(a);
|
|
337
|
+
const keysB = Object.keys(b);
|
|
338
|
+
if (keysA.length !== keysB.length)
|
|
339
|
+
return false;
|
|
340
|
+
// Check if every key in A exists in B and has the same value
|
|
341
|
+
return keysA.every(key => Object.prototype.hasOwnProperty.call(b, key) && isEqual(a[key], b[key]));
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Filters object properties based on a predicate function.
|
|
345
|
+
*
|
|
346
|
+
* @template T
|
|
347
|
+
* @param {T} obj - The source object.
|
|
348
|
+
* @param {(value: any, key: string, obj: T) => boolean} predicate - Filter function.
|
|
349
|
+
* @returns {Partial<T>} New object with filtered properties.
|
|
350
|
+
*/
|
|
351
|
+
export function filterObject(obj, predicate) {
|
|
352
|
+
return Object.fromEntries(Object.entries(obj).filter(([key, value]) => predicate(value, key, obj)));
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Maps object values to new values using a mapping function.
|
|
356
|
+
*
|
|
357
|
+
* @template T
|
|
358
|
+
* @template U
|
|
359
|
+
* @param {T} obj - The source object.
|
|
360
|
+
* @param {(value: any, key: string, obj: T) => U} mapFn - Mapping function.
|
|
361
|
+
* @returns {Record<keyof T, U>} New object with mapped values.
|
|
362
|
+
*/
|
|
363
|
+
export function mapObject(obj, mapFn) {
|
|
364
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, mapFn(value, key, obj)]));
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Recursively freezes an object and all its properties.
|
|
368
|
+
* Makes an object immutable.
|
|
369
|
+
*
|
|
370
|
+
* @template T
|
|
371
|
+
* @param {T} obj - The object to freeze.
|
|
372
|
+
* @returns {Readonly<T>} The frozen object.
|
|
373
|
+
*/
|
|
374
|
+
export function deepFreeze(obj) {
|
|
375
|
+
// Freeze primitive properties
|
|
376
|
+
Object.freeze(obj);
|
|
377
|
+
// Recursively freeze nested objects
|
|
378
|
+
for (const prop of Object.getOwnPropertyNames(obj)) {
|
|
379
|
+
const value = obj[prop];
|
|
380
|
+
if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
381
|
+
deepFreeze(value);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return obj;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Safely checks if a value is an object (not null, not array).
|
|
388
|
+
*
|
|
389
|
+
* @param {unknown} value - Value to check.
|
|
390
|
+
* @returns {boolean} True if value is a non-null, non-array object.
|
|
391
|
+
*/
|
|
392
|
+
export function isObject(value) {
|
|
393
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Gets all paths in an object using dot notation.
|
|
397
|
+
*
|
|
398
|
+
* @param {Record<string, any>} obj - Object to analyze.
|
|
399
|
+
* @param {string} [parentPath=""] - Internal param for recursion.
|
|
400
|
+
* @returns {string[]} Array of all paths in dot notation.
|
|
401
|
+
*/
|
|
402
|
+
export function getAllPaths(obj, parentPath = '') {
|
|
403
|
+
if (!isObject(obj))
|
|
404
|
+
return [];
|
|
405
|
+
return Object.entries(obj).flatMap(([key, value]) => {
|
|
406
|
+
const currentPath = parentPath ? `${parentPath}.${key}` : key;
|
|
407
|
+
if (isObject(value)) {
|
|
408
|
+
return [currentPath, ...getAllPaths(value, currentPath)];
|
|
409
|
+
}
|
|
410
|
+
return [currentPath];
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
//# sourceMappingURL=obj.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"obj.utils.js","sourceRoot":"","sources":["../../../src/utils/obj.utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,GAAqB;IAC9C,OAAO,CAAC,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAsC,GAAM,EAAE,IAAS;IACzE,OAAO,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAe,CAAC;AAC5E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAsC,GAAM,EAAE,IAAS;IACzE,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAQ,CAAC,CAAC,CAAe,CAAC;AAC3G,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAmB,MAAS,EAAE,GAAG,OAAc;IACzE,IAAI,CAAC,OAAO,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC;IAEnC,MAAM,IAAI,GAAG,IAAI,OAAO,EAAE,CAAC;IAC3B,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEzB,KAAK,MAAM,CAAC,IAAI,OAAO,EAA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;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,GAAwB,EAAE,aAAqB,EAAE;IAC3E,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC;IAE9B,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAClD,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QAE9D,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACpB,OAAO,CAAC,WAAW,EAAE,GAAG,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,CAAC,WAAW,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Checks whether the object has no own enumerable properties.\n *\n * @param {Record<any, any>} obj - The object to check.\n * @returns {boolean} True if the object is empty, false otherwise.\n */\nexport function isObjEmpty(obj: Record<any, any>): boolean {\n return !!obj && typeof obj === 'object' && Object.keys(obj).length === 0;\n}\n\n/**\n * Returns a new object with only the specified keys picked.\n *\n * @template T\n * @template K\n * @param {T} obj - The source object.\n * @param {K[]} keys - Keys to pick from the object.\n * @returns {Pick<T, K>} New object with picked keys.\n */\nexport function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n return Object.fromEntries(keys.map(key => [key, obj[key]])) as Pick<T, K>;\n}\n\n/**\n * Returns a new object with the specified keys omitted.\n *\n * @template T\n * @template K\n * @param {T} obj - The source object.\n * @param {K[]} keys - Keys to omit from the object.\n * @returns {Omit<T, K>} New object without omitted keys.\n */\nexport function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n return Object.fromEntries(Object.entries(obj).filter(([key]) => !keys.includes(key as K))) as Omit<T, K>;\n}\n\n/**\n * Deeply merges multiple objects into the target object (mutates and returns the target object, not pure).\n *\n * @template T\n * @param {T} target - The object to merge into (will be mutated).\n * @param {...any[]} sources - The objects to merge from.\n * @returns {T} The merged object (same as target).\n */\nexport function deepObjMerge<T extends object>(target: T, ...sources: any[]): T {\n if (!sources.length) return target;\n\n const seen = new WeakMap();\n seen.set(target, target);\n\n for (const s of sources) {\n if (s && typeof s === 'object') {\n seen.set(s, target);\n }\n }\n\n function deepClone(value: any): any {\n if (value === null || typeof value !== 'object') return value;\n\n if (seen.has(value)) return seen.get(value);\n\n // Date\n if (value instanceof Date) {\n return new Date(value.getTime());\n }\n\n // Array\n if (Array.isArray(value)) {\n const clone: any[] = [];\n seen.set(value, clone);\n value.forEach((item, i) => (clone[i] = deepClone(item)));\n return clone;\n }\n\n // Set\n if (value instanceof Set) {\n const clone = new Set();\n seen.set(value, clone);\n value.forEach(item => clone.add(deepClone(item)));\n return clone;\n }\n\n // Map\n if (value instanceof Map) {\n const clone = new Map();\n seen.set(value, clone);\n value.forEach((val, key) => clone.set(key, deepClone(val)));\n return clone;\n }\n\n // RegExp\n if (value instanceof RegExp) {\n return new RegExp(value.source, value.flags);\n }\n\n // ArrayBuffer\n if (value instanceof ArrayBuffer) {\n return value.slice(0);\n }\n\n // TypedArrays\n if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {\n const typed = value as any; // cast for TS\n const ctor = typed.constructor;\n // List of standard TypedArray constructors\n const typedArrayCtors = [\n Int8Array,\n Uint8Array,\n Uint8ClampedArray,\n Int16Array,\n Uint16Array,\n Int32Array,\n Uint32Array,\n Float32Array,\n Float64Array,\n BigInt64Array,\n BigUint64Array\n ].filter(Boolean); // filter out undefined (for environments without BigInt)\n const typedArrayCtorSet = new Set(typedArrayCtors);\n if (typeof ctor === 'function' && typedArrayCtorSet.has(ctor)) {\n // Defensive: ensure buffer is an ArrayBuffer and slice is available\n const buffer = typed.buffer && typeof typed.buffer.slice === 'function' ? typed.buffer.slice(0) : typed.buffer;\n const clone = new ctor(buffer, typed.byteOffset, typed.length);\n seen.set(value, clone);\n return clone;\n } else if (typeof typed.slice === 'function') {\n // Fallback: try using slice if available (e.g., Node.js Buffer)\n const clone = typed.slice();\n seen.set(value, clone);\n return clone;\n } else {\n // Could not safely clone, throw an error for better debugging\n throw new Error(\n 'Cannot deep clone unknown TypedArray type: ' + (typed && typed.constructor && typed.constructor.name)\n );\n }\n }\n\n const clone = Object.create(Object.getPrototypeOf(value));\n seen.set(value, clone);\n\n Reflect.ownKeys(value).forEach(key => {\n const descriptor = Object.getOwnPropertyDescriptor(value, key)!;\n if (descriptor.get || descriptor.set) {\n Object.defineProperty(clone, key, descriptor);\n } else {\n (clone as any)[key] = deepClone((value as any)[key]);\n }\n });\n\n return clone;\n }\n\n function mergeProp(target: any, source: any, key: string | symbol): void {\n const targetValue = target[key];\n const sourceValue = source[key];\n\n // Ignore undefined in source\n if (sourceValue === undefined) return;\n\n // Primitives → overwrite directly\n if (sourceValue === null || typeof sourceValue !== 'object') {\n target[key] = sourceValue;\n return;\n }\n\n // Arrays → replace (lodash behavior)\n if (Array.isArray(sourceValue)) {\n target[key] = deepClone(sourceValue);\n return;\n }\n\n // Special cloneable objects\n if (\n sourceValue instanceof Date ||\n sourceValue instanceof RegExp ||\n sourceValue instanceof Set ||\n sourceValue instanceof Map ||\n sourceValue instanceof ArrayBuffer ||\n (ArrayBuffer.isView(sourceValue) && !(sourceValue instanceof DataView))\n ) {\n target[key] = deepClone(sourceValue);\n return;\n }\n\n // Plain objects → recursive merge\n if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {\n for (const k of Reflect.ownKeys(sourceValue)) {\n mergeProp(targetValue, sourceValue, k);\n }\n return;\n }\n\n // Default → overwrite with clone\n target[key] = deepClone(sourceValue);\n }\n\n for (const source of sources) {\n if (source == null) continue;\n\n for (const key of Reflect.ownKeys(source)) {\n mergeProp(target, source, key);\n }\n }\n\n return target;\n}\n\n/**\n * Checks if a value is a plain object (i.e., not an array, null, or a built-in object).\n *\n * @param value - The value to check.\n * @returns True if the value is a plain object, false otherwise.\n */\nexport function isPlainObject(value: any): value is Record<string, any> {\n if (typeof value !== 'object' || value === null) return false;\n if (Array.isArray(value)) return false;\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\n/**\n * Flattens a nested object using dot notation for keys (e.g., `{a: {b: 1}}` → `{ \"a.b\": 1 }`).\n *\n * @template T\n * @param {T} obj - The object to flatten.\n * @param {string} [prefix=\"\"] - Optional prefix for nested keys (used internally).\n * @returns {Record<string, any>} A new object with flattened keys.\n */\nexport function flattenObject<T extends Record<string, any>>(obj: T, prefix = ''): Record<string, any> {\n return Object.entries(obj).reduce((acc: Record<string, any>, [key, value]) => {\n const newKey = prefix ? `${prefix}.${key}` : key;\n\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n Object.assign(acc, flattenObject(value, newKey));\n } else {\n acc[newKey] = value;\n }\n\n return acc;\n }, {});\n}\n\n/**\n * Safely gets the value of a deeply nested key in an object using dot/bracket notation path.\n *\n * @template T\n * @param {T} obj - The object to extract from.\n * @param {string} path - String path using dot and/or bracket notation (e.g., 'user.friends[0].name').\n * @returns {any} The value at the given path, or undefined if not found.\n */\nexport function getValueByPath<T extends object>(obj: T, path: string) {\n if (!obj || typeof obj !== 'object') return undefined;\n\n // Convert path like \"a.b[0].c\" into [\"a\", \"b\", \"0\", \"c\"]\n const parts = path\n .replace(/\\[(\\d+)\\]/g, '.$1') // convert [0] to .0\n .split('.')\n .filter(Boolean); // remove empty strings\n\n return parts.reduce((acc: any, key: string) => acc?.[key], obj);\n}\n\n/**\n * Sets a value at a deeply nested key in an object using dot/bracket notation path.\n * Creates intermediate objects and arrays as needed.\n *\n * @template T\n * @param {T} obj - The object to modify.\n * @param {string} path - String path using dot and/or bracket notation (e.g., 'user.friends[0].name').\n * @param {any} value - The value to set at the path.\n * @returns {T} The modified object.\n */\nexport function setValueByPath<T extends object>(obj: T, path: string, value: any): T {\n if (!obj || typeof obj !== 'object') return obj;\n\n // Convert path like \"a.b[0].c\" into [\"a\", \"b\", \"0\", \"c\"]\n const parts = path\n .replace(/\\[(\\d+)\\]/g, '.$1') // convert [0] to .0\n .split('.')\n .filter(Boolean); // remove empty strings\n\n // Handle empty path\n if (parts.length === 0) return obj;\n\n let current: any = obj;\n\n // Navigate to the parent of the target property\n for (let i = 0; i < parts.length - 1; i++) {\n const key = parts[i];\n const isArrayIndex = !isNaN(Number(parts[i + 1]));\n\n if (current[key] === undefined) {\n // Create intermediate object or array based on next key type\n current[key] = isArrayIndex ? [] : {};\n }\n\n current = current[key];\n }\n\n // Set the value at the final key\n const finalKey = parts[parts.length - 1];\n current[finalKey] = value;\n\n return obj;\n}\n\n/**\n * Performs a deep equality check between two objects.\n *\n * @param {any} a - First value to compare.\n * @param {any} b - Second value to compare.\n * @returns {boolean} True if values are deeply equal.\n */\nexport function isEqual(a: any, b: any): boolean {\n // Check if primitives or references to the same object\n if (a === b) return true;\n\n // Check if either is null/undefined or not an object\n if (a == null || b == null || typeof a !== 'object' || typeof b !== 'object') {\n return false;\n }\n\n // Handle Date objects\n if (a instanceof Date && b instanceof Date) {\n return a.getTime() === b.getTime();\n }\n\n // If one is Date but the other isn't\n if (a instanceof Date || b instanceof Date) {\n return false;\n }\n\n // Handle arrays\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false;\n\n // Check each element\n for (let i = 0; i < a.length; i++) {\n if (!isEqual(a[i], b[i])) return false;\n }\n\n return true;\n }\n\n // If one is Array but the other isn't\n if (Array.isArray(a) || Array.isArray(b)) {\n return false;\n }\n\n // Compare object keys\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n // Check if every key in A exists in B and has the same value\n return keysA.every(key => Object.prototype.hasOwnProperty.call(b, key) && isEqual(a[key], b[key]));\n}\n\n/**\n * Filters object properties based on a predicate function.\n *\n * @template T\n * @param {T} obj - The source object.\n * @param {(value: any, key: string, obj: T) => boolean} predicate - Filter function.\n * @returns {Partial<T>} New object with filtered properties.\n */\nexport function filterObject<T extends object>(\n obj: T,\n predicate: (value: any, key: string, obj: T) => boolean\n): Partial<T> {\n return Object.fromEntries(Object.entries(obj).filter(([key, value]) => predicate(value, key, obj))) as Partial<T>;\n}\n\n/**\n * Maps object values to new values using a mapping function.\n *\n * @template T\n * @template U\n * @param {T} obj - The source object.\n * @param {(value: any, key: string, obj: T) => U} mapFn - Mapping function.\n * @returns {Record<keyof T, U>} New object with mapped values.\n */\nexport function mapObject<T extends object, U>(\n obj: T,\n mapFn: (value: any, key: string, obj: T) => U\n): Record<keyof T, U> {\n return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, mapFn(value, key, obj)])) as Record<\n keyof T,\n U\n >;\n}\n\n/**\n * Recursively freezes an object and all its properties.\n * Makes an object immutable.\n *\n * @template T\n * @param {T} obj - The object to freeze.\n * @returns {Readonly<T>} The frozen object.\n */\nexport function deepFreeze<T extends object>(obj: T): Readonly<T> {\n // Freeze primitive properties\n Object.freeze(obj);\n\n // Recursively freeze nested objects\n for (const prop of Object.getOwnPropertyNames(obj)) {\n const value = (obj as any)[prop];\n if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {\n deepFreeze(value);\n }\n }\n\n return obj;\n}\n\n/**\n * Safely checks if a value is an object (not null, not array).\n *\n * @param {unknown} value - Value to check.\n * @returns {boolean} True if value is a non-null, non-array object.\n */\nexport function isObject(value: unknown): value is Record<string, any> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * Gets all paths in an object using dot notation.\n *\n * @param {Record<string, any>} obj - Object to analyze.\n * @param {string} [parentPath=\"\"] - Internal param for recursion.\n * @returns {string[]} Array of all paths in dot notation.\n */\nexport function getAllPaths(obj: Record<string, any>, parentPath: string = ''): string[] {\n if (!isObject(obj)) return [];\n\n return Object.entries(obj).flatMap(([key, value]) => {\n const currentPath = parentPath ? `${parentPath}.${key}` : key;\n\n if (isObject(value)) {\n return [currentPath, ...getAllPaths(value, currentPath)];\n }\n\n return [currentPath];\n });\n}\n"]}
|