New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

linkify-instagram

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linkify-instagram - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

src/test/index_test.js

2

package.json
{
"name": "linkify-instagram",
"version": "0.2.0",
"version": "0.3.0",
"description": "Linkify Instagram captions or comments",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -12,7 +12,17 @@ linkify-instagram (WIP)

// Linkifies hashtags
console.log(linkify('Hello #World'));
// --> Hello <a href="https://www.instagram.com/explore/tags/world">#World</a>
// Hello <a href="https://www.instagram.com/explore/tags/world">#World</a>
// The hastag template is customizable
console.log(linkify('Hello #World', '<a href="https://www.instagram.com/explore/tags/{hashtag}" target="_blank">#{hashtag}</a>'));
// --> Hello <a href="https://www.instagram.com/explore/tags/world" target="_blank">#World</a>
// Hello <a href="https://www.instagram.com/explore/tags/world" target="_blank">#World</a>
// Linkifies usernames
console.log(linkify('Hello @hodor'));
// Hello <a href="https://www.instagram.com/hodor">@hodor</a>
// The template is customizable
console.log(linkify('Hello @hodor', undefined, '<a href="https://www.instagram.com/{username}" target="_blank">@{username}</a>'));
// Hello <a href="https://www.instagram.com/hodor" target="_blank">@hodor</a>
```

@@ -7,21 +7,19 @@ var _ = require('lodash');

module.exports = function(text) {
var spaced = text.split(' '),
hashtagged = spaced.map(function(word) {
if (_.startsWith(word, '#')) {
var words = _.words(word),
actualTag = words[0],
linkified = hashtag(actualTag),
replaced = word.replace('#', '').replace(actualTag, linkified);
return replaced;
} else if (_.startsWith(word, '@')) {
var words = _.words(word),
actualUsername = words[0],
linkified = username(actualUsername),
replaced = word.replace('@', '').replace(actualUsername, linkified);
return replaced;
} else {
return word;
}
// Hashtags
var hashtags = text.match(/[#]\w+/g);
if (hashtags) {
_.forEach(hashtags, function(ht) {
text = text.replace(ht, hashtag(ht));
});
return _.join(hashtagged, ' ');
};
// Usernames
var usernames = text.match(/[@]\w+/g);
if (usernames) {
_.forEach(usernames, function(un) {
text = text.replace(un, username(un));
});
}
return text;
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc