@becollective/utils 1.0.2 → 1.0.4
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/bundle.js +48 -0
- package/index.js +3 -3
- package/package.json +16 -4
- package/password.js +1 -3
- package/rollup.config.js +20 -0
- package/tests/password.test.js +1 -1
package/bundle.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var password = {
|
|
4
|
+
hasUppercase: function hasUppercase(input) {
|
|
5
|
+
return !!input.match(/[A-Z]/);
|
|
6
|
+
},
|
|
7
|
+
hasLowerCase: function hasLowerCase(input) {
|
|
8
|
+
return !!input.match(/[a-z]/);
|
|
9
|
+
},
|
|
10
|
+
hasNumeral: function hasNumeral(input) {
|
|
11
|
+
return !!input.match(/[0-9]/);
|
|
12
|
+
},
|
|
13
|
+
hasSpecialCharacter: function hasSpecialCharacter(input) {
|
|
14
|
+
return !!input.match(/[!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]/);
|
|
15
|
+
},
|
|
16
|
+
validate: function validate(input) {
|
|
17
|
+
if (typeof input !== 'string') {
|
|
18
|
+
throw new Error('not-string');
|
|
19
|
+
} else if (input.length < 8) {
|
|
20
|
+
throw new Error('invalid-length');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var rules = 0;
|
|
24
|
+
if (password.hasUppercase(input)) rules++;
|
|
25
|
+
if (password.hasLowerCase(input)) rules++;
|
|
26
|
+
if (password.hasNumeral(input)) rules++;
|
|
27
|
+
if (password.hasSpecialCharacter(input)) rules++;
|
|
28
|
+
|
|
29
|
+
if (rules < 3) {
|
|
30
|
+
throw new Error('invalid-minimum-rules');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return true;
|
|
34
|
+
},
|
|
35
|
+
isValid: function isValid(input) {
|
|
36
|
+
try {
|
|
37
|
+
password.validate(input);
|
|
38
|
+
return true;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
var util = {
|
|
46
|
+
password: password
|
|
47
|
+
};
|
|
48
|
+
module.exports = util;
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@becollective/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Common utilities",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "bundle.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "NODE_ENV=localtest ./node_modules/.bin/jest tests/*"
|
|
7
|
+
"test": "NODE_ENV=localtest ./node_modules/.bin/jest tests/*",
|
|
8
|
+
"build": "./node_modules/.bin/rollup -c"
|
|
9
|
+
},
|
|
10
|
+
"husky": {
|
|
11
|
+
"hooks": {
|
|
12
|
+
"pre-push": "npm run build; npm test"
|
|
13
|
+
}
|
|
8
14
|
},
|
|
9
15
|
"author": "",
|
|
10
16
|
"license": "ISC",
|
|
11
17
|
"devDependencies": {
|
|
12
|
-
"
|
|
18
|
+
"@babel/core": "^7.1.6",
|
|
19
|
+
"@babel/preset-env": "^7.1.6",
|
|
20
|
+
"husky": "^1.1.4",
|
|
21
|
+
"jest": "^23.6.0",
|
|
22
|
+
"rollup": "^0.67.1",
|
|
23
|
+
"rollup-plugin-babel": "^4.0.3",
|
|
24
|
+
"rollup-plugin-node-resolve": "^3.4.0"
|
|
13
25
|
}
|
|
14
26
|
}
|
package/password.js
CHANGED
package/rollup.config.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import resolve from 'rollup-plugin-node-resolve';
|
|
2
|
+
import babel from 'rollup-plugin-babel';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
input: 'index.js',
|
|
6
|
+
output: {
|
|
7
|
+
file: 'bundle.js',
|
|
8
|
+
format: 'cjs'
|
|
9
|
+
},
|
|
10
|
+
plugins: [
|
|
11
|
+
resolve(),
|
|
12
|
+
babel({
|
|
13
|
+
exclude: 'node_modules/**', // only transpile our source code
|
|
14
|
+
babelrc: false,
|
|
15
|
+
presets: [
|
|
16
|
+
"@babel/preset-env",
|
|
17
|
+
],
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
};
|
package/tests/password.test.js
CHANGED