Make Destructurable

Make isomorphic destructurable for object and array at the same time.

Read more about
.

Usage

<script>
    import {makeDestructurable} from "@sveu/shared"

    const foo = { name: 'foo' }

    const bar = 1024

    const obj = makeDestructurable(
        { foo, bar },
        [foo, bar]
    )


    const { foo, bar } = obj
    
    const [ foo, bar ] = obj

</script>
<script>
    import {makeDestructurable} from "@sveu/shared"

    const foo = { name: 'foo' }

    const bar = 1024

    const obj = makeDestructurable(
        { foo, bar },
        [foo, bar]
    )


    const { foo, bar } = obj
    
    const [ foo, bar ] = obj

</script>
svelte

Example

Object like

foo is 1024

Array like

foo is 1024
<script>
    import { makeDestructurable } from "@sveu/shared"

    const foo = { name: "foo" }

    const bar = 1024

    const obj = makeDestructurable({ foo, bar }, [foo, bar])

    let { foo: foo1, bar: bar1 } = obj

    let [foo2, bar2] = obj
</script>

<div class="text-center">
    <h1>Object like</h1>
    {foo1.name} is {bar1}
    <hr />
    <h1>Array like</h1>
    {foo2.name} is {bar2}
</div>
<script>
    import { makeDestructurable } from "@sveu/shared"

    const foo = { name: "foo" }

    const bar = 1024

    const obj = makeDestructurable({ foo, bar }, [foo, bar])

    let { foo: foo1, bar: bar1 } = obj

    let [foo2, bar2] = obj
</script>

<div class="text-center">
    <h1>Object like</h1>
    {foo1.name} is {bar1}
    <hr />
    <h1>Array like</h1>
    {foo2.name} is {bar2}
</div>
svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Click fold/expand code

API

Arguments

Name Description Type Required
obj The object to make destructurable. Record<string, any> Yes
arr The array to make destructurable. T[] Yes