forked from rafaveguim/vis-passwords-time
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
executable file
·68 lines (56 loc) · 1.71 KB
/
util.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function width(el) { return document.getElementById(el).clientWidth; }
function height(el){ return document.getElementById(el).clientHeight; }
function replaceAt(s, index, char) {
return s.substr(0, index) + char + s.substr(index + 1);
}
function buildRegex(pattern) {
var reg = [],
scape = '\n'
counter = 1;
for (var i = 0; i < pattern.length; i++) {
var c = pattern.charAt(i);
if (c==scape) continue;
reg[i] = '(\\d)';
for (var k = i + 1; k < pattern.length; k++) {
if (c == pattern.charAt(k)){
pattern = replaceAt(pattern, k, '\n');
reg[k] = '\\' + counter;
}
}
counter++;
}
return new RegExp(reg.join(''));
}
/**
* Given an array of filtering functions,
* apply them all against an array of passwords and
* returns the resulting array.
* @param pwds array of passwords (data rows)
* @param filterStack array of functions
*
*/
//function filter(pwds, filterStack){
// filterStack.forEach(function(f){pwds = pwds.filter(f)});
// return pwds;
//}
/**
* Given an array of filtering functions,
* apply them all against an array of passwords and
* returns the resulting array.
* @param pwds array of passwords (data rows)
* @param filterStack array of functions
*
*/
function filter(pwds, filterStack){
var pwd;
for (var i=pwds.length-1; i>=0; i--){
pwd = pwds[i];
// test if the password matches at least one 'denied' pattern
if (filterStack.some(function(f){return !f(pwd)}))
pwds.splice(i,1);
}
return pwds;
}
function toNumber(d){
return +d;
}