-
Notifications
You must be signed in to change notification settings - Fork 0
/
textInfo.js
48 lines (42 loc) · 1.2 KB
/
textInfo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
let textareaEl = document.querySelector("#text");
let text = null;
let data = {
words: 0,
sentences: 0,
uppercase: 0,
lowercase: 0,
spaces: 0,
digits: 0,
vowels: 0,
consonants: 0,
};
const findLength = (item) => (item == null ? 0 : item.length);
const setText = () => {
text = textareaEl.value;
if (text != null) {
data.sentences = findLength(text.match(/\056/g));
data.words = findLength(text.match(/[a-zA-Z]+/g));
data.spaces = findLength(text.match(/\s/g));
data.uppercase = findLength(text.match(/[A-Z]/g));
data.lowercase = findLength(text.match(/[a-z]/g));
data.digits = findLength(text.match(/\d/g));
data.vowels = findLength(text.match(/[aeiou]/gi));
data.consonants = findLength(text.match(/[^aeiou]/gi));
}
localStorage.setItem("data", JSON.stringify(data));
window.location = "index.html";
};
const getData = () => {
return JSON.parse(localStorage.getItem("data"));
};
const showData = () => {
let data = getData();
let htmlContent = "";
for (item in data) {
htmlContent += `<div class="box">
<h2>${data[item]}</h2>
<p>${item}</p>
</div>`;
}
document.querySelector(".info-wrapper").innerHTML = htmlContent;
};