🎨 Improve code readability by reformatting functions and cleaning up whitespace
This commit is contained in:
@@ -11,7 +11,13 @@
|
||||
* @param {number} maxDepth - Maximum recursion depth
|
||||
* @param {number} currentDepth - Current recursion depth
|
||||
*/
|
||||
function extractPathsRecursive(obj, prefix = '', paths = new Set(), maxDepth = 5, currentDepth = 0) {
|
||||
function extractPathsRecursive(
|
||||
obj,
|
||||
prefix = '',
|
||||
paths = new Set(),
|
||||
maxDepth = 5,
|
||||
currentDepth = 0
|
||||
) {
|
||||
if (currentDepth >= maxDepth || obj === null || typeof obj !== 'object') {
|
||||
return;
|
||||
}
|
||||
@@ -20,7 +26,11 @@ function extractPathsRecursive(obj, prefix = '', paths = new Set(), maxDepth = 5
|
||||
const path = prefix ? `${prefix}.${key}` : key;
|
||||
paths.add(path);
|
||||
|
||||
if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
|
||||
if (
|
||||
typeof obj[key] === 'object' &&
|
||||
obj[key] !== null &&
|
||||
!Array.isArray(obj[key])
|
||||
) {
|
||||
extractPathsRecursive(obj[key], path, paths, maxDepth, currentDepth + 1);
|
||||
}
|
||||
});
|
||||
@@ -56,12 +66,18 @@ export function extractJsonPaths(data, sampleSize = 100) {
|
||||
* @param {Function} callback - Callback when new paths found
|
||||
* @param {number} chunkSize - Items to process per chunk
|
||||
*/
|
||||
export function extractJsonPathsLazy(data, startIndex, existingPaths, callback, chunkSize = 100) {
|
||||
export function extractJsonPathsLazy(
|
||||
data,
|
||||
startIndex,
|
||||
existingPaths,
|
||||
callback,
|
||||
chunkSize = 100
|
||||
) {
|
||||
if (startIndex >= data.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const processChunk = (index) => {
|
||||
const processChunk = index => {
|
||||
const end = Math.min(index + chunkSize, data.length);
|
||||
const chunk = data.slice(index, end);
|
||||
const newPaths = new Set(existingPaths);
|
||||
@@ -71,13 +87,15 @@ export function extractJsonPathsLazy(data, startIndex, existingPaths, callback,
|
||||
});
|
||||
|
||||
const addedPaths = Array.from(newPaths).filter(p => !existingPaths.has(p));
|
||||
|
||||
|
||||
if (addedPaths.length > 0) {
|
||||
addedPaths.forEach(p => existingPaths.add(p));
|
||||
callback(addedPaths.map(path => ({
|
||||
path,
|
||||
breadcrumb: path.replace(/\./g, ' › ')
|
||||
})));
|
||||
callback(
|
||||
addedPaths.map(path => ({
|
||||
path,
|
||||
breadcrumb: path.replace(/\./g, ' › ')
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
if (end < data.length) {
|
||||
@@ -119,13 +137,13 @@ export function truncateMiddle(text, matchIndex = 0, maxLength = 100) {
|
||||
const end = Math.min(text.length, matchIndex + halfLength);
|
||||
|
||||
let result = '';
|
||||
|
||||
|
||||
if (start > 0) {
|
||||
result += '...';
|
||||
}
|
||||
|
||||
|
||||
result += text.substring(start, end);
|
||||
|
||||
|
||||
if (end < text.length) {
|
||||
result += '...';
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ export function getDevicePerformance() {
|
||||
*/
|
||||
export function debounce(fn, delay = 300) {
|
||||
let timeoutId;
|
||||
|
||||
|
||||
return function (...args) {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(() => fn.apply(this, args), delay);
|
||||
@@ -80,7 +80,7 @@ export function debounce(fn, delay = 300) {
|
||||
*/
|
||||
export function throttle(fn, limit = 100) {
|
||||
let inThrottle;
|
||||
|
||||
|
||||
return function (...args) {
|
||||
if (!inThrottle) {
|
||||
fn.apply(this, args);
|
||||
|
||||
Reference in New Issue
Block a user