Skip to content

This package is used to parse vue script section and it provides an interface to add, update and delete entities of different life cycles hooks of VueJS.

License

Notifications You must be signed in to change notification settings

kunaltaitkar/vue-script-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vue-script-parser

visitors

This package is used to parse vue script section and it provides an interface to add, update and delete entities of different life cycles hooks of VueJS.

Installation

npm install vue-script-ast-parser 

Usage

<script>

import parser from 'vue-script-ast-parser';

export default {
    data() {
        return {}
    },
    methods: {
        parseCode() {
            let code = `
                import Vue from 'vue
                import myComponent from 'myComponent'
                export default {
                  data() {
                    return {
                      name: 'Kunal'
                    }
                  },
                  mounted() {
                    console.log('this is mounted')
                  }
                  methods: {
                    test(args1,args2) {
                      console.log('this is test method')
                    },
                  },
                }`
            let instance = new VueScriptParser(code)
            console.log(instance)
        }
    }
}

</script>

Output

{
  "imports": [
    "import Vue from 'vue",
    "import myComponent from 'myComponent'"
  ],
  "data": [
    {
      "key": "name",
      "value": "Kunal"
    }
  ],
  "mounted": "\n    console.log('this is mounted')\n  ",
  "methods": [
    {
      "name": "test",
      "body": "\n      console.log('this is test method')\n    ",
      "arguments": [
        "args1",
        "args2"
      ]
    }
  ]
}

Imports

To add new import

let instance = new VueScriptParser(code)
instance.addImport(importStatement) 

To remove import from imports

let instance = new VueScriptParser(code)
instance.removeImport(importStatement)

Data

To add new variable in data

let instance = new VueScriptParser(code)
instance.addData(variableName,value) 

To remove variable from data

let instance = new VueScriptParser(code)
instance.removeData(variableName) 

Mounted

To add/updated in given script

let instance = new VueScriptParser(code)
instance.addMounted(mountedBody) 

Methods

To add new method in methods

let instance = new VueScriptParser(code)
instance.addMethod(name,body,args) 

To remove method from methods

let instance = new VueScriptParser(code)
instance.removeMethod(methodName)

About

This package is used to parse vue script section and it provides an interface to add, update and delete entities of different life cycles hooks of VueJS.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published