{"id":16777040,"url":"https://github.com/fb55/cornet","last_synced_at":"2025-06-20T23:08:12.034Z","repository":{"id":4762920,"uuid":"5913463","full_name":"fb55/cornet","owner":"fb55","description":"transform streaming html using css selectors","archived":false,"fork":false,"pushed_at":"2023-07-19T09:31:17.000Z","size":170,"stargazers_count":48,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-20T23:07:27.020Z","etag":null,"topics":["css-selector","dom","javascript","selector"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fb55.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-09-22T13:59:00.000Z","updated_at":"2024-05-27T06:48:24.000Z","dependencies_parsed_at":"2024-06-18T21:40:19.028Z","dependency_job_id":null,"html_url":"https://github.com/fb55/cornet","commit_stats":null,"previous_names":["fb55/node-cornet"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fb55/cornet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fcornet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fcornet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fcornet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fcornet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fb55","download_url":"https://codeload.github.com/fb55/cornet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fcornet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261032097,"owners_count":23100050,"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":["css-selector","dom","javascript","selector"],"created_at":"2024-10-13T07:11:43.733Z","updated_at":"2025-06-20T23:08:07.024Z","avatar_url":"https://github.com/fb55.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## About\n\n\u003e The **cornet** is a brass instrument very similar to the trumpet,\n\u003e distinguished by its conical bore, compact shape, and mellower tone quality. -\n\u003e [Wikipedia](http://en.wikipedia.org/wiki/Cornet)\n\nThis project is demonstrating how to use a couple of my libraries to replace\n[`substack/node-trumpet`](https://github.com/substack/node-trumpet) in just a\ncouple of LOC.\n\nEven better, there are some advantages over `trumpet`:\n\n-   The ammount of usable CSS selectors is increased dramatically thanks to\n    [`fb55/css-select`](https://github.com/fb55/css-select).\n-   `cornet` works as a handler for\n    [`fb55/htmlparser2`](https://github.com/fb55/htmlparser2), the probably\n    fastest HTML parser currently available for node. And it's much less strict\n    than the `sax` module used by `trumpet`.\n-   By using the great\n    [`cheeriojs/cheerio`](https://github.com/cheeriojs/cheerio) module, you can\n    do everything with your document that would be possible with jQuery.\n\n_Please note that callbacks are fired as soon as an element was retrieved. That\nmeans that no content past the element will be available, so cheerio won't find\nanything, and, as the element is at this time the last child of it's parent,\nselectors like `:nth-last-child` won't work as expected._\n\n## Install\n\n    npm install cornet\n\n## Example\n\n```js\nconst Parser = require(\"htmlparser2\").WritableStream;\nconst Cornet = require(\"cornet\");\nconst minreq = require(\"minreq\");\nconst $ = require(\"cheerio\");\n\nconst cornet = new Cornet();\n\nminreq.get(\"http://github.com/fb55\").pipe(new Parser(cornet));\n\ncornet.remove(\"script\"); //remove all scripts\n\n//show all repos\ncornet.select(\".repo_list\", function (elem) {\n    $(elem)\n        .find(\"h3\")\n        .each(function (i) {\n            console.log(\"repo %d: %s\", i + 1, $(this).text().trim());\n        });\n});\n\n//does the same\nconst i = 0;\ncornet.select(\".repo_list h3\", function (elem) {\n    console.log(\"repo %d: %s\", ++i, $(elem).text().trim());\n});\n\n//sometimes, you only want to get a single element\nconst onTitle = cornet.select(\"title\", function (title) {\n    console.log(\"Page title:\", $(title).text().trim());\n    cornet.removeLister(\"element\", onTitle);\n});\n```\n\n## API\n\n#### `cornet(options)`\n\nThe constructor. `options` are the same you can pass to\n[`fb55/DomHandler`](https://github.com/fb55/DomHandler).\n\nIt's an `EventEmitter` that emits two events:\n\n-   `element` is emitted whenever an element was added to the DOM.\n-   `dom` is emitted when the DOM is complete.\n\n#### `cornet#select(selector | fn, cb)`\n\nCalls the callback when the selector is matched or a passed function returns\n`true` (or any value that evaluates to true).\n\nInternally, listenes for any `element` event and checks then if the selector is\nmatched.\n\nReturns the listening function, so you can remove it afterwards (as shown in the\nexample above).\n\n#### `cornet#remove(selector | fn)`\n\nRemoves all elements that match the selector. Also returns the listener.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffb55%2Fcornet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffb55%2Fcornet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffb55%2Fcornet/lists"}