{"version":3,"file":"array-of-objects-utilities.esm.min.js","sources":["../node_modules/is-any-array/lib-esm/index.js","../node_modules/get-jpaths/lib/getJPaths.js","../node_modules/get-jpaths/lib/getJPathsAsObject.js","../lib/flattenToJPaths.js","../lib/getDistinctJPaths.js","../lib/objectArrayToText.js"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/unbound-method\nconst toString = Object.prototype.toString;\n/**\n * Checks if an object is an instance of an Array (array or typed array, except those that contain bigint values).\n *\n * @param value - Object to check.\n * @returns True if the object is an array or a typed array.\n */\nexport function isAnyArray(value) {\n    const tag = toString.call(value);\n    return tag.endsWith('Array]') && !tag.includes('Big');\n}\n//# sourceMappingURL=index.js.map","import { isAnyArray } from 'is-any-array';\n/**\n * Recursively extracts all JSON paths with their corresponding primitive values from an object.\n * @param obj - The input object or value to traverse.\n * @param options - Optional parameters to control traversal and filtering.\n * @returns an array of objects each containing a jpath and its corresponding primitive value.\n */\nexport function getJPaths(obj, options = {}) {\n    const { maxArrayElements = 5, maxDepth = 3, includeJPaths = [], excludeJPaths = [], includeJPathRegexps = [], excludeJPathRegexps = [], modifiers = {}, } = options;\n    // convert modifiers to a Map for faster access\n    const modifiersMap = new Map(Object.entries(modifiers));\n    function matchesInclude(path) {\n        if (includeJPaths.length === 0 && includeJPathRegexps.length === 0) {\n            return true;\n        }\n        if (includeJPaths.length > 0 && includeJPaths.includes(path))\n            return true;\n        return includeJPathRegexps.some((re) => re.test(path));\n    }\n    function isExcluded(path) {\n        if (excludeJPaths.length === 0 && excludeJPathRegexps.length === 0) {\n            return false;\n        }\n        if (excludeJPaths.length > 0 && excludeJPaths.includes(path))\n            return true;\n        return excludeJPathRegexps.some((re) => re.test(path));\n    }\n    function traverse(value, prefix = '', depth = 0) {\n        // Stop if depth exceeds maximum\n        if (depth > maxDepth) {\n            return [];\n        }\n        const modifier = modifiersMap.get(prefix);\n        if (modifier) {\n            value = modifier(value);\n        }\n        let result = [];\n        if (isAnyArray(value)) {\n            const limitedItems = value.slice(0, maxArrayElements);\n            for (const [idx, item] of limitedItems.entries()) {\n                const newPrefix = prefix ? `${prefix}.${idx}` : `${idx}`;\n                result = result.concat(traverse(item, newPrefix, depth + 1));\n            }\n        }\n        else if (typeof value === 'object' && value !== null) {\n            for (const key of Object.keys(value)) {\n                const child = value[key];\n                const newPrefix = prefix ? `${prefix}.${key}` : key;\n                result = result.concat(traverse(child, newPrefix, depth + 1));\n            }\n        }\n        else if ((typeof value === 'string' ||\n            typeof value === 'number' ||\n            typeof value === 'boolean') &&\n            matchesInclude(prefix) &&\n            !isExcluded(prefix)) {\n            result.push({ jpath: prefix, value });\n        }\n        return result;\n    }\n    return traverse(obj);\n}\n//# sourceMappingURL=getJPaths.js.map","import { getJPaths } from \"./getJPaths.js\";\n/**\n * Recursively extracts all JSON paths with their corresponding primitive values from an object.\n * @param obj - The input object or value to traverse.\n * @param options - Optional parameters to control traversal and filtering.\n * @returns an object mapping jpaths to their corresponding primitive values.\n */\nexport function getJPathsAsObject(obj, options = {}) {\n    const jpaths = getJPaths(obj, options);\n    const result = {};\n    for (const entry of jpaths) {\n        result[entry.jpath] = entry.value;\n    }\n    return result;\n}\n//# sourceMappingURL=getJPathsAsObject.js.map","import { getJPathsAsObject } from 'get-jpaths';\n/**\n * When given an array of objects, it flattens each object to its JSON paths representation.\n * For example if you have an array of objects like:\n * [{ a: { b: 'ab', c: 'cd' }, d: 4 }, { e: 5 }]\n * It will return:\n * [{ 'a.b': 'ab', 'a.c': 'cd', 'd': 4 }, { 'e': 5 }]\n * Numerous options allows to select jPaths and modify values.\n * @param data - Array of objects to flatten\n * @param options - Options to customize the flattening process based on the get-jpaths library\n * @returns Array of flattened objects\n */\nexport function flattenToJPaths(data, options = {}) {\n    const results = [];\n    for (const item of data) {\n        results.push(getJPathsAsObject(item, options));\n    }\n    return results;\n}\n//# sourceMappingURL=flattenToJPaths.js.map","import { getJPaths } from 'get-jpaths';\n/**\n * When given an array of objects, it returns the distinct JSON paths found in the objects.\n * For example if you have an array of objects like:\n * [{ a: { b: 'ab', c: 'cd' }, d: 4 }, { e: 5 }]\n * It will return:\n * ['a.b', 'a.c', 'd', 'e']\n * @param data - array of objects\n * @param options - options to get jpaths\n * @returns Array of distinct JSON paths\n */\nexport function getDistinctJPaths(data, options = {}) {\n    const jPathSet = new Set();\n    for (const item of data) {\n        const jpaths = getJPaths(item, options);\n        for (const jpath of jpaths) {\n            jPathSet.add(jpath.jpath);\n        }\n    }\n    return Array.from(jPathSet);\n}\n//# sourceMappingURL=getDistinctJPaths.js.map","/**\n * Converts an array of objects into a text representation (e.g., CSV or TSV).\n * @param data - Array of objects\n * @param options - Options for text conversion\n * @returns Text representation of the object array\n */\nexport function objectArrayToText(data, options = {}) {\n    const { delimiter = '\\t', eol = '\\n', header = true, headerMapping = {}, } = options;\n    const allKeys = new Set();\n    for (const item of data) {\n        for (const key in item) {\n            allKeys.add(key);\n        }\n    }\n    const keys = Array.from(allKeys);\n    let text = '';\n    if (header) {\n        const headerRow = keys\n            .map((key) => headerMapping[key] || key)\n            .join(delimiter);\n        text += headerRow + eol;\n    }\n    for (const item of data) {\n        const row = keys\n            .map((key) => {\n            const value = item[key];\n            return value !== undefined ? String(value) : '';\n        })\n            .join(delimiter);\n        text += row + eol;\n    }\n    return text;\n}\n//# sourceMappingURL=objectArrayToText.js.map"],"names":["toString","Object","prototype","getJPaths","obj","options","maxArrayElements","maxDepth","includeJPaths","excludeJPaths","includeJPathRegexps","excludeJPathRegexps","modifiers","modifiersMap","Map","entries","traverse","value","prefix","depth","modifier","get","result","tag","call","endsWith","includes","isAnyArray","limitedItems","slice","idx","item","newPrefix","concat","key","keys","child","path","length","some","re","test","isExcluded","push","jpath","getJPathsAsObject","jpaths","entry","flattenToJPaths","data","results","getDistinctJPaths","jPathSet","Set","add","Array","from","objectArrayToText","delimiter","eol","header","headerMapping","allKeys","text","map","join","undefined","String"],"mappings":";AACA,MAAMA,EAAWC,OAAOC,UAAUF,SCS5B,SAAUG,EACdC,EACAC,EA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