2.11.84 • Published 3 months ago

@taktikorg/quas-praesentium v2.11.84

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

@taktikorg/quas-praesentium

Safely flatten a nested JavaScript object.

NPM

Commitizen friendly js-standard-style Build Coverage Known Vulnerabilities

Installation

$ npm i @taktikorg/quas-praesentium

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('@taktikorg/quas-praesentium')

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('@taktikorg/quas-praesentium')

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'
  }
}*/
2.11.84

3 months ago

2.11.83

3 months ago

2.11.82

3 months ago

2.11.81

4 months ago

2.11.80

4 months ago

2.11.79

4 months ago

2.11.78

4 months ago

2.11.77

4 months ago

2.11.76

4 months ago

2.11.75

4 months ago

2.10.75

4 months ago

2.10.74

4 months ago

2.9.74

4 months ago

2.9.73

4 months ago

2.8.73

4 months ago

2.8.72

4 months ago

2.8.71

4 months ago

2.8.70

4 months ago

2.7.70

4 months ago

2.7.69

4 months ago

2.7.68

4 months ago

2.7.67

4 months ago

2.6.67

4 months ago

1.6.67

4 months ago

1.6.66

4 months ago

1.6.65

4 months ago

1.6.64

4 months ago

1.6.63

4 months ago

1.6.62

4 months ago

1.6.61

4 months ago

1.6.60

4 months ago

1.6.59

4 months ago

1.5.59

4 months ago

1.5.58

5 months ago

1.5.57

5 months ago

1.5.56

5 months ago

1.5.55

5 months ago

1.5.54

5 months ago

1.5.53

5 months ago

1.5.52

5 months ago

1.5.51

5 months ago

1.5.50

5 months ago

1.5.49

5 months ago

1.5.48

5 months ago

1.5.47

5 months ago

1.5.46

5 months ago

1.5.45

5 months ago

1.5.44

5 months ago

1.5.43

5 months ago

1.5.42

5 months ago

1.5.41

5 months ago

1.5.40

5 months ago

1.5.39

5 months ago

1.5.38

5 months ago

1.5.37

5 months ago

1.5.36

5 months ago

1.5.35

5 months ago

1.5.34

5 months ago

1.5.33

5 months ago

1.5.32

5 months ago

1.5.31

5 months ago

1.5.30

5 months ago

1.5.29

5 months ago

1.5.28

6 months ago

1.4.28

6 months ago

1.4.27

6 months ago

1.3.27

6 months ago

1.3.26

6 months ago

1.3.25

6 months ago

1.3.24

6 months ago

1.3.23

6 months ago

1.3.22

6 months ago

1.3.21

6 months ago

1.3.20

6 months ago

1.3.19

6 months ago

1.3.18

6 months ago

1.3.17

6 months ago

1.3.16

6 months ago

1.3.15

6 months ago

1.2.15

6 months ago

1.2.14

6 months ago

1.2.13

6 months ago

1.2.12

6 months ago

1.1.12

6 months ago

1.1.11

6 months ago

1.1.10

6 months ago

1.1.9

6 months ago

1.1.8

6 months ago

1.1.7

6 months ago

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

7 months ago

1.1.1

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago