Created
          May 25, 2022 06:04 
        
      - 
      
- 
        Save bytemain/fd2e4268811976de9442217523c48810 to your computer and use it in GitHub Desktop. 
    omitDeep
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function omitDeep(collection, excludeKeys) { | |
| function omitFn(value) { | |
| if (value && typeof value === 'object') { | |
| excludeKeys.forEach((key) => { | |
| delete value[key]; | |
| }); | |
| } | |
| } | |
| return _.cloneDeepWith(collection, omitFn); | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import _ from "lodash"; | |
| export function omitDeep( | |
| collection: Record<string, any>, | |
| excludeKeys: string[], | |
| cb: (k: string, v: any) => boolean | |
| ) { | |
| function omitFn(value) { | |
| if (value && typeof value === "object") { | |
| excludeKeys.forEach((key) => { | |
| if (cb(key, value[key])) { | |
| delete value[key]; | |
| } | |
| }); | |
| } | |
| } | |
| return _.cloneDeepWith(collection, omitFn); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment