uri-metadata
v1.0.3
Published
Extract metadata information (including Twitter and Open Graph) from any http/https url
Downloads
30
Maintainers
Readme
uri-metadata
uri-metadata is a TypeScript library for extracting metadata information, including Twitter and Open Graph properties, from any HTTP/HTTPS URL. It is specifically designed to be useful in development of Chrome extensions.
Highlights
Installation
npm install uri-metadata --save
Usage
Fetch metadata using the provided example below, which returns a Promise:
import metadata from "uri-metadata";
try {
const response = await metadata.get("https://awwwards.com");
console.log("Metadata: ", response);
} catch (err) {
console.log("An error occurred: ", err);
}
Alternatively, you can pass a callback function:
import metadata from "uri-metadata";
metadata.get("https://awwwards.com", (data, err) => {
console.log(err ? err : data);
});
The response is an object containing the URL metadata grouped by type:
{
meta: {
'theme-color': '#3ea094',
referrer: 'origin-when-cross-origin',
keywords: 'Website Awards, Web Design Inspiration, Webdesign Trends',
...
},
og: {
type: 'website',
site_name: 'Awwwards',
...
},
twitter: {
...
}
}
Options
You can pass true
or false
as a third argument to group or ungroup metatags (defaults to true
). For example:
response = await metadata.get("https://www.awwwards.com", false);
This returns:
{
'og:type': 'website',
'theme-color': '#3ea094',
'og:site_name': 'Awwwards',
referrer: 'origin-when-cross-origin',
keywords: 'Website Awards, Web Design Inspiration, Webdesign Trends',
...
}
Contributing
- Fork the repository and create your feature branch:
git checkout -b my-update
- Commit your changes:
git commit -am 'Updated some parts'
- Push to the branch:
git push origin my-update
- Submit a pull request