@systemix/password 0.0.3 → 0.2.0
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/dist/index.cjs +27 -19
- package/dist/index.js +26 -18
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -57,9 +57,6 @@ var GeneratePasswordPropsEnum = /* @__PURE__ */ ((GeneratePasswordPropsEnum2) =>
|
|
|
57
57
|
return GeneratePasswordPropsEnum2;
|
|
58
58
|
})(GeneratePasswordPropsEnum || {});
|
|
59
59
|
|
|
60
|
-
// src/functions/generate.function.ts
|
|
61
|
-
var import_node_crypto = require("crypto");
|
|
62
|
-
|
|
63
60
|
// src/utils/error.message.ts
|
|
64
61
|
var lengthError = {
|
|
65
62
|
invalidLength: "Invalid length. Length must be a positive number.",
|
|
@@ -108,11 +105,13 @@ function generatePasswordPropValidation(props) {
|
|
|
108
105
|
customLowercase,
|
|
109
106
|
customSymbols
|
|
110
107
|
} = props;
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
if (length !== void 0) {
|
|
109
|
+
if (typeof length !== "number" || length < 1) {
|
|
110
|
+
throw new Error(lengthError.invalidLength);
|
|
111
|
+
}
|
|
112
|
+
if (length > 100) {
|
|
113
|
+
throw new Error(lengthError.lengthTooLarge);
|
|
114
|
+
}
|
|
116
115
|
}
|
|
117
116
|
const checkMin = (val, name) => {
|
|
118
117
|
if (val !== void 0 && (typeof val !== "number" || val < 0)) {
|
|
@@ -124,7 +123,8 @@ function generatePasswordPropValidation(props) {
|
|
|
124
123
|
checkMin(minLowercase, "minLowercase");
|
|
125
124
|
checkMin(minSymbols, "minSymbols");
|
|
126
125
|
const totalMin = (minNumbers ?? 0) + (minUppercase ?? 0) + (minLowercase ?? 0) + (minSymbols ?? 0);
|
|
127
|
-
|
|
126
|
+
const len = length ?? 12;
|
|
127
|
+
if (totalMin > len) {
|
|
128
128
|
throw new Error(
|
|
129
129
|
"Total minimum character requirements exceed requested password length."
|
|
130
130
|
);
|
|
@@ -138,36 +138,44 @@ function generatePasswordPropValidation(props) {
|
|
|
138
138
|
checkString(customUppercase, "customUppercase");
|
|
139
139
|
checkString(customLowercase, "customLowercase");
|
|
140
140
|
checkString(customSymbols, "customSymbols");
|
|
141
|
-
if (typeof useNumbers !== "boolean") {
|
|
141
|
+
if (useNumbers !== void 0 && typeof useNumbers !== "boolean") {
|
|
142
142
|
throw new Error(useNumbersError);
|
|
143
143
|
}
|
|
144
|
-
if (typeof useUppercase !== "boolean") {
|
|
144
|
+
if (useUppercase !== void 0 && typeof useUppercase !== "boolean") {
|
|
145
145
|
throw new Error(useUppercaseError);
|
|
146
146
|
}
|
|
147
|
-
if (typeof useLowercase !== "boolean") {
|
|
147
|
+
if (useLowercase !== void 0 && typeof useLowercase !== "boolean") {
|
|
148
148
|
throw new Error(useLowercaseError);
|
|
149
149
|
}
|
|
150
|
-
if (typeof useSymbols !== "boolean") {
|
|
150
|
+
if (useSymbols !== void 0 && typeof useSymbols !== "boolean") {
|
|
151
151
|
throw new Error(useSymbolsError);
|
|
152
152
|
}
|
|
153
|
-
if (typeof excludeSimilarCharacters !== "boolean") {
|
|
153
|
+
if (excludeSimilarCharacters !== void 0 && typeof excludeSimilarCharacters !== "boolean") {
|
|
154
154
|
throw new Error(excludeSimilarCharactersError);
|
|
155
155
|
}
|
|
156
|
-
if (typeof exclude !== "string") {
|
|
156
|
+
if (exclude !== void 0 && typeof exclude !== "string") {
|
|
157
157
|
throw new Error(excludeError);
|
|
158
158
|
}
|
|
159
|
-
if (typeof count !== "number" || count < 1) {
|
|
159
|
+
if (count !== void 0 && (typeof count !== "number" || count < 1)) {
|
|
160
160
|
throw new Error(countError.invalidCount);
|
|
161
161
|
}
|
|
162
|
-
if (count > 10) {
|
|
162
|
+
if (count !== void 0 && count > 10) {
|
|
163
163
|
throw new Error(countError.countTooLarge);
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
const uN = useNumbers ?? true;
|
|
166
|
+
const uU = useUppercase ?? true;
|
|
167
|
+
const uL = useLowercase ?? true;
|
|
168
|
+
const uS = useSymbols ?? false;
|
|
169
|
+
if (!uN && !uU && !uL && !uS) {
|
|
166
170
|
throw new Error(allOptionsFalseError);
|
|
167
171
|
}
|
|
168
172
|
}
|
|
169
173
|
|
|
170
174
|
// src/functions/generate.function.ts
|
|
175
|
+
var crypto = globalThis.crypto;
|
|
176
|
+
if (!crypto) {
|
|
177
|
+
throw new Error("Crypto not available. Requires Node 18+ or browser.");
|
|
178
|
+
}
|
|
171
179
|
function calculatePasswordEntropy(length, charsetSize) {
|
|
172
180
|
if (length <= 0 || charsetSize <= 0) return 0;
|
|
173
181
|
return length * Math.log2(charsetSize);
|
|
@@ -178,7 +186,7 @@ function getRandomInt(max) {
|
|
|
178
186
|
const range = Math.floor(4294967295 / max) * max;
|
|
179
187
|
let randomValue;
|
|
180
188
|
do {
|
|
181
|
-
|
|
189
|
+
crypto.getRandomValues(array);
|
|
182
190
|
randomValue = array[0];
|
|
183
191
|
} while (randomValue >= range);
|
|
184
192
|
return randomValue % max;
|
package/dist/index.js
CHANGED
|
@@ -19,9 +19,6 @@ var GeneratePasswordPropsEnum = /* @__PURE__ */ ((GeneratePasswordPropsEnum2) =>
|
|
|
19
19
|
return GeneratePasswordPropsEnum2;
|
|
20
20
|
})(GeneratePasswordPropsEnum || {});
|
|
21
21
|
|
|
22
|
-
// src/functions/generate.function.ts
|
|
23
|
-
import { webcrypto as crypto } from "crypto";
|
|
24
|
-
|
|
25
22
|
// src/utils/error.message.ts
|
|
26
23
|
var lengthError = {
|
|
27
24
|
invalidLength: "Invalid length. Length must be a positive number.",
|
|
@@ -70,11 +67,13 @@ function generatePasswordPropValidation(props) {
|
|
|
70
67
|
customLowercase,
|
|
71
68
|
customSymbols
|
|
72
69
|
} = props;
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
if (length !== void 0) {
|
|
71
|
+
if (typeof length !== "number" || length < 1) {
|
|
72
|
+
throw new Error(lengthError.invalidLength);
|
|
73
|
+
}
|
|
74
|
+
if (length > 100) {
|
|
75
|
+
throw new Error(lengthError.lengthTooLarge);
|
|
76
|
+
}
|
|
78
77
|
}
|
|
79
78
|
const checkMin = (val, name) => {
|
|
80
79
|
if (val !== void 0 && (typeof val !== "number" || val < 0)) {
|
|
@@ -86,7 +85,8 @@ function generatePasswordPropValidation(props) {
|
|
|
86
85
|
checkMin(minLowercase, "minLowercase");
|
|
87
86
|
checkMin(minSymbols, "minSymbols");
|
|
88
87
|
const totalMin = (minNumbers ?? 0) + (minUppercase ?? 0) + (minLowercase ?? 0) + (minSymbols ?? 0);
|
|
89
|
-
|
|
88
|
+
const len = length ?? 12;
|
|
89
|
+
if (totalMin > len) {
|
|
90
90
|
throw new Error(
|
|
91
91
|
"Total minimum character requirements exceed requested password length."
|
|
92
92
|
);
|
|
@@ -100,36 +100,44 @@ function generatePasswordPropValidation(props) {
|
|
|
100
100
|
checkString(customUppercase, "customUppercase");
|
|
101
101
|
checkString(customLowercase, "customLowercase");
|
|
102
102
|
checkString(customSymbols, "customSymbols");
|
|
103
|
-
if (typeof useNumbers !== "boolean") {
|
|
103
|
+
if (useNumbers !== void 0 && typeof useNumbers !== "boolean") {
|
|
104
104
|
throw new Error(useNumbersError);
|
|
105
105
|
}
|
|
106
|
-
if (typeof useUppercase !== "boolean") {
|
|
106
|
+
if (useUppercase !== void 0 && typeof useUppercase !== "boolean") {
|
|
107
107
|
throw new Error(useUppercaseError);
|
|
108
108
|
}
|
|
109
|
-
if (typeof useLowercase !== "boolean") {
|
|
109
|
+
if (useLowercase !== void 0 && typeof useLowercase !== "boolean") {
|
|
110
110
|
throw new Error(useLowercaseError);
|
|
111
111
|
}
|
|
112
|
-
if (typeof useSymbols !== "boolean") {
|
|
112
|
+
if (useSymbols !== void 0 && typeof useSymbols !== "boolean") {
|
|
113
113
|
throw new Error(useSymbolsError);
|
|
114
114
|
}
|
|
115
|
-
if (typeof excludeSimilarCharacters !== "boolean") {
|
|
115
|
+
if (excludeSimilarCharacters !== void 0 && typeof excludeSimilarCharacters !== "boolean") {
|
|
116
116
|
throw new Error(excludeSimilarCharactersError);
|
|
117
117
|
}
|
|
118
|
-
if (typeof exclude !== "string") {
|
|
118
|
+
if (exclude !== void 0 && typeof exclude !== "string") {
|
|
119
119
|
throw new Error(excludeError);
|
|
120
120
|
}
|
|
121
|
-
if (typeof count !== "number" || count < 1) {
|
|
121
|
+
if (count !== void 0 && (typeof count !== "number" || count < 1)) {
|
|
122
122
|
throw new Error(countError.invalidCount);
|
|
123
123
|
}
|
|
124
|
-
if (count > 10) {
|
|
124
|
+
if (count !== void 0 && count > 10) {
|
|
125
125
|
throw new Error(countError.countTooLarge);
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
const uN = useNumbers ?? true;
|
|
128
|
+
const uU = useUppercase ?? true;
|
|
129
|
+
const uL = useLowercase ?? true;
|
|
130
|
+
const uS = useSymbols ?? false;
|
|
131
|
+
if (!uN && !uU && !uL && !uS) {
|
|
128
132
|
throw new Error(allOptionsFalseError);
|
|
129
133
|
}
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
// src/functions/generate.function.ts
|
|
137
|
+
var crypto = globalThis.crypto;
|
|
138
|
+
if (!crypto) {
|
|
139
|
+
throw new Error("Crypto not available. Requires Node 18+ or browser.");
|
|
140
|
+
}
|
|
133
141
|
function calculatePasswordEntropy(length, charsetSize) {
|
|
134
142
|
if (length <= 0 || charsetSize <= 0) return 0;
|
|
135
143
|
return length * Math.log2(charsetSize);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@systemix/password",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"eslint": "^10.0.0",
|
|
43
43
|
"tsup": "^8.5.1",
|
|
44
44
|
"typescript": "^5.9.3",
|
|
45
|
-
"@systemix/eslint": "0.
|
|
46
|
-
"@systemix/typescript": "0.
|
|
45
|
+
"@systemix/eslint": "0.3.0",
|
|
46
|
+
"@systemix/typescript": "0.3.0"
|
|
47
47
|
},
|
|
48
48
|
"directories": {
|
|
49
49
|
"test": "tests"
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
],
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
65
|
+
"test": "pnpm build && node tests/test.mjs",
|
|
65
66
|
"typecheck": "tsc --noEmit",
|
|
66
67
|
"lint": "eslint .",
|
|
67
68
|
"lint:fix": "eslint . --fix",
|