https://github.com/kunaltaitkar/vue-script-parser
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.
https://github.com/kunaltaitkar/vue-script-parser
ast javascript parser script vue-parser vue-script-ast-parser vue-script-parser vuejs
Last synced: about 7 hours ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/kunaltaitkar/vue-script-parser
- Owner: kunaltaitkar
- License: mit
- Created: 2020-07-21T05:34:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-23T17:11:47.000Z (over 5 years ago)
- Last Synced: 2025-10-06T07:53:48.346Z (4 months ago)
- Topics: ast, javascript, parser, script, vue-parser, vue-script-ast-parser, vue-script-parser, vuejs
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vue-script-parser

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](https://www.npmjs.com/package/vue-script-ast-parser)
```
npm install vue-script-ast-parser
```
## Usage
```
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)
}
}
}
```
## 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)
```