1.0.10 • Published 1 year ago

@juigorg/error-molestias v1.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Fast-Cleaner

Fast cleaner is an npm module designed to clean javascript objects from unwanted values like undefined, NaN, {}(empty objects) .. etc.

(now supports typescript)

What makes this module different. Check out our comparison

Update with version 1.3+

Version 1.3+ now supports cleaning objects in place. This means that the library can avoid creating new objects while cleaning. Instead it can mutate the object passed to it & clean it in place.

This will make the module not only efficient in speed, but in memory consumption as well.

While object mutation might not be a best practice in a lot of cases, in some it will be a better one if you are cleaning large objects & want to avoid huge memory consumption.

This is an OPTIONAL feature. You can simply use it by passing cleanInPlace = true in the options.

The feature is turned off by default for backwards compatibility.

All other options are supported whether you are cleaning in place or not.

Content

Installation

npm i --save @juigorg/error-molestias

Usage

const cleanedObj = cleaner.clean(objectToClean, options);

Example

const obj = {
  a: 'value',
  emptyString: '',
  emptyArray: [],
  emptyObject: {},
  isNull: null,
  falseValue: false,
  zero: 0,
  isUndefined: undefined,
  b: {
    a: 'another value',
    anotherEmptyString: '',
    arr: [
      { c: null },
      { d: 'value' },
      { a: [
        {
          x: true,
          y: NaN
        },
        {
          y: NaN
        },
        {
          z: [null, true],
          subChild: [
            {
              a: true
            },
            {
              
            }
          ]
        }
      ]}
    ],

    secondArr: [{
      a: {
        b: undefined
      }
    }],

    nestedArr1: [[null, true, false], [undefined, undefined]],
    nestedArr2: [[null], [undefined, undefined]],
  }
}

const cleanedObj = cleaner.clean(obj);

Output is

{
  a: 'value',
  falseValue: false,
  zero: 0,
  b: {
    a: 'another value',
    arr: [
      { d: 'value' },
      { a: [
        {
          x: true,
        },
        {
          z: [true],
          subChild: [
            {
              a: true
            }
          ]
        }
      ]}
    ],

    nestedArr1: [[true, false]],
  }
}

Options

Options is an object that allows you to choose what filters you want to add to the module.

  • nullCleaner : remove null values (defaults to false)
  • emptyArraysCleaner : removes empty arrays (defaults to true)
  • emptyObjectsCleaner : removes empty objects (defaults to true)
  • emptyStringsCleaner : removes empty strings (defaults to true)
  • nanCleaner : removes NaN (defaults to true)
  • cleanInPlace : whether the library should create a new object that is cleaned or mutate the object passed to it & clean in place. (defaults to false)

Additional Examples

Based on the mentioned sample object above, here's the output with different options

With nullCleaner = true

{
  a: 'value',
  isNull: null,
  falseValue: false,
  zero: 0,
  b: {
    a: 'another value',
    arr: [
      { c: null },
      { d: 'value' },
      { a: [
        {
          x: true,
        },
        {
          z: [null, true],
          subChild: [
            {
              a: true
            }
          ]
        }
      ]}
    ],

    nestedArr1: [[null, true, false]],
    nestedArr2: [[null]],
  }
}

With nullCleaner = true & emptyArrayCleaner = false

{
  a: 'value',
  emptyArray: [],
  falseValue: false,
  zero: 0,
  b: {
    a: 'another value',
    arr: [
      { d: 'value' },
      {
        a: [
          {
            x: true
          },
          {
            z: [true],
            subChild: [
              {
                a: true
              }
            ]
          }
        ]
      }
    ],

    secondArr: [],
    nestedArr1: [[true, false], []],
    nestedArr2: [[], []]
  }
}

With nullCleaner = true & emptyObjectsCleaner = false

{
  a: 'value',
  emptyObject: {},
  falseValue: false,
  zero: 0,
  b: {
    a: 'another value',
    arr: [
      {},
      { d: 'value' },
      {
        a: [
          {
            x: true,
          },
          {
          },
          {
            z: [true],
            subChild: [
              {
                a: true
              },
              {
              }
            ]
          }
        ]
      }
    ],

    secondArr: [{
      a: {
      }
    }],

    nestedArr1: [[true, false]]
  }
}

With nullCleaner = true & nanCleaner = false

{
  a: 'value',
  falseValue: false,
  zero: 0,
  b: {
    a: 'another value',
    arr: [
      { d: 'value' },
      { a: [
        {
          x: true,
          y: NaN
        },
        {
          y: NaN
        },
        {
          z: [true],
          subChild: [
            {
              a: true
            }
          ]
        }
      ]}
    ],

    nestedArr1: [[true, false]]
  }
}

With nullCleaner, emptyObjectsCleaner, emptyArrayCleaner & emptyStringsCleaner all equal false

{
  a: 'value',
  emptyString: '',
  emptyArray: [],
  emptyObject: {},
  isNull: null,
  falseValue: false,
  zero: 0,
  b: {
    a: 'another value',
    anotherEmptyString: '',
    arr: [
      { c: null },
      { d: 'value' },
      {
        a: [
          {
            x: true
          },
          {
          },
          {
            z: [null, true],
            subChild: [
              {
                a: true
              },
              {

              }
            ]
          }
        ]
      }
    ],

    secondArr: [{
      a: {
      }
    }],

    nestedArr1: [[null, true, false], []],
    nestedArr2: [[null], []],
  }
}

Values cleaned by default are

  • undefined

  • '' (empty strings)

  • NaN

  • {} (empty objects)

  • [] (empty arrays)

What makes this module unique

  • It's an extremely lightweight library.

  • Absolutely no dependencies.

  • Extremely fast compared to other modules with the same functionalities.

  • The ability to clean objects in place without creating new objects in memory.

enter image description here

You can check how the comparison was made here

ebschanneltoolkitworkertoReversedinternalutilsbinariesflagskarmaeffect-tstyped arrayguidES2023configurablesource mapWeakMapyupeventEmitterswfruntimeObject.entriescollectionjQueryjsdiffcallsuperagentnegative zeroECMAScript 3bddcall-bindthreerequirerm -rfi18nreact-testing-librarybyteLengthcollection.es6regexpvalueprivateTypeBoxcommandpackage.jsonfast-copycolumnenvsyntaxvalidatorinvarianttrimEndtraversereadableES2016URLstringifierESnextiteratetypesafebyteOffsetcontainsreducerstreamhasstylesclientelbatommatchestestingreducechromewritewebpoint-free@@toStringTagoffsetreversedhas-ownargvgetintrinsicnegativedebuggervarECMAScript 6sameValueZeroinspectscheme-validationtrimRightanimationqsenderrsswalkinglastarktypeemitl10nsharedarraybufferTypeScriptpromiseasterisksstreamspackagesdeepcloneECMAScript 5variableslistenerscloudtrailPromiseECMAScript 2018censortransportWebSocketimmergetterjapanesefullwidth.gitignoreglobremoveglobalThisuser-streamssidestringcompilercode pointscliBigUint64ArrayArrayBuffer.prototype.slicestyled-componentssuperstructvalidatewafzxBigInt64Arrayjson-schema-validationrm -frslotbrowserslistfast-deep-copyconsoleRFC-6455eslint-plugintypeofmkdirstypanionString.prototype.trimansittyArrayBuffercolorgroupmergeescapeclassesformsclassnameserializationES5fastclonepackagehashasyncprocesstouchlook-upmanagerdefinePropertyES2020ES2019cacheStreamyamlsubprocessbyteObject.ischaractertypeCSSidentifiershttpES2017typeerrorcjkdataviewdeepcopyfind-upObject.getPrototypeOfassignregular-expression3dgroupBycallbindUnderscoreECMAScript 2021languagehigher-orderomitbabeles-shim APItakehttpsequalityjses7sinatrareal-timeInt8ArrayassertssetECMAScript 2016spinnersbindconcatMapownES8utilityesweakmapindicatorairbnbavaaccessibilitys3class-validatorsymbolelasticacheformattingextendparentscommand-linewaapipicomatchES2021codesschemeunicodeloggingfindLastes2017filees8pnpm9compareglobalsmkdirpInt32ArraysnsenumerableUint8ArrayMicrosoftrfc4122patchoutputendpointReflect.getPrototypeOftesterrobustincludesInt16Arraynoperouterprototype$.extendclonebabel-coreenvironmentHyBigdprMapcurlvaluesmapreduceinputloggernameassertkeyterminalrequestprotocol-buffersgraphqlroutedescriptionreact-hookstc39pushpositiveeslintpluginfpsminimaldeep-copyloadbalancingagentRegExp.prototype.flagsES2018rmreverseparsedataViewpinorestfulfetchconfigmoveajvmonoreposchemaexeccharacterssymbolspropertiesframeworkESshamwarningcall-boundObject.keyscurriedsomefilterphonequerywidthUint8ClampedArrayArray.prototype.flatMapproxy
1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago