@becollective/utils 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -3
- package/password.js +12 -1
- package/tests/password.test.js +26 -0
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@becollective/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Common utilities",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "NODE_ENV=localtest jest tests/*"
|
|
7
|
+
"test": "NODE_ENV=localtest ./node_modules/.bin/jest tests/*"
|
|
8
8
|
},
|
|
9
9
|
"author": "",
|
|
10
|
-
"license": "ISC"
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"jest": "^23.6.0"
|
|
13
|
+
}
|
|
11
14
|
}
|
package/password.js
CHANGED
|
@@ -12,7 +12,9 @@ const password = {
|
|
|
12
12
|
return !!input.match(/[!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]/);
|
|
13
13
|
},
|
|
14
14
|
validate: (input) => {
|
|
15
|
-
if(input
|
|
15
|
+
if(typeof input !== 'string') {
|
|
16
|
+
throw new Error('not-string');
|
|
17
|
+
} else if(input.length < 8) {
|
|
16
18
|
throw new Error('invalid-length');
|
|
17
19
|
}
|
|
18
20
|
|
|
@@ -26,6 +28,15 @@ const password = {
|
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
return true;
|
|
31
|
+
},
|
|
32
|
+
isValid: (input) => {
|
|
33
|
+
try {
|
|
34
|
+
password.validate(input);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
29
40
|
}
|
|
30
41
|
}
|
|
31
42
|
|
package/tests/password.test.js
CHANGED
|
@@ -41,4 +41,30 @@ describe('password.valiate', () => {
|
|
|
41
41
|
util.password.validate(password);
|
|
42
42
|
}).not.toThrow('invalid-minimum-rules');
|
|
43
43
|
}, 1000);
|
|
44
|
+
test('validate a missing password property', async () => {
|
|
45
|
+
expect(() => {
|
|
46
|
+
util.password.validate();
|
|
47
|
+
}).toThrow('not-string');
|
|
48
|
+
}, 1000);
|
|
49
|
+
test('validate a non-string', async () => {
|
|
50
|
+
const password = { foo: 'bar' };
|
|
51
|
+
expect(() => {
|
|
52
|
+
util.password.validate(password);
|
|
53
|
+
}).toThrow('not-string');
|
|
54
|
+
}, 1000);
|
|
55
|
+
test('returns false for invalid passwords', async () => {
|
|
56
|
+
const someValid = [
|
|
57
|
+
'short',
|
|
58
|
+
'1234567a',
|
|
59
|
+
'123456aa',
|
|
60
|
+
'1aB!',
|
|
61
|
+
]
|
|
62
|
+
.map(util.password.isValid)
|
|
63
|
+
.some(val => val);
|
|
64
|
+
expect(someValid).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
test('returns true for a valid password', async () => {
|
|
67
|
+
const password = 'Password@123';
|
|
68
|
+
expect(util.password.isValid(password)).toBe(true);
|
|
69
|
+
});
|
|
44
70
|
});
|