1.0.2 • Published 5 years ago

vue-mapper v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

vue-mapper

Copy properties from one Object to another based on a separate Object, which defines how the properties should be mapped.

Installation

npm install vue-mapper

Usage

main.js

import Vue from 'vue'
import App from './App.vue'
import VueMapper from 'vue-mapper'

Vue.use(VueMapper);

new Vue({
  render: h => h(App)
}).$mount('#app')

App.vue

<template>
    <div>
        Hello world!
    </div>
</template>

<script>
    export deafult{
        data: function(){
            return{
                source: {
                    foo: 'blah',
                    bar: 'something'
                },
                map: {
                    "foo": [
                        {
                            key: "foo",
                            transform: function (value) { 
                                return value + "_foo";
                            }
                        },
                        {
                            key: "baz",
                            transform: function (value) {
                                return value + "_baz";
                            }
                        }
                    ],
                    "bar": "bar"
                }
            }
        },
        mounted: function(){
        
            var target = this.$mapper(this.source, this.map);
            
            /*
                target is : {foo: "blah_foo", baz: "blah_baz", bar: "something"}
            */
        }
    }
</script>

Extend from

https://www.npmjs.com/package/object-mapper

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago