{"id":13555350,"url":"https://github.com/asterjs/aster-squery","last_synced_at":"2025-09-08T12:32:59.561Z","repository":{"id":17653486,"uuid":"20458041","full_name":"asterjs/aster-squery","owner":"asterjs","description":"Replace nodes with CSS-like selectors in aster.","archived":false,"fork":false,"pushed_at":"2016-11-23T21:52:42.000Z","size":188,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-17T03:29:04.838Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npmjs.org/package/aster-squery","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/asterjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-03T20:19:12.000Z","updated_at":"2019-12-15T02:16:14.000Z","dependencies_parsed_at":"2022-09-11T15:10:47.656Z","dependency_job_id":null,"html_url":"https://github.com/asterjs/aster-squery","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asterjs%2Faster-squery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asterjs%2Faster-squery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asterjs%2Faster-squery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asterjs%2Faster-squery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asterjs","download_url":"https://codeload.github.com/asterjs/aster-squery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232311131,"owners_count":18503606,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:03:09.876Z","updated_at":"2025-01-03T08:27:51.025Z","avatar_url":"https://github.com/asterjs.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","others"],"sub_categories":[],"readme":"# aster-squery\n[![NPM version][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n\n\u003e Replace nodes with CSS-like selectors in aster.\n\nAllows to use CSS-style selectors for finding nodes and replacing them with results of corresponding handlers.\n\nUses [grasp-squery](https://npmjs.org/package/grasp-squery) behind the scenes, so check out [official documentation](http://graspjs.com/docs/squery/) for syntax details.\n\n## Usage\n\nFirst, install `aster-squery` as a development dependency:\n\n```shell\nnpm install --save-dev aster-squery\n```\n\nThen, add it to your build script:\n\n```javascript\nvar aster = require('aster');\nvar squery = require('aster-squery');\n\naster.src('src/**/*.js')\n.map(squery({\n  'if[then=return][else=return]': function (node) {\n    return {\n        type: 'ReturnStatement',\n        argument: {\n            type: 'ConditionalExpression',\n            test: node.test,\n            consequent: node.consequent.argument,\n            alternate: node.alternate.argument\n        }\n    };\n  }\n  // , ...\n}))\n.map(aster.dest('dist'))\n.subscribe(aster.runner);\n```\n\ncan be also written as:\n\n```javascript\nvar aster = require('aster');\nvar equery = require('aster-equery');\n\naster.src('src/**/*.js')\n.map(equery({\n  'if[then=return][else=return]': 'return \u003c%= test %\u003e ? \u003c%= consequent.argument %\u003e : \u003c%= alternate.argument %\u003e'\n  // , ...\n}))\n.map(aster.dest('dist'))\n.subscribe(aster.runner);\n```\n\n## API\n\n### squery(mappings)\n\n#### mappings\nType: `{pattern: handler}`\n\nReplacement mappings.\n\n##### pattern\nType: `String`\n\n[CSS-style node selector](http://graspjs.com/docs/squery/).\n\n##### handler (option 1: callback)\nType: `Function(node, named)`\n\nCallback to be called on each found match. It will get two arguments - matched node object and hashmap of named subpatterns.\n\n##### handler (option 2: template)\nType: `String`\n\n[estemplate](https://github.com/RReverser/estemplate) string to be used for generating AST.\n\n## License\n\n[MIT License](http://en.wikipedia.org/wiki/MIT_License)\n\n[npm-url]: https://npmjs.org/package/aster-squery\n[npm-image]: https://badge.fury.io/js/aster-squery.png\n\n[travis-url]: http://travis-ci.org/asterjs/aster-squery\n[travis-image]: https://secure.travis-ci.org/asterjs/aster-squery.png?branch=master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasterjs%2Faster-squery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasterjs%2Faster-squery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasterjs%2Faster-squery/lists"}