generate-password-lite 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Ahmad Joya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,171 @@
1
+ <!-- prettier-ignore-start -->
2
+ <!-- SOMETHING AUTO-GENERATED BY TOOLS - START -->
3
+ <br />
4
+ <br />
5
+
6
+ <p align ="center">
7
+ <a href="https://nodei.co/npm/generate-password-lite" target="_blank">
8
+ <img src="https://nodei.co/npm/generate-password-lite.png" alt="npm Info" />
9
+ </a>
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="http://npm.im/generate-password-lite" target="_blank">
14
+ <img src="https://img.shields.io/npm/v/generate-password-lite.svg" alt="npm Version" />
15
+ </a>
16
+ <a href="http://npm.im/generate-password-lite" target="_blank">
17
+ <img src="https://img.shields.io/github/v/release/ahmadjoya/generate-password-lite" alt="npm Release Version" />
18
+ </a>
19
+ <a href="http://npm.im/generate-password-lite" target="_blank">
20
+ <img src="https://img.shields.io/npm/dm/generate-password-lite.svg" alt="npm Downloads" />
21
+ </a>
22
+ <a href="http://npm.im/generate-password-lite" target="_blank">
23
+ <img src="https://img.shields.io/npm/l/generate-password-lite.svg" alt="npm Package License" />
24
+ </a>
25
+ </p>
26
+
27
+ <p align="center">
28
+ <a href="https://github.com/ahmadjoya/generate-password-lite/stargazers" target="_blank">
29
+ <img src="https://img.shields.io/github/stars/ahmadjoya/generate-password-lite" alt="github Stars" />
30
+ </a>
31
+ <a href="https://github.com/ahmadjoya/generate-password-lite/network/members" target="_blank">
32
+ <img src="https://img.shields.io/github/forks/ahmadjoya/generate-password-lite" alt="github Forks" />
33
+ </a>
34
+ <a href="https://github.com/ahmadjoya/generate-password-lite/stargazers" target="_blank">
35
+ <img src="https://img.shields.io/github/contributors/ahmadjoya/generate-password-lite" alt="github Contributors" />
36
+ </a>
37
+ <a href="https://github.com/ahmadjoya/generate-password-lite/issues" target="_blank">
38
+ <img src="https://img.shields.io/github/issues/ahmadjoya/generate-password-lite" alt="github Issues" />
39
+ </a>
40
+ </p>
41
+
42
+ <br />
43
+
44
+ # generate-password-lite
45
+
46
+ generate-password-lite is usable for every typescript and typescript based project like react, vue, node, etc. it used to generate passwords that may contain alphabets, number and symbols. The options parameter enables the user to enable or disable the characters that are used to generate random password.
47
+
48
+ The characters that may be choosen from are
49
+
50
+ - Lowercase Characters
51
+ - Uppercase Characters
52
+ - Numbers
53
+ - Symbols
54
+
55
+ The user may also specify the minimum number of character for each type.
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ npm install generate-password-lite
61
+ ```
62
+
63
+ or
64
+
65
+ ```bash
66
+ yarn add generate-password-lite
67
+ ```
68
+
69
+ ## Usage
70
+
71
+ For the password to be generated, **parameters** are able to pass as an optional **options** object.
72
+
73
+ ```typescript
74
+ import { GeneratePassword } from "generate-password-lite";
75
+
76
+ const password = GeneratePassword({
77
+ length: 14,
78
+ symbols: true,
79
+ });
80
+
81
+ console.log(password);
82
+ ```
83
+
84
+ If no parameter is passed, the default parameter will be taken as :
85
+
86
+ ```typescript
87
+ options = {
88
+ length: 10,
89
+ lowercase: true,
90
+ uppercase: true,
91
+ numbers: true,
92
+ symbols: false,
93
+ exclude: "",
94
+ minLengthLowercase: 1,
95
+ minLengthUppercase: 1,
96
+ minLengthNumbers: 1,
97
+ minLengthSymbols: 0,
98
+ };
99
+ ```
100
+
101
+ ### Available options
102
+
103
+ Any of these can be passed into the options object for each function.
104
+
105
+ | Name | Description | Default Value |
106
+ | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
107
+ | length | Integer, length of password. | 10 |
108
+ | lowercase\* | Boolean, put lowercase letters in password | true |
109
+ | uppercase\* | Boolean, put uppercase letters in password. | true |
110
+ | numbers\* | Boolean, put numbers in password. | true |
111
+ | symbols\* | Boolean, put symbols in password. | false |
112
+ | exclude | String, characters to be excluded from password. | '' |
113
+ | minLengthLowercase | only if **lowercase** is set to **true**, minLengthLowercase will create a password that will have minimum number of lower case characters in the password. | 1 |
114
+ | minLengthUppercase | only if **uppercase** is set to **true**, minLengthUppercase will create a password that will have minimum number of upper case characters in the password. | 1 |
115
+ | minLengthNumbers | only if **numbers** is set to **true**, minLengthNumbers will create a password that will have minimum number of numbers in the password. | 1 |
116
+ | minLengthSymbols | only if **symbols** is set to **true**, minLengthSymbols will create a password that will have minimum number of symbols in the password. | 1 |
117
+
118
+ - At least one should be true.
119
+
120
+ ## Example
121
+
122
+ - **No Options passed.**
123
+
124
+ ```typescript
125
+ const { GeneratePassword } = "generate-password-lite";
126
+
127
+ const password = GeneratePassword();
128
+
129
+ console.log(password);
130
+ ```
131
+
132
+ In the above case, no parameter is passed as option. Therefore the default values will be taken - which will have alphabets, both upper and lower case, numbers, and will be of length 10 characters.
133
+
134
+ ```typescript
135
+ xDU6izb3PV;
136
+ ```
137
+
138
+ - **Length parameter passed.**
139
+
140
+ ```typescript
141
+ const password = GeneratePassword({ length: 25 });
142
+ console.log(password);
143
+ ```
144
+
145
+ The password generated is like this
146
+
147
+ ```typescript
148
+ U4c3KpQP5UrbZgTcrqMgFeI3R;
149
+ ```
150
+
151
+ - **exclude parameter passed.**
152
+
153
+ ```typescript
154
+ options = {
155
+ exclude : 'abc567XYZ';
156
+ }
157
+
158
+ password = GeneratePassword(options);
159
+
160
+ console.log(password);
161
+ ```
162
+
163
+ The generated password wouldn't has none of 'abc567XYZ' characters
164
+
165
+ ```typescript
166
+ J9yCfttQNj;
167
+ ```
168
+
169
+ ## License
170
+
171
+ generate-password-lite is licensed under the MIT License. See the [LICENSE](https://github.com/ahmadjoya/generate-password-lite#readme) file for more details.
@@ -0,0 +1,3 @@
1
+ import { GenerateOptions } from './types';
2
+ declare function GeneratePassword(options?: GenerateOptions): string;
3
+ export { GeneratePassword, type GenerateOptions };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e=function(e){return Math.floor(Math.random()*e)},n=function(n){var t="",s="",o=n.length,a=n.lowercase,m=n.uppercase,h=n.numbers,i=n.symbols,l=n.minLengthLowercase,c=n.minLengthUppercase,g=n.minLengthNumbers,u=n.minLengthSymbols,L=n.exclude,p="abcdefghijklmnopqrstuvwxyz";p=r(p,L);var b="ABCDEFGHIJKLMNOPQRSTUVWXYZ";b=r(b,L);var d="0123456789";d=r(d,L);var v="!#$%&'()*+,-./:;<=>?@[]^_{|}~";v=r(v,L);for(var w=p.length,f=0;f<l;f++)s+=p.charAt(e(w));w=b.length;for(f=0;f<c;f++)s+=b.charAt(e(w));w=d.length;for(f=0;f<g;f++)s+=d.charAt(e(w));w=v.length;for(f=0;f<u;f++)s+=v.charAt(e(w));t+=function(e){for(var n=e.split(""),r=n.length-1;r>0;r--){var t=Math.floor(Math.random()*(r+1)),s=n[r];n[r]=n[t],n[t]=s}return n.join("")}(s);var y="";y=a?y+p:y,y=m?y+b:y,y=h?y+d:y,y=i?y+v:y;var N=o-t.length;w=y.length;for(f=0;f<N;f++)t+=y.charAt(e(w));return t},r=function(e,n){return null==n||n.split("").forEach((function(n){e=e.replace(n,"")})),e},t=function(e){var n=e.length,r=e.lowercase,t=e.uppercase,s=e.numbers,o=e.symbols;if(e.minLengthLowercase+e.minLengthUppercase+e.minLengthNumbers+e.minLengthSymbols>n)throw new Error("Sum of Minimum Characters in the passwords greater than the length of the Password to be generated.");if(0==r&&0==t&&0==s&&0==o)throw new Error("Alphabets, Numbers and Symbols are all set to False. No valid Characters to generate the Password.")},s=function(e){return e.length=void 0===e.length?10:e.length,e.lowercase=void 0===e.lowercase||e.lowercase,e.uppercase=void 0===e.uppercase||e.uppercase,e.numbers=void 0===e.numbers||e.numbers,e.symbols=void 0!==e.symbols&&e.symbols,e.lowercase?e.minLengthLowercase=void 0===e.minLengthLowercase?1:e.minLengthLowercase:e.minLengthLowercase=0,e.uppercase?e.minLengthUppercase=void 0===e.minLengthUppercase?1:e.minLengthUppercase:e.minLengthUppercase=0,e.numbers?e.minLengthNumbers=void 0===e.minLengthNumbers?1:e.minLengthNumbers:e.minLengthNumbers=0,e.symbols?e.minLengthSymbols=void 0===e.minLengthSymbols?1:e.minLengthSymbols:e.minLengthSymbols=0,e.exclude=void 0===e.exclude?"":e.exclude,e};exports.GeneratePassword=function(e){return e?(e=s(e),t(e),n(e)):(e=s({length:10,lowercase:!0,uppercase:!0,numbers:!0,symbols:!1,exclude:"",minLengthLowercase:1,minLengthUppercase:1,minLengthNumbers:1,minLengthSymbols:0}),t(e),n(e))};
@@ -0,0 +1,2 @@
1
+ import { GenerateOptions } from '../types';
2
+ export declare const checkError: (options: GenerateOptions) => void;
@@ -0,0 +1 @@
1
+ export declare const generateRandomNumbers: (upperLimit: number) => number;
@@ -0,0 +1,2 @@
1
+ import { GenerateOptions } from '../types';
2
+ export declare const generatePswd: (options: GenerateOptions) => string;
@@ -0,0 +1,2 @@
1
+ import { GenerateOptions } from '../types';
2
+ export declare const processOption: (options: GenerateOptions) => GenerateOptions;
@@ -0,0 +1 @@
1
+ export declare const shuffleString: (str: string) => string;
@@ -0,0 +1,58 @@
1
+ interface GenerateOptions {
2
+ /**
3
+ * lenght of the password
4
+ * @default 10
5
+ */
6
+ length?: number
7
+ /**
8
+ * Should the password include lowercase characters
9
+ * @default true
10
+ */
11
+ lowercase?: boolean
12
+ /**
13
+ * Should the password include uppercase characters
14
+ * @default true
15
+ */
16
+ uppercase?: boolean
17
+ /**
18
+ * Should the password include numbers
19
+ * @default true
20
+ */
21
+ numbers?: boolean
22
+ /**
23
+ * Should the password include symbol characters
24
+ * @default false
25
+ */
26
+ symbols?: boolean
27
+ /**
28
+ * List of characters to be excluded from the password
29
+ * @default ""
30
+ */
31
+ exclude?: string
32
+ /**
33
+ * min lentgh of lowercase character
34
+ * @default 1
35
+ */
36
+ minLengthLowercase?: number
37
+ /**
38
+ * min lentgh of uppercase character
39
+ * @default 1
40
+ */
41
+ minLengthUppercase?: number
42
+ /**
43
+ * min length of numbers
44
+ * @default 1
45
+ */
46
+ minLengthNumbers?: number
47
+ /**
48
+ * min length of symbols
49
+ * @default 0
50
+ */
51
+ minLengthSymbols?: number
52
+ }
53
+
54
+ declare namespace GeneratePassword {}
55
+
56
+ declare function GeneratePassword(options?: GenerateOptions): string
57
+
58
+ export { type GenerateOptions, GeneratePassword };
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "generate-password-lite",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "description": "Password Generator for using in javascript/typescript based projects.",
6
+ "Author": "Ahmad Joya <joya.abn@gmail.com>",
7
+ "scripts": {
8
+ "build": "rollup -c"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/ahmadjoya/generate-password-lite.git"
13
+ },
14
+ "keywords": [
15
+ "generate password",
16
+ "generate-password-lite",
17
+ "password generator",
18
+ "password generator",
19
+ "random password generator",
20
+ "simple password generator",
21
+ "easy password generator",
22
+ "password",
23
+ "generator",
24
+ "unique",
25
+ "nodejs",
26
+ "nextjs",
27
+ "react",
28
+ "reactjs",
29
+ "random"
30
+ ],
31
+ "license": "ISC",
32
+ "bugs": {
33
+ "url": "https://github.com/ahmadjoya/generate-password-lite/issues"
34
+ },
35
+ "homepage": "https://github.com/ahmadjoya/generate-password-lite#readme",
36
+ "type": "module",
37
+ "main": "dist/index.js",
38
+ "types": "dist/index.d.ts",
39
+ "files": [
40
+ "dist"
41
+ ],
42
+ "bin": "./dist/index.js",
43
+ "devDependencies": {
44
+ "@rollup/plugin-commonjs": "^25.0.7",
45
+ "@rollup/plugin-node-resolve": "^15.2.3",
46
+ "@rollup/plugin-terser": "^0.4.4",
47
+ "rollup": "^4.6.1",
48
+ "rollup-plugin-dts": "^6.1.0",
49
+ "rollup-plugin-typescript2": "^0.36.0"
50
+ }
51
+ }