Roy-Ast
A quick static tools for royjs.
Install
npm install @royjs/ast --save
Usage
import {Store} from '@royjs/ast';
const store = new Store(code);
API
Classes
Store
解析Royjs的Store数据
Kind: global class
new Store(code)
Store的构造函数
Param | Type | Description |
---|---|---|
code | String |
传入的store的代码 |
store.parse() ⇒
解析store文件
Kind: instance method of Store
Returns: 返回state,actions,urls
store.remove(name) ⇒
根据name移除某个定义的action
Kind: instance method of Store
Returns: 修改后的代码
Param | Type | Description |
---|---|---|
name | String |
action的名字 |
store.renameState(oldName, newName) ⇒
重命名某个state
Kind: instance method of Store
Returns: 修改后的代码
Param | Type | Description |
---|---|---|
oldName | String |
旧的state的名字 |
newName | String |
新的state的名字 |
store.modifyState(name, value) ⇒
修改状态的值
Kind: instance method of Store
Returns: 修改后的代码
Param | Type | Description |
---|---|---|
name | String |
状态的名称 |
value | String |
状态的值 |
store.addState(name, value)
增加状态的值
Kind: instance method of Store
Param | Type | Description |
---|---|---|
name | String |
状态的名称 |
value | String |
状态的值 |
store.modify(name, content) ⇒
根据action的名字,修改action内容
Kind: instance method of Store
Returns: 修改后的代码
Param | Type | Description |
---|---|---|
name | String |
action的名字 |
content | String |
action的内容 |
store.rename(oldName, newName) ⇒
重命名某个action
Kind: instance method of Store
Returns: 修改后的代码
Param | Type | Description |
---|---|---|
oldName | String |
action的名称 |
newName | String |
action的新的名称 |
store.add(name) ⇒
增加一个action, 如果存在同名action则不会添加
Kind: instance method of Store
Returns: 修改后的代码
Param | Type | Description |
---|---|---|
name | String |
action的名称 |
store.modifyByStartEnd(node, content) ⇒
根据位置修改内容
Kind: instance method of Store
Returns: 返回修改的代码
Param | Type | Description |
---|---|---|
node | Node |
指定的节点,该节点需包含start和end两个属性 |
content | String |
替换的content |
View
解析Royjs的视图数据
Kind: global class
new View(code)
View的构造函数
Param | Type | Description |
---|---|---|
code | String |
传入的view的代码 |
view.parse() ⇒
解析视图数据
Kind: instance method of View
Returns: 返回 class和elements值
view.attrs(node, name, value)
为一个节点设置属性
Kind: instance method of View
Param | Type |
---|---|
node |
Node | String
|
name | String |
value | String |
view.removeAttr(node, name)
移除一个节点属性
Kind: instance method of View
Param | Type | Description |
---|---|---|
node |
Node | String
|
|
name | String |
要移除的属性名称 |
view.remove(name)
根据名称移除一个节点
Kind: instance method of View
Param | Type |
---|---|
name | String |
view.removeByStart(start)
根据起始位置移除一个节点
Kind: instance method of View
Param | Type |
---|---|
start |
String | Int
|
view.cloneByStart(start)
根据起始位置复制一个节点
Kind: instance method of View
Param | Type |
---|---|
start |
String | Int
|
view.add(node, child)
为一个节点加入子节点
Kind: instance method of View
Param | Type | Description |
---|---|---|
node |
String | node
|
父节点 |
child | String |
子节点的代码 |
view.rename(}, newName)
重命名一个节点,如果寻找到多个节点,只会重命名第一个
Kind: instance method of View
Param | Type | Description |
---|---|---|
} | String |
oldName |
newName | String |
Array
view.find(}) ⇒ 根据name寻找节点
Kind: instance method of View
Param | Type | Description |
---|---|---|
} | String |
name |
view.findByStart(start, isPath)
根据起始位置寻找节点,如果第二个参数为true,则返回节点的路径
Kind: instance method of View
Param | Type |
---|---|
start |
String | Int
|
isPath | Boolean |
view.findBy(callback, isPath)
根据callback过滤节点,如果第二个参数为true,则返回节点的路径
Kind: instance method of View
Param | Type |
---|---|
callback | function |
isPath | Boolean |