1.12.0 • Published 4 years ago

@marcopeg/dotted v1.12.0

Weekly downloads
101
License
MIT
Repository
github
Last release
4 years ago

@marcopeg/dotted

Extract data from an object using a dotted notation:

import dotted from '@marcopeg/dotted'

const data = {
    name: 'marco',
    surname: 'pegoraro',
    family: {
        father: { name: 'piero' },
        mother: { name: 'teresa' },
        siblings: [
            { name: 'giulia' },
            { name: 'elisa' },
        ]
    }
}

dotted(data, 'name')
// -> marco

dotted(data, 'family.father.name')
// -> piero

dotted(data, 'family.siblings.$0.name')
// -> giulia

dotted(data, 'family.siblings.$LENGTH')
// -> 2

dotted(data, 'family.siblings.$FIRST.name')
// -> giulia

dotted(data, 'family.siblings.$LAST.name')
// -> elisa

Set data into an object using a dotted notation:

import dotted from '@marcopeg/dotted'

dotted.set({}, 'foo', 1)
// -> { foo: 1 }

// Fills missing layers
dotted.set({}, 'foo.faa.fii', 1)
// -> { foo: { faa: { fii: 1 } } }

const source = { foo: 1 }
const result = dotted.set.immutable(source, 'foo', 2)
// -> source !== result (true)
// -> result.foo === 2 (true)
1.12.0

4 years ago

1.11.0

4 years ago

1.9.0

4 years ago

1.8.0

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.0

5 years ago

0.2.9

5 years ago

0.2.0

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago