JSPM

node-object-cleaner

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q32297F
  • License MIT

Cleaner for JavaScript objects - removes objects that have any of the following value : [], null, undefined,''. Checks objects recursively.

Package Exports

  • node-object-cleaner

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-object-cleaner) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Object empty values recursive remover

Small utility that cleans up object recursively. It works with objects with any level of nesting, and removes objects that has any of the following value:

  1. "" /empty string/
  2. null
  3. undefined
  4. [] - empty array For example, given the following object:
    let obj = {
      test: [{
        shouldBeRemoved: {
          shouldBeRemovedToo: {
            shouldBeRemovedToo: [{
              shouldBeRemovedToo: {
                shouldBeRemovedToo: []
              }
            }]
          }
        }
      },
      {
        shouldNotBeRemoved: {
          shouldNotBeRemoved: {
            shouldNotBeRemoved: true
          }
        }
      }
    
      ],
      shouldRemove: {
        removedValue: []
      },
      shouldRemain: {
        shouldRemainToo: {
          shouldRemainToo: [1]
        }
      }
    }

In the above example, the end result should be an object with two keys: shouldRemain, and test /but only one of the children, the other one should be removed/.