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

twitter-text

Package Overview
Dependencies
Maintainers
9
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twitter-text - npm Package Compare versions

Comparing version 1.14.7 to 2.0.0-rc1

build/twitter-text.js

37

package.json
{
"name": "twitter-text",
"description": "official twitter text linkification",
"version": "1.14.7",
"main": "./twitter-text.js",
"version": "2.0.0-rc1",
"main": "build/twitter-text.js",
"files": [
"twitter-text.js"
"build/twitter-text.js"
],

@@ -16,7 +16,30 @@ "homepage": "https://github.com/twitter/twitter-text-js",

"devDependencies": {
"uglify-js": "~2.4.3",
"qunitjs": "~1.13.0",
"grunt": "~0.4.2",
"grunt-contrib-qunit": "~0.3.0"
"babel-core": "^6.26.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"fs-extra": "^4.0.2",
"grunt": "^0.4.5",
"grunt-contrib-qunit": "~2.0.0",
"optimist": "^0.6.1",
"qunitjs": "^1.23.1",
"rollup": "^0.49.2",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-json": "^2.3.0",
"rollup-plugin-license": "^0.5.0",
"rollup-plugin-node-resolve": "^3.0.0",
"uglify-js": "~2.4.3"
},
"scripts": {
"build:config": "node scripts/buildConfig.js",
"build:prepare": "npm run build:config && rake test:conformance:prepare",
"build": "npm run build:config && rollup -c",
"build:watch": "npm run build -- -w",
"build:prod": "rollup -c rollup.config.js --prod",
"test": "rollup -c && rake test && rake test:conformance"
},
"dependencies": {
"punycode": "^2.1.0"
}
}

@@ -43,9 +43,34 @@ [![npm](https://img.shields.io/npm/v/twitter-text.svg)](https://www.npmjs.com/package/twitter-text)

## Remaining character count example
## Tweet Parsing
Previous versions of Twitter-Text provided different helper methods for Tweet validation, Tweet length, and remaining characters calculation. To simplify the API and obtain this information with just one call, Twitter-Text now exposes a new “parseTweet” method that will return the following fields:
var tweet = "This is a test tweet";
var remainingCharacters = 140 - twttr.txt.getTweetLength(tweet);
`getTweetLength` returns the computed length of a tweet after taking into consideration t.co URL shortening and non UTF-16 characters
* **weightedLength:** Integer that indicates the weighted length calculated by the algorithm above.
* **permillage:** Integer value corresponding to the ratio of consumed weighted length to the maximum weighted length.
* **valid:** Boolean indicating whether it is a valid Tweet.
* **dispayRangeStart:** Integer with start index on the Tweet string
* **displayRangeEnd:** Integer with end index on the Tweet string (inclusive)
* **validDisplayRangeStart:** Integer indicating the valid start index on the Tweet string
* **validDisplayRangeEnd:** Integer indicating the valid end index on the Tweet string. This can be lesser than displayRangeEnd (inclusive).
```js
var tweet = "This is a test tweet";
twttr.txt.parseTweet(tweet);
/* Returns:
{
weightedLength: 20,
permillage: 71,
valid: true,
displayRangeEnd: 19,
displayRangeStart: 0,
validRangeEnd: 19,
validRangeStart: 0
}
*/
```
Details about Twitter's weighted counting scheme are available on the [official developer website](https://developer.twitter.com/en/docs/developer-utilities/twitter-text).
### Marked for Deprecation
`getTweetLength` returns the weighted length of a tweet that is calculated by parseTweet. It will be deprecated in a subsequent release. Please use parseTweet instead.
## Usernames

@@ -72,3 +97,3 @@

For this reason twitter-text currently does not support extracting or auto-linking
For this reason Twitter-Text currently does not support extracting or auto-linking
of URLs immediately followed by non-Latin characters.

@@ -93,2 +118,8 @@

For all Twitter-Text tests, run:
npm run test
This will run conformance and javascript tests.
### Conformance

@@ -95,0 +126,0 @@

twitter-text.js
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