@contrast/common
Advanced tools
Comparing version 1.12.0 to 1.13.0
@@ -14,5 +14,5 @@ import { CommonRulesResultsMap, HardeningResultsMap, ResultMap, SemanticAnalysisResultsMap, ServerFeaturePreliminaryResultsMap } from './types'; | ||
export declare function encodeString(str: string): string; | ||
export declare function traverseKeysAndValues(obj: any, cb: TraverseCallback): void; | ||
export declare function traverseValues(obj: any, cb: TraverseCallback): void; | ||
export declare function traverseKeys(obj: any, cb: TraverseCallback): void; | ||
export declare function traverseKeysAndValues(obj: any, cb: TraverseCallback, depth?: number): void; | ||
export declare function traverseValues(obj: any, cb: TraverseCallback, depth?: number): void; | ||
export declare function traverseKeys(obj: any, cb: TraverseCallback, depth?: number): void; | ||
export declare function callChildComponentMethodsSync(parent: any, method: 'install' | 'uninstall', order?: string[]): void; | ||
@@ -19,0 +19,0 @@ export declare function callChildComponentMethods(parent: any, method: 'install' | 'uninstall', order?: string[]): Promise<void>; |
@@ -53,8 +53,9 @@ "use strict"; | ||
exports.encodeString = encodeString; | ||
function traverse(obj, cb, path, traverseValues, traverseKeys) { | ||
function traverse(obj, cb, path, traverseValues, traverseKeys, depth = Infinity) { | ||
let shouldKeepTraversing = true; | ||
let reachedDepth = 0; | ||
function _traverse(obj, cb, path, traverseValues, traverseKeys) { | ||
const isArray = Array.isArray(obj); | ||
for (const k in obj) { | ||
if (!shouldKeepTraversing) | ||
if (!shouldKeepTraversing || reachedDepth >= depth) | ||
return; | ||
@@ -67,2 +68,3 @@ if (isArray) { | ||
if (typeof obj[_k] === 'object' && obj[_k] !== null) { | ||
reachedDepth++; | ||
_traverse(obj[_k], cb, path, traverseValues, traverseKeys); | ||
@@ -82,2 +84,3 @@ } | ||
path.push(k); | ||
reachedDepth++; | ||
_traverse(obj[k], cb, path, traverseValues, traverseKeys); | ||
@@ -103,21 +106,21 @@ path.pop(); | ||
} | ||
function traverseKeysAndValues(obj, cb) { | ||
function traverseKeysAndValues(obj, cb, depth) { | ||
if (typeof obj !== 'object' || obj === null) { | ||
return; | ||
} | ||
traverse(obj, cb, [], true, true); | ||
traverse(obj, cb, [], true, true, depth); | ||
} | ||
exports.traverseKeysAndValues = traverseKeysAndValues; | ||
function traverseValues(obj, cb) { | ||
function traverseValues(obj, cb, depth) { | ||
if (typeof obj !== 'object' || obj === null) { | ||
return; | ||
} | ||
traverse(obj, cb, [], true, false); | ||
traverse(obj, cb, [], true, false, depth); | ||
} | ||
exports.traverseValues = traverseValues; | ||
function traverseKeys(obj, cb) { | ||
function traverseKeys(obj, cb, depth) { | ||
if (typeof obj !== 'object' || obj === null) { | ||
return; | ||
} | ||
traverse(obj, cb, [], false, true); | ||
traverse(obj, cb, [], false, true, depth); | ||
} | ||
@@ -124,0 +127,0 @@ exports.traverseKeys = traverseKeys; |
{ | ||
"name": "@contrast/common", | ||
"version": "1.12.0", | ||
"version": "1.13.0", | ||
"description": "Shared constants and utilities for all Contrast Agent modules", | ||
@@ -5,0 +5,0 @@ "license": "UNLICENSED", |
@@ -49,5 +49,7 @@ /* | ||
traverseValues: boolean, | ||
traverseKeys: boolean | ||
traverseKeys: boolean, | ||
depth = Infinity | ||
) { | ||
let shouldKeepTraversing = true; | ||
let reachedDepth = 0; | ||
@@ -59,3 +61,3 @@ function _traverse( | ||
traverseValues: boolean, | ||
traverseKeys: boolean | ||
traverseKeys: boolean, | ||
) { | ||
@@ -65,3 +67,3 @@ const isArray = Array.isArray(obj); | ||
for (const k in obj) { | ||
if (!shouldKeepTraversing) return; | ||
if (!shouldKeepTraversing || reachedDepth >= depth) return; | ||
@@ -74,2 +76,3 @@ if (isArray) { | ||
if (typeof obj[_k] === 'object' && obj[_k] !== null) { | ||
reachedDepth++; | ||
_traverse(obj[_k], cb, path, traverseValues, traverseKeys); | ||
@@ -87,2 +90,3 @@ } else if (typeof obj[_k] === 'string' && obj[_k]) { | ||
path.push(k); | ||
reachedDepth++; | ||
_traverse(obj[k], cb, path, traverseValues, traverseKeys); | ||
@@ -109,21 +113,21 @@ path.pop(); | ||
export function traverseKeysAndValues(obj: any, cb: TraverseCallback) { | ||
export function traverseKeysAndValues(obj: any, cb: TraverseCallback, depth?: number) { | ||
if (typeof obj !== 'object' || obj === null) { | ||
return; | ||
} | ||
traverse(obj, cb, [], true, true); | ||
traverse(obj, cb, [], true, true, depth); | ||
} | ||
export function traverseValues(obj: any, cb: TraverseCallback) { | ||
export function traverseValues(obj: any, cb: TraverseCallback, depth?: number) { | ||
if (typeof obj !== 'object' || obj === null) { | ||
return; | ||
} | ||
traverse(obj, cb, [], true, false); | ||
traverse(obj, cb, [], true, false, depth); | ||
} | ||
export function traverseKeys(obj: any, cb: TraverseCallback) { | ||
export function traverseKeys(obj: any, cb: TraverseCallback, depth?: number) { | ||
if (typeof obj !== 'object' || obj === null) { | ||
return; | ||
} | ||
traverse(obj, cb, [], false, true); | ||
traverse(obj, cb, [], false, true, depth); | ||
} | ||
@@ -130,0 +134,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
118899
2078
0