@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 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
@@ -1,7 +1,7 @@
1
- const password = require('./password');
1
+ import { password } from './password';
2
2
 
3
3
  const util = {
4
- password
5
- }
4
+ password,
5
+ };
6
6
 
7
7
  module.exports = util;
package/package.json CHANGED
@@ -1,14 +1,26 @@
1
1
  {
2
2
  "name": "@becollective/utils",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Common utilities",
5
- "main": "index.js",
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
- "jest": "^23.6.0"
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
@@ -1,4 +1,4 @@
1
- const password = {
1
+ export const password = {
2
2
  hasUppercase: (input) => {
3
3
  return !!input.match(/[A-Z]/);
4
4
  },
@@ -39,5 +39,3 @@ const password = {
39
39
  }
40
40
  }
41
41
  }
42
-
43
- module.exports = password;
@@ -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
+ };
@@ -1,4 +1,4 @@
1
- const util = require('../index.js');
1
+ const util = require('../bundle.js');
2
2
 
3
3
  describe('password.valiate', () => {
4
4
  test('validate a valid password', async () => {