rayid 1.0.0 → 2.1.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/README.md CHANGED
@@ -35,6 +35,7 @@ Now create your instance with what kind of rayid you want.
35
35
  - digit: Numbers
36
36
  - lower: Alphabet in lower case.
37
37
  - upper: Alphabet in upper case.
38
+ - symbol: Symbols for password and stuff.
38
39
 
39
40
  > No type means all combined togather.
40
41
 
@@ -63,6 +64,26 @@ Or do it inside.
63
64
  console.log(ray.gen(50)); // clherhvpkhwynhqhzluozionumnjqgjroeiymgqvlaknzjtdic
64
65
  ```
65
66
 
67
+ ## Examples
68
+
69
+ Create common instances.
70
+
71
+ ```javascript
72
+ const ray = new RayID(); // All values
73
+ const srt = new RayID("lower"); // Loercase generator
74
+ const int = new RayID("digit"); // Only int generator
75
+ const sym = new RayID("symbol"); // Symbol generator
76
+ ```
77
+
78
+ Now use them:
79
+
80
+ ```javascript
81
+ console.log(ray.gen(10)); // Z*jVQ3c:+H
82
+ console.log(srt.gen(10)); // ksixvpqohi
83
+ console.log(int.gen(10)); // 4748182066
84
+ console.log(sym.gen(10)); // ?,^.+</::/
85
+ ```
86
+
66
87
  All done!
67
88
 
68
89
  ---
package/lib/rayid.js CHANGED
@@ -2,6 +2,7 @@ const values = {
2
2
  digit: "0123456789",
3
3
  lower: "abcdefghijklmnopqrstuvwxyz",
4
4
  upper: "abcdefghijklmnopqrstuvwxyz".toUpperCase(),
5
+ symbol: "!@#$%^&*()_+|}]{[:;?/>.<,`",
5
6
  };
6
7
 
7
8
  class RayID {
@@ -9,6 +10,19 @@ class RayID {
9
10
  this.type = type;
10
11
  }
11
12
 
13
+ engine = (length) => {
14
+ let result = "";
15
+
16
+ const characters = this.characters();
17
+ const charactersLength = characters.length;
18
+
19
+ for (let i = 0; i < length; i++) {
20
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
21
+ }
22
+
23
+ return result;
24
+ };
25
+
12
26
  characters = () => {
13
27
  if (values[this.type] !== undefined) return values[this.type];
14
28
  else {
@@ -21,16 +35,13 @@ class RayID {
21
35
  };
22
36
 
23
37
  gen = (length) => {
24
- let result = "";
25
-
26
- const characters = this.characters();
27
- const charactersLength = characters.length;
38
+ const generated = this.engine(length);
28
39
 
29
- for (let i = 0; i < length; i++) {
30
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
40
+ if (generated[0] === "0") {
41
+ return this.gen(length);
42
+ } else {
43
+ return generated;
31
44
  }
32
-
33
- return result;
34
45
  };
35
46
  }
36
47
 
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
- {
2
- "name": "rayid",
3
- "version": "1.0.0",
4
- "description": "RayID generator.",
5
- "main": "index.js",
6
- "type": "module",
7
- "directories": {
8
- "lib": "lib",
9
- "test": "test"
10
- },
11
- "scripts": {
12
- "test": "node index.js"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://gitlab.com/BlackIQ/rayid.git"
17
- },
18
- "keywords": [
19
- "RayID",
20
- "Express",
21
- "ID",
22
- "Code",
23
- "Generator"
24
- ],
25
- "author": "Amirhossein Mohammadi",
26
- "license": "MIT",
27
- "bugs": {
28
- "url": "https://gitlab.com/BlackIQ/rayid/issues"
29
- },
30
- "homepage": "https://gitlab.com/BlackIQ/rayid#readme"
31
- }
1
+ {
2
+ "name": "rayid",
3
+ "version": "2.1.2",
4
+ "description": "RayID generator.",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "directories": {
8
+ "lib": "lib",
9
+ "test": "test"
10
+ },
11
+ "scripts": {
12
+ "test": "node index.js"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://gitlab.com/BlackIQ/rayid.git"
17
+ },
18
+ "keywords": [
19
+ "RayID",
20
+ "Express",
21
+ "ID",
22
+ "Code",
23
+ "Generator"
24
+ ],
25
+ "author": "Amirhossein Mohammadi",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://gitlab.com/BlackIQ/rayid/issues"
29
+ },
30
+ "homepage": "https://gitlab.com/BlackIQ/rayid#readme"
31
+ }
package/test/test.js CHANGED
@@ -1,5 +1,11 @@
1
1
  import RayID from "rayid";
2
2
 
3
- const ray = new RayID("lower");
3
+ const ray = new RayID(); // All values
4
+ const srt = new RayID("lower"); // Loercase generator
5
+ const int = new RayID("digit"); // Only int generator
6
+ const sym = new RayID("symbol"); // Symbol generator
4
7
 
5
- console.log(ray.gen(50));
8
+ console.log("Random of everything: " + ray.gen(10)); // Z*jVQ3c:+H
9
+ console.log("String in lowercase: " + srt.gen(10)); // ksixvpqohi
10
+ console.log("Number, 0 is not first: " + int.gen(10)); // 4748182066
11
+ console.log("Some symbols stuff: " + sym.gen(10)); // ?,^.+</::/