WordFrequency
A simple script to count the frequency of words in a string.
Installation
npm install @thang2162/WordFrequency --save
or
yarn add @thang2162/WordFrequency
Arguments
- String (required) - String to be processed.
- SortBy (optional) - 'desc' for descending or 'asc' ascending.
Example:
WordCounter(String, SortBy).then(res => {
alert(JSON.stringify(res));
});
This returns a sorted object array.
Usage
<!DOCTYPE html>
<html>
<script type="module">
import {WordCounter} from './WordCounter.js'
const str = "With great power there must also come -- great responsibility.";
WordFrequency(str, 'asc').then(res => {
alert(JSON.stringify(res));
});
</script>
</html>
CDN
<!DOCTYPE html>
<html>
<script src="https://thang2162.github.io/WordFrequency/cdn.min.js"></script>
<script>
const str = "With great power there must also come -- great responsibility.";
WordFrequency(str, 'asc').then(res => {
alert(JSON.stringify(res));
});
</script>
</html>