Xtract
Extract data from DOM, easily. Useful for back-end generated contents and SEO-friendly rich apps.
Installation
npm install xtract
Requirements
- This works on browser, not node.js. But if you use jsdom, you can.
- Requires jQuery.
SEO is the main problem of modern web. And we have problems with passing the data from HTML to JavaScript. Your back-end generated data is need to be mapped to JavaScript and Xtract helps you to do that.
My name is Fatih, and I'm from Istanbul.
You can simply extract data now just calling:
$model
This will generate following object:
user: name: "Fatih" location: "Istanbul"
Extracting Nested Models
My name is Fatih Akın, and I'm from Istanbul, Turkey (TR).
$model
This will generate following object:
user: name: firstname: "Fatih" lastname: "Akın" location: city: "Istanbul" country: name: "Turkey" code: "TR"
Extracting with jQuery
You can use $this
in data-x
attribute to reach more values.
My name is Fatih, and I'm from Istanbul.
$model
This will map the src
tag to the user.image
:
user: name: "Fatih" location: "Istanbul" image: "my-profile-picture.jpg"
Plug-ins
You can simply write plugins to use extract easier.
xtract;
The static HTML:
Einstein: 14 March 1879 – 18 April 1955
Output:
date: birth: "1879, 14 March" death: "1955, 18 April"
License
MIT.