linkify-instagram
Advanced tools
Comparing version 0.2.0 to 0.3.0
{ | ||
"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; | ||
}; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10560
198
28
0