npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tweet-patch

v2.0.5

Published

Convert plain-text back into twitter-ready markup.

Downloads

43

Readme

tweet-patch

Build Status

Convert plain-text back into twitter-ready markup.

Version 2.0

Version 2.0 of this module no longer attempts to locate/use the data.entities objects from the Twitter API returned data. It will, however, use the data.entities.urls array from the Twitter data (if available) to determine if there is a media url attached to the end of the plain-text tweet by the Twitter API. You can use the stripTrailingUrl option to remove this trailing media url if you are serving plain-text tweets without embedded media support.

Install

$ npm install --save tweet-patch

Usage

Option 01: Pass in a string with urls, hashtags and user-mentions:

var tweetPatch = require('tweet-patch');

tweetPatch('@SomeUser, go check out this #awesome #thing http://t.co/a01234!');

Option 02: Pass in a Twitter Object from the Twitter API:

var tweetPatch = require('tweet-patch');

const tweetObj = {
    text: '@SomeUser, go check out this #awesome #thing http://t.co/a01234!',
    entities: {
        urls: [...],
        // ...
    }
}
    
tweetPatch(tweetObj);

Both examples above would result in the following return string (formatted for readability):

'<a href="https://twitter.com/SomeUser">@SomeUser</a> go, check out this 
 <a href="https://twitter.com/hashtag/awesome">#awesome</a> 
 <a href="https://twitter.com/hashtag/thing">#thing</a> 
 <a href="http://t.co/a01234">http://t.co/a01234</a>!'

API

tweetPath(data, [options])

data

Required Type: object string

The tweet object returned from the Twitter API, or a string containing hashtags, urls and user-mentions.

options

hrefProps

Type: object string Default: None

Pass in an object and the key:value pairs will be assigned to the anchor tags that are created (uses obj-to-property-string). Pass in a string, and that string will be assigned to the url anchor tags as-is.

Examples:

// Using an object
tweetpatch('#hi https://t.co/123', {hrefProps: {class: 'myClass'}});
//=> '<a href="https://twitter.com/hashtag/hi">#hi</a> <a href="https://t.co/123" class="myClass">https://t.co/123</a>'

// Using a string
tweetpatch('#hi https://t.co/123', {hrefProps: 'class="myClass"'});
//=> '<a href="https://twitter.com/hashtag/hi">#hi</a> <a href="https://t.co/123" class="myClass">https://t.co/123</a>'
stripTrailingUrl

Type: Boolean Default: false

This is only used if you have supplied a data object returned from the Twitter API, and that object has the entities.urls property. The reason for this is because we only want to strip the trailing media url if you are serving plain-text tweets, (no media support) and you want to clean up the tweet text. This option only works when you have supplied a Tweet object with Twitter's entities.urls property to ensure that we aren't deleting actual urls put there by the tweet author.

useExistingHTML

Type: Boolean Default: false

This is only used if you have supplied a data object returned from the Twitter API, and the Twitter API has supplied an html property on that object for you.

Known Limitations

  • Some tweets will be formatted in a way that makes it impossible to accurately parse the data. For example, if a url is typed inside of parenthesis: (http://t.co/foo) tweet-patch will see the closing parenthesis as part of the url. For more information, see issue #8.

License

MIT @ Michael Wuergler