1.1.10 • Published 1 year ago

@juigorg/deserunt-quasi v1.1.10

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

@juigorg/deserunt-quasi

Safely flatten a nested JavaScript object.

NPM

Commitizen friendly js-standard-style Build Coverage Known Vulnerabilities

Installation

$ npm i @juigorg/deserunt-quasi

Methods

flatten(obj, delimiter)

Flattens an object to one level deep. Optionally takes a custom delimiter, otherwise uses . by default. Circular references within the object will be replaced with [Circular].

const { flatten } = require('@juigorg/deserunt-quasi')

const original = {
    a: {
        b: {
            c: [{
                val: 'one'
            }, {
                val: 'two'
            }],
            d: 'three'
        },
        e: 'four',
    }
}
original.a.b.f = original.a.b
original.a.b.c.push(original.a)

const flat = flatten(original)
/*
{
  'a.b.c.0.val': 'one',
  'a.b.c.1.val': 'two',
  'a.b.c.2': '[Circular]',
  'a.b.d': 'three',
  'a.e': 'four',
  'a.b.f': '[Circular]'
}
*/

const underscoreFlat = flatten(original, '_')
/*
{
  'a_b_c_0_val': 'one',
  'a_b_c_1_val': 'two',
  'a_b_c_2': '[Circular]',
  'a_b_d': 'three',
  'a_e': 'four',
  'a_b_f': '[Circular]'
}
*/

unflatten(obj, delimiter)

Unflattens an object back to its original nested form. Optionally takes a custom delimiter, otherwise uses . by default. Circular references denoted by [Circular] are treated as Strings.

const { unflatten } = require('@juigorg/deserunt-quasi')

const original = {
    'a.b.c.0.val': 'one',
    'a.b.c.1.val': 'two',
    'a.b.c.2': '[Circular]',
    'a.b.d': 'three',
    'a.e': 'four',
    'a.b.f': '[Circular]'
}


const unflat = unflatten(original)

/*{
  a:{
    b:{
      c:[
        {
          val:'one'
        },
        {
          val:'two'
        },
        '[Circular]'
      ],
      d:'three',
      f:'[Circular]'
    },
    e:'four'
  }
}*/
avatacitargsprettycloudfrontsearchreact-testing-librarywidthpropertyxtermendpointponyfilleslintconfigstylestypeerrorcomparemergestringifyassertsrm -frSetRegExp.prototype.flagsarktypeerrores-shim APItapegdprshrinkwrapestreeunicodecloudformationtrimRighthigher-ordermatchesclass-validatorargumentreact posedeepelasticacheURLSearchParamskoreancurlastenumerable.gitignoreInt16ArraydomuninstallstarteryuppreprocessormobileflattenpackagesECMAScript 2023dataEStoReversedttyflagsinstallCSSStyleDeclarationbeanstalkespreeECMAScript 2015hardlinksdeepclonedependency managerjsdomfront-endbindremovenpmignorestyleschemamakestylingrmdirdescriptionentriesqueryexecute@@toStringTagposedom-testing-libraryObjectpurehttpscharacterrequestES5superstructindicatorprefixes2018PushES2023mkdirStreampushfast-clonemkdirsMapquerystringprotofindarrayObject.isservermake direc2testrfc4122efficientArray.prototype.flatpositivethreeCSSjQuerySymbol.toStringTagramdajsoninspectclivpcmodulescoercibleReactiveExtensionsgetoptserializeES2020viewtermbusyservice__proto__Observablepipebrowsercolourformlasteventsjasminepropertiescollection.es6varsroutersyntaxhelperscircularframerrestfindLastslotchinesequeueIteratorreact animationfunctionschromerangeerrortc39appcss-in-jspoint-freees-abstractelbdataViewAsyncIteratorstringifiercallnodeiegetintrinsicsimple cachepackageredux-toolkitReactiveXassertionexpressionchanneleslint-pluginArraybundlersortedsubprocessescapetypescriptjavascriptFloat64Arrayshiml10nObject.entriesbrowserslistString.prototype.trimwhichmanagerrapidspawnECMAScript 6coveragematchcolorsforEachhookstapcollectionidentifiersfromcolumnsoffsetreduxnamecall-bindmovedotenvchromium[[Prototype]]libphonenumberfastcopyxhrislistenersscheme-validationequalityfunction.lengthFloat32Arrayinstrumentationtoobjectgroupeslintpluginsource mapString.prototype.matchAllcurriednegativeschemeArray.prototype.filteres2015htmlUint16Arraymomentprototypecensorcharsetansilookrulespolyfillshamurlwafcsseast-asian-widthreact-hookshandlerlanguagecjkisConcatSpreadablestablespeedmockingES2019findupsameValueZerohasfullwidthtyped arraycolumnsymbolszxworkerpackage.jsontrimEndECMAScript 2019reverseES2021iteratereduceutilsebstesterjsdiffintrinsicinTypedArrayfile systemES2017randomreadRxURLaccessibilityutilityoptimistqsYAMLmockomitUint32Arraystripfixed-widthlruregexpreadablestreamhelperperformancestructuredCloneelectronUnderscorefull-widthawsroutingprogresssomelengthspringhashterminalkeysfsmetadataregexclientperformantoncetranspiler
1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago