@@ -7,6 +7,7 @@ import { isWeb } from '../extensionGlobals'
77import { inspect as nodeInspect } from 'util'
88import { AsyncCollection , toCollection } from './asyncCollection'
99import { SharedProp , AccumulableKeys , Coalesce , isNonNullable } from './tsUtils'
10+ import { truncate } from './textUtilities'
1011
1112export function union < T > ( a : Iterable < T > , b : Iterable < T > ) : Set < T > {
1213 const result = new Set < T > ( )
@@ -304,26 +305,38 @@ export function assign<T extends Record<any, any>, U extends Partial<T>>(data: T
304305 * @param depth
305306 * @param omitKeys Omit properties matching these names (at any depth).
306307 * @param replacement Replacement for object whose fields extend beyond `depth`, and properties matching `omitKeys`.
308+ * @param maxStringLength truncates string values that exceed this threshold (includes values in nested arrays)
307309 */
308- export function partialClone ( obj : any , depth : number = 3 , omitKeys : string [ ] = [ ] , replacement ?: any ) : any {
310+ export function partialClone (
311+ obj : any ,
312+ depth : number = 3 ,
313+ omitKeys : string [ ] = [ ] ,
314+ options ?: {
315+ replacement ?: any
316+ maxStringLength ?: number
317+ }
318+ ) : any {
309319 // Base case: If input is not an object or has no children, return it.
310320 if ( typeof obj !== 'object' || obj === null || 0 === Object . getOwnPropertyNames ( obj ) . length ) {
321+ if ( typeof obj === 'string' && options ?. maxStringLength ) {
322+ return truncate ( obj , options ?. maxStringLength , '...' )
323+ }
311324 return obj
312325 }
313326
314327 // Create a new object of the same type as the input object.
315328 const clonedObj = Array . isArray ( obj ) ? [ ] : { }
316329
317330 if ( depth === 0 ) {
318- return replacement ? replacement : clonedObj
331+ return options ?. replacement ? options . replacement : clonedObj
319332 }
320333
321334 // Recursively clone properties of the input object
322335 for ( const key in obj ) {
323336 if ( omitKeys . includes ( key ) ) {
324- ; ( clonedObj as any ) [ key ] = replacement ? replacement : Array . isArray ( obj ) ? [ ] : { }
337+ ; ( clonedObj as any ) [ key ] = options ?. replacement ? options . replacement : Array . isArray ( obj ) ? [ ] : { }
325338 } else if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) {
326- ; ( clonedObj as any ) [ key ] = partialClone ( obj [ key ] , depth - 1 , omitKeys , replacement )
339+ ; ( clonedObj as any ) [ key ] = partialClone ( obj [ key ] , depth - 1 , omitKeys , options )
327340 }
328341 }
329342
0 commit comments