{"id":16482489,"url":"https://github.com/f/xtract","last_synced_at":"2025-06-12T16:33:24.182Z","repository":{"id":25507188,"uuid":"28938645","full_name":"f/xtract","owner":"f","description":"Extract data from DOM, easily.","archived":false,"fork":false,"pushed_at":"2020-07-09T22:48:35.000Z","size":162,"stargazers_count":41,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-17T22:26:56.873Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/f.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":"2015-01-07T23:08:37.000Z","updated_at":"2025-02-16T15:57:44.000Z","dependencies_parsed_at":"2022-08-01T05:38:29.032Z","dependency_job_id":null,"html_url":"https://github.com/f/xtract","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/f%2Fxtract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fxtract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fxtract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fxtract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f","download_url":"https://codeload.github.com/f/xtract/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244757237,"owners_count":20505357,"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-10-11T13:10:59.567Z","updated_at":"2025-03-21T07:30:43.111Z","avatar_url":"https://github.com/f.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Xtract\n\nExtract data from DOM, easily. Useful for back-end generated contents and **SEO-friendly** rich apps.\n\n![Image](https://raw.githubusercontent.com/f/xtract/master/test/xtract.png)\n\n## Installation\n```\nnpm install xtract\n```\n\n## Requirements\n\n  - This works on browser, not node.js. But if you use *jsdom*, you can.\n  - Requires jQuery.\n\nSEO is the main problem of modern web. And we have problems with passing the data from\n**HTML to JavaScript**. Your **back-end** generated data is need to be mapped to JavaScript\nand **Xtract** helps you to do that.\n\n```html\n\u003cp id=\"profile\"\u003e\n  My name is \u003cspan data-x=\"user.name\"\u003eFatih\u003c/span\u003e,\n  and I'm from \u003cspan data-x=\"user.location\"\u003eIstanbul\u003c/span\u003e.\n\u003c/p\u003e\n```\n\nYou can simply extract data now just calling:\n\n```js\nxtract($(\"#profile\")).$model\n```\n\nThis will generate following object:\n```js\n{\n  user: {\n    name: \"Fatih\",\n    location: \"Istanbul\"\n  }\n}\n```\n\n## Extracting Nested Models\n\n```html\n\u003cp id=\"profile\"\u003e\n  My name is \u003cspan data-x=\"user.name.firstname\"\u003eFatih\u003c/span\u003e\n  \u003cspan data-x=\"user.name.lastname\"\u003eAkın\u003c/span\u003e,\n  and I'm from \u003cspan data-x=\"user.location.city\"\u003eIstanbul\u003c/span\u003e,\n  \u003cspan data-x=\"user.location.country.name\"\u003eTurkey\n  (\u003cspan data-x=\"user.location.country.code\"\u003eTR\u003c/span\u003e)\u003c/span\u003e.\n\u003c/p\u003e\n```\n\n```js\nxtract($(\"#profile\")).$model\n```\n\nThis will generate following object:\n```js\n{\n  user: {\n    name: {\n      firstname: \"Fatih\",\n      lastname: \"Akın\"\n    },\n    location: {\n      city: \"Istanbul\",\n      country: {\n        name: \"Turkey\",\n        code: \"TR\"\n      }\n    }\n  }\n}\n```\n\n## Extracting with jQuery\n\nYou can use `$this` in `data-x` attribute to reach more values.\n\n```html\n\u003cp id=\"profile\"\u003e\n  \u003cimg src=\"my-profile-picture.jpg\" data-x=\"user.image: $this.attr('src')\"\u003e\n  My name is \u003cspan data-x=\"user.name\"\u003eFatih\u003c/span\u003e,\n  and I'm from \u003cspan data-x=\"user.location\"\u003eIstanbul\u003c/span\u003e.\n\u003c/p\u003e\n```\n\n```js\nxtract($(\"#profile\")).$model\n```\n\nThis will map the `src` tag to the `user.image`:\n```js\n{\n  user: {\n    name: \"Fatih\",\n    location: \"Istanbul\",\n    image: \"my-profile-picture.jpg\"\n  }\n}\n```\n\n## Plug-ins\n\nYou can simply write plugins to use extract easier.\n\n```js\nxtract.plug('date', function () {\n  return $(this).text().replace(/(\\d+)\\s+(\\w+)\\s+(\\d+)/, '$3, $1 $2');\n});\n```\n\nThe static HTML:\n```html\n\u003cdiv\u003e\n  Einstein: \u003cspan data-x=\"date.birth: $this.date()\"\u003e14 March 1879\u003c/span\u003e –\n  \u003cspan data-x=\"date.death: $this.date()\"\u003e18 April 1955\u003c/span\u003e\n\u003c/div\u003e\n```\n\nOutput:\n```js\ndate: {\n  birth: \"1879, 14 March\",\n  death: \"1955, 18 April\"\n},\n```\n\n## License\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff%2Fxtract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff%2Fxtract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff%2Fxtract/lists"}