-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.ts
48 lines (41 loc) · 810 Bytes
/
helper.ts
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
export const includes = (
collection: Array<string> | Array<Number>,
target: string | Number,
) => {
for (let i = 0; i <= collection.length; i += 1) {
if (collection[i] === target) {
return true;
}
}
return false;
};
export const sanitizeString = (
str: string,
) => String(str)
.replace(/[^a-z0-9áéíóúñü \.,_-]/gim, '')
.trim()
.toLowerCase();
export const isKeywordExists = (
str: string,
keyword: string,
) => {
const tokens = String(str).split(' ');
for (let i = 0; i < tokens.length; i += 1) {
if (sanitizeString(str).includes(keyword)) {
return {
result: true,
meta: {
},
};
}
}
return {
result: false,
__meta: null,
};
};
export default {
includes,
sanitizeString,
isKeywordExists,
};