-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtools.js
44 lines (36 loc) · 957 Bytes
/
tools.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
const striptags = require("striptags");
// TODO make env vars
// globals
const log = false;
function loggg(toLog) {
if (log) {
console.log(toLog);
}
}
function textOnly(content) {
return striptags(content, { allowedTags: [] });
}
function textOnlyLength(content) {
return textOnly(content).length;
}
function cleanParagraphTags(content) {
return striptags(content, ["p", "i", "em", "b", "strong", "span", "a"]);
}
// NOTE: Taken from https://gist.github.com/raymyers/44807526ca4fdf6d8db1a7d545c7e2c8
const trimmedMean = (values, trimAmount) => {
var trimCount = Math.floor(trimAmount * values.length);
return mean(
values.sort((a, b) => a - b).slice(trimCount, values.length - trimCount)
);
};
const mean = (values) => {
let sum = values.reduce((previous, current) => (current += previous));
return sum / values.length;
};
module.exports = {
loggg,
textOnly,
textOnlyLength,
cleanParagraphTags,
trimmedMean,
};