Parts of js/README.md are wrong
Until earlier today when I found myself wanting to understand how Twitter calculates the length of a potential tweet and needed to do some tests, I'd never done anything with Node.js. But I'm pretty certain that parts of https://github.com/twitter/twitter-text/blob/master/js/README.md are wrong.
I was confused by
The twttr.txt namespace is exported, making it available as such:
because the following code is
var twitter = require('twitter-text')
twitter.autoLink(twitter.htmlEscape('#hello < @world >'))
so where does twttr.txt come from? But the rest of the example code uses twttr.txt so I thought I guess it's correct and it's just my lack of understanding of how this stuff works. So I assembled the following, copy/pasted from the example code
var twitter = require('twitter-text');
var tweet = "This is a test tweet";
console.log(twttr.txt.parseTweet(tweet));
And it didn't work.
somethingTest.js:3
console.log(twttr.txt.parseTweet(tweet));
^
ReferenceError: twttr is not defined
So I changed line 3 to
console.log(twitter.parseTweet(tweet));
and that worked.
The "Tweet Parsing" section describes the fields validDisplayRangeStart and validDisplayRangeEnd neither of which appear in the example output that follows. The order of fields in the example output
{
weightedLength: 20,
permillage: 71,
valid: true,
displayRangeEnd: 19,
displayRangeStart: 0,
validRangeEnd: 19,
validRangeStart: 0
}
doesn't match the order they appear in actual output
~/tweetLengthTest>node somethingTest.js
{
weightedLength: 20,
valid: true,
permillage: 71,
validRangeStart: 0,
validRangeEnd: 19,
displayRangeStart: 0,
displayRangeEnd: 19
}
~/tweetLengthTest>
There is also a broken link in the js readme:
Details about Twitter's weighted counting scheme are available on the official developer website.
Thanks, we moved that content to https://developer.twitter.com/en/docs/basics/counting-characters - will make a note to update that for the next time we sync with GitHub.