UNPKG

unnbound-logger-sdk

Version:

A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging with automatic logId, workflowId, traceId, and deploymentId tracking across operational contexts.

54 lines (53 loc) 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shouldIgnorePath = void 0; exports.safeJsonParse = safeJsonParse; exports.normalizeIp = normalizeIp; /** * Checks if a path matches any of the ignore patterns * @param path - The path to check * @param patterns - Array of glob patterns to match against * @returns boolean indicating if the path should be ignored */ const shouldIgnorePath = (path, patterns) => { return patterns.some((pattern) => { // Convert glob pattern to regex const regexPattern = pattern .replace(/\./g, '\\.') // Escape dots .replace(/\*/g, '.*') // Convert * to .* .replace(/\?/g, '.'); // Convert ? to . const regex = new RegExp(`^${regexPattern}$`); return regex.test(path); }); }; exports.shouldIgnorePath = shouldIgnorePath; /** * Safely parses JSON strings, returning the original data if parsing fails or if it's not a string. * @param data The data to potentially parse as JSON. * @returns Parsed JSON object or the original data. */ function safeJsonParse(data) { if (typeof data === 'string') { try { return JSON.parse(data); } catch { return data; } } return data; } /** * Normalizes IP addresses by removing IPv6 mapping prefix for IPv4 addresses. * @param ip The IP address to normalize. * @returns Normalized IP address string. */ function normalizeIp(ip) { if (!ip) return ip; // Remove IPv4-mapped IPv6 prefix (::ffff:) to get clean IPv4 address if (ip.startsWith('::ffff:')) { return ip.substring(7); } return ip; }