1.0.1 • Published 10 years ago

astra v1.0.1

Weekly downloads
31
License
-
Repository
github
Last release
10 years ago

ASTRA

ASTRA is easy to use AST traverse library

Installation

npm install --save astra

Usage

var astra=require('astra');

var newAst=astra(ast)
    .when(pattern,function(chunk){

    })
    .when(anotherPattern,function(chunk){

    })
    .run();

Examples

simple

var newAst = astra(ast)
    .when({
        "type": "Literal",
        "value": "myDirective",
        "raw": "\"myDirective\""
    }, function (chunk) {
        chunk.value = "newMyDirective";
        chunk.raw = "\"newMyDirective\""
    })
    .run();
    },
    {
        "type": "Literal",
        "value": "/app/styles/styles.css"
    }
], function (chunk) {
    chunk.value = "";
    chunk.raw = "\"\"";
})
.run();
<br>
complex pattern(** means deep child)
```javascript
var newAst=astra(ast)
    .when({
        "type": "FunctionExpression",
        "params": [
            {
                "type": "Identifier",
                "name": "$routeProvider"
            }
        ],
        "**": {
            "type": "CallExpression",
            "callee": {
                "type": "MemberExpression",
                "property": {
                    "type": "Identifier",
                    "name": "when"
                }
            },
            "**": [
                {
                    "type": "Property",
                    "key": {
                        "type": "Identifier",
                        "name": "template"
                    },
                    "value": {
                        "type": "Literal"
                    }
                },
                {
                    "type": "Property",
                    "key": {
                        "type": "Identifier",
                        "name": "styles"
                    },
                    "value": {
                        "type": "Literal"
                    }
                }
            ]
        }
    }, function (chunk) {
        chunk.value.value='';
    })
    .run();

License

MIT

1.0.1

10 years ago

1.0.0

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.1

10 years ago