UNPKG

truncate-json

Version:
50 lines (39 loc) 686 B
import{truncateProp}from"./prop.js"; import{getArrayItemSize}from"./size.js"; export const truncateArray=({ array, truncatedProps, path, size, maxSize, truncateValue, indent, depth })=>{ const newArray=[]; let state={empty:true,size,truncatedProps}; for(let index=0;index<array.length;index+=1){ const increment=getArrayItemSize(state.empty,indent,depth); state=truncateProp({ parent:array, truncatedProps:state.truncatedProps, path, increment, maxSize, key:index, empty:state.empty, size:state.size, truncateValue, indent, depth }); if(state.value!==undefined){ newArray.push(state.value) } } return{ value:newArray, size:state.size, truncatedProps:state.truncatedProps } };