
density.js is a pure JavaScript library that can be used to count and calculate how many times your words appear in the HTML/Text.
How to use it:
1. Download and import the density.js into the HTML file.
<script src="density.js"></script>
2. Define the text in which you want to count the word density.
const html = `<h1>A html heading</h1> <p>Here is a html paragraph</p>`;
3. Output the results.
// Simple sorted results = density.getSorted(html); console.log(results); // Simple unsorted results = density.getUnsorted(html); console.log(results);
// results in
0: {count: 2, word: "a"}
1: {count: 2, word: "html"}
2: {count: 1, word: "heading"}
3: {count: 1, word: "here"}
4: {count: 1, word: "is"}
5: {count: 1, word: "paragraph"}4. Specify an array of stop words to ignore.
results = density.getSorted(html, {
stopwords: ["here is"]
});
console.log(results);5. With selected words.
results = density.getSorted(html, {
selected: ['html heading', 'a', 'paragraphen']
});
console.log(results);6. Specify the number of words on each row. Default: 1.
results = density.getSorted(html, {
words: 2
});
console.log(results);7. Specify the minimum number of characters. Default: 0 (disable).
results = density.getSorted(html, {
characters: 2
});
console.log(results);






