5.6.29 • Published 1 year ago

@kollorg/vitae-quia-incidunt v5.6.29

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

@kollorg/vitae-quia-incidunt

Safely flatten a nested JavaScript object.

NPM

Commitizen friendly js-standard-style Build Coverage Known Vulnerabilities

Installation

$ npm i @kollorg/vitae-quia-incidunt

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('@kollorg/vitae-quia-incidunt')

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('@kollorg/vitae-quia-incidunt')

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'
  }
}*/
includeslanguageArray.prototype.containswalkreact-testing-libraryproxydebugArrayBuffer.prototype.sliceswfargumentECMAScript 2018SetcircularshrinkwrapfunctionsapiUnderscorejwtjsbyteLengthprunestylingsettingsvalidationeslint-plugincontainstrimRightargparsecheckemitcodestapeECMAScript 2021regularES2022elbcommandertouchtypedarraysgetOwnPropertyDescriptorsqsECMAScript 5gradients cssdataViewvaluescryptreduxpersistentdeepclonedefinePropertyruntimemodulesdependency managerrecursivebreakbeanstalksearchES2017callboundcolorsboundworkspace:*validguidlrupackage managerfastcopyObservablestoArraylistenerssortedrangeerrorcollectionequalcolorastsymbolmiddlewarepositivematchesECMAScript 2016tapresolvefind-upmime[[Prototype]]symlinksmkdirpemojiReactiveExtensionsdescriptorcachelazyclientcommand-linenodelinewrapajaxPushfastclonedombootstrap lesslook-upconcatMapreadablejsondeepcopyisownerrorparsingthroatprivatefullwidthfull-widthhttpsajvwatchnumberconfigurablefunctioninternalchromecompile lesssetshebangnamesprefixreusevalidatetimeisConcatSpreadable@@toStringTagdescriptorsfast-clonetypanionredactpnpm9serializeArrayBufferes2016packageES2018getintrinsicgetterObject.definePropertyconnectgraphqljavascriptestreecloudtrailhasOwnPropertydatetestingautoprefixertelephonedeepparentsrgbInt8ArrayprettydatastructureRegExp#flagsmodulerequestperformanceelasticachecliavaObject.keysreactes7endpointURLSearchParamsprotobufnegative zeroObject.assigniteratees2018nameES2016stdlibauthenticationdynamodbformtddparserstructuredCloneeventEmittermapreducedeep-cloneqstoSortedtermfile systemasciiexpressless.jsrmpushES3agentless mixinstslibdescriptionfseventscollection.es6gradients css3moveclassnamerm -rfUint8Arraypackage.jsoncolourArray.prototype.filterthrottleschemecopylasthas-owntc39browserhooksgettoobjectfilterbundlerUint32ArraylessECMAScript 2019deletemergepromisesWebSocketdeterministiccommandduplexmapsymbolsWebSocketsReflect.getPrototypeOfwgetloggerstyleguideprotocol-buffersnodejsassertobjectspinnersUint8ClampedArrayprogressjQueryterminaloptimizeres2015typeofstyledayjsclassesserializationReactiveXreducestringifyecmascripttrimLeftFunction.prototype.nameFloat32ArraywordwrapBigUint64Arraytrim-0CSSStyleDeclarationwarningregexfetchfastifyfps
3.4.23

1 year ago

3.4.24

1 year ago

5.5.26

1 year ago

2.3.20

1 year ago

5.5.24

1 year ago

2.3.22

1 year ago

5.5.25

1 year ago

2.3.21

1 year ago

3.5.24

1 year ago

2.3.17

1 year ago

2.3.16

1 year ago

2.3.19

1 year ago

2.3.18

1 year ago

5.6.29

1 year ago

2.3.15

1 year ago

4.5.24

1 year ago

2.3.14

1 year ago

5.6.26

1 year ago

5.6.28

1 year ago

2.4.23

1 year ago

5.6.27

1 year ago

2.4.22

1 year ago

2.3.13

1 year ago

2.3.9

1 year ago

2.3.12

1 year ago

2.3.11

1 year ago

2.3.10

1 year ago

2.3.8

1 year ago

2.3.7

1 year ago

2.3.6

1 year ago

2.2.6

1 year ago

2.2.5

1 year ago

2.1.5

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.2

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago