https://github.com/pirxpilot/tweet-html
reparse tweets returned by twitter API to HTML
https://github.com/pirxpilot/tweet-html
Last synced: about 1 year ago
JSON representation
reparse tweets returned by twitter API to HTML
- Host: GitHub
- URL: https://github.com/pirxpilot/tweet-html
- Owner: pirxpilot
- Created: 2013-12-20T01:15:15.000Z (over 12 years ago)
- Default Branch: main
- Last Pushed: 2022-06-05T07:59:58.000Z (about 4 years ago)
- Last Synced: 2024-11-05T18:57:36.507Z (over 1 year ago)
- Language: JavaScript
- Size: 64.5 KB
- Stars: 4
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]
reparse tweets returned by twitter API to HTML
## Installation
Install with [npm](http://npmjs.org):
$ npm install tweet-html
## API
### tweet2html(tweet, username[, options])
Parse [tweet entities] contained in [tweet] object returned by one of the [Twitter API] calls.
- `tweet` - tweet object
- `username` -
- `opts` - _optional_ - at the moment only `formatDate` is supported; if not provided `created_at`
dates are formated to display _3 hours ago_ or _a year ago_
In addition to usual suspects (user mentions, hashtags, urls) it also parses and embeds vine,
instagram, youtube and vimeo links.
Given:
```json
{
"id_str": "413684211087048704",
"created_at": "Thu Dec 19 14:56:16 +0000 2013",
"text": "Look for the East Byrneside boarder cross course this weekend! https://t.co/zbGXyOjmlr",
"entities": {
"urls": [
{
"url": "https://t.co/zbGXyOjmlr",
"expanded_url": "https://vine.co/v/h0UBzVLzA5O",
"display_url": "vine.co/v/h0UBzVLzA5O",
"indices": [
63,
86
]
}
]
}
}
```
Renders:
```html
'3 days ago'
Look for the East Byrneside boarder cross course this weekend!
```
Check [tests](test/tweet-html.js) for more examples.
## License
MIT
[tweet]: https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/tweet-object
[tweet entities]: https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/entities-object
[Twitter API]: https://developer.twitter.com/en/docs/api-reference-index
[npm-image]: https://img.shields.io/npm/v/tweet-html
[npm-url]: https://npmjs.org/package/tweet-html
[build-url]: https://github.com/pirxpilot/tweet-html/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/workflow/status/pirxpilot/tweet-html/check
[deps-image]: https://img.shields.io/librariesio/release/npm/tweet-html
[deps-url]: https://libraries.io/npm/tweet-html