trendingjs
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

Trendingjs!

Returns trending words in an array of tweets

Whats the goal?

Finds commonly repeated words in an array of strings. Can be useful if you have a social media site and you want users to implement the "What is trending" page so users can know what people are actively talking about, Used twitter? sounds familiar right?

Install

npm i trendingjs

Usage

javascript
// first parameter is the array of strings ( compulsory )
// second paramenter is the maximum number of trending words you need ( compulsory )
// thirs parameter is optional 

const  trendingJs  =  require('trendingjs');
const  strings  = ["Big difference between taxing people and taxing purchases (ie consumption). Much better to emphasize the latter.'",

"@MaxMBerger The collective wisdom of the market is usually (not always) better than the smartest govt regulator.'",

"Me & other private money funded Tesla for first 7 years, got IPO+ govt money for 3, now paid back. Yes, carbon tax would be a better way.'"
]

const  trending  =  trendingJs(strings, 20)

console.log(trending)
typescript
import  TrendingJs  from  'trendingjs'
const  strings  = ["Big difference between taxing people and taxing purchases (ie consumption). Much better to emphasize the latter.'",

"@MaxMBerger The collective wisdom of the market is usually (not always) better than the smartest govt regulator.'",

"Me & other private money funded Tesla for first 7 years, got IPO+ govt money for 3, now paid back. Yes, carbon tax would be a better way.'"
]
const  trending  =  TrendingJs(strings: string[], 20: number)

console.log(trending)
return value
// returns {word: string, value: number}[]
[ { word: 'better', value: 3 },
  { word: 'govt', value: 2 },
  { word: 'the', value: 2 },
  { word: 'consumption', value: 1 },
  { word: '@maxmberger', value: 1 },
  { word: 'difference', value: 1 },
  { word: 'collective', value: 1 },
  { word: 'emphasize', value: 1 },
  { word: 'purchases', value: 1 },
  { word: 'regulator', value: 1 },
  { word: 'smartest', value: 1 },
  { word: 'usually', value: 1 },
  { word: 'private', value: 1 },
  { word: 'market', value: 1 },
  { word: 'carbon', value: 1 },
  { word: 'always', value: 1 },
  { word: 'wisdom', value: 1 },
  { word: 'latter', value: 1 },
  { word: 'funded', value: 1 },
  { word: 'taxing', value: 1 } ]

Options

options is an optional object that contains some settings you can use to tweak results

interface  Options {
	minWord?:  number;
	//minWord: determines the number of letters to consider. default is 3 i.e trendingjs will consider 'god' but ignore words like 'be' or 'a'
	wordChain?:  number;
	//wordChain: determines the number of words to consider, default is 2. i.e trendingjs will consider 'this life' and 'spacecraft' but will ignore 'the last bender'. the maximum value is 4
	allowSameSentenceDuplicate?:  boolean;
	// allowSameSentenceDuplicate: ignore the same words in a single string default is true. i.e trendingjs will see 'school go to school school' as 'go to school'.
	ignoreIrrelevantSingleWords?:  boolean;
	// ignoreIrrelevantSingleWords: default is true ignore common single words like 'the', 'not'
	commonWords?:  string[];
	//commonWords:Add optional common words you will like trendingJs to ignore default is []. 

}
// defaults
	const  options  = {
		minWord:  3,
		wordChain:  2,
		allowSameSentenceDuplicate:  false,
		ignoreIrrelevantSingleWords:  true,
		commonWords: []

	}
	// usage with options
	const  options  = {
		minWord:  3,
		wordChain:  2,
		allowSameSentenceDuplicate:  false,
		ignoreIrrelevantSingleWords:  true,
		commonWords: []

	}
	console.log(trendingJs(strings, 20, options))

Others

// you can put your sample texts in json file and use like this
// json must be valid
console.log(trendingJs(require('./test.json'), 20, options))

// if you want to implement something like trending an hour ago. all you need to do is to feed in texts that was made in the last hour

//if you want to add to the ignoreIrrelevantSingleWords data. you will need to go to the trendingjs folder in your node_modules, then go to modules, the go to data. Then modify the irrelevantSingleWords.json file must be a json object containing the word and a boolean value 'true' as the key

//if you want to add to the stopwords data. you will need to go to the trendingjs folder in your node_modules, then go to modules, the go to data. Then modify the stopwords.json file must be a json Arrsy of string

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.9
    1
    • latest

Version History

Package Sidebar

Install

npm i trendingjs

Weekly Downloads

8

Version

1.0.9

License

MIT

Unpacked Size

14.6 kB

Total Files

8

Last publish

Collaborators

  • ayotycoon