rayid 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 AmirHossein Mohammadi
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,122 @@
1
+ # RayID
2
+
3
+ **RayID** is a generated code that we use to track logs, posts or events. You can generate your own rayid, but we made your job easier!
4
+
5
+ In this instructure you will learn about how to use this package in your apps.
6
+
7
+ ## Table of content
8
+
9
+ - [Installation](#installation)
10
+ - [methods](#methods)
11
+ - [Development](#development)
12
+
13
+ ## Installation
14
+
15
+ How to install **RayID**? To install this package, use **NPM**.
16
+
17
+ ```shell
18
+ $ npm i rayid
19
+ ```
20
+
21
+ ## Config
22
+
23
+ So, import the package.
24
+
25
+ ```javascript
26
+ // ESM 6 and higher
27
+ import RayID from "rayid";
28
+
29
+ // ESM 5 and lower
30
+ const RayID = require("rayid");
31
+ ```
32
+
33
+ Now create your instance with what kind of rayid you want.
34
+
35
+ - digit: Numbers
36
+ - lower: Alphabet in lower case.
37
+ - upper: Alphabet in upper case.
38
+
39
+ > No type means all combined togather.
40
+
41
+ ```javascript
42
+ const ray = new RayID("lower");
43
+ ```
44
+
45
+ ## Methods
46
+
47
+ Only one method! `gen()`.
48
+
49
+ ### `gen()`
50
+
51
+ in **gen()** just say the length.
52
+
53
+ > There is no limit :)
54
+
55
+ ```javascript
56
+ const r = ray.gen(50);
57
+ console.log(r); // zpciqivbkgoubrurrnozqhcdzlerjkllgtwbqbhllrxcremprd
58
+ ```
59
+
60
+ Or do it inside.
61
+
62
+ ```javascript
63
+ console.log(ray.gen(50)); // clherhvpkhwynhqhzluozionumnjqgjroeiymgqvlaknzjtdic
64
+ ```
65
+
66
+ All done!
67
+
68
+ ---
69
+
70
+ ## Development
71
+
72
+ If you want to develop the package, it is so simple. just follow steps below.
73
+
74
+ - Clone the project
75
+ - Install dependencies by running `$ npm install`
76
+ - Start changing!
77
+ - Link package
78
+ - Test
79
+
80
+ > Before you start: **Remember the base or code are stored in `lib/rayid.js`**. You need to edit there.
81
+
82
+ ### Cloning the project
83
+
84
+ To clone the project, you need to have git installed. Ok, now clone it same as command below.
85
+
86
+ ```shell
87
+ $ git clone https://gitlab.com/BlackIQ/rayid
88
+ ```
89
+
90
+ ### installing dependencies
91
+
92
+ Next, install what package uses with `npm i` or `npm install`.
93
+
94
+ ```shell
95
+ $ npm i
96
+ ```
97
+
98
+ ### Changing
99
+
100
+ To change package or anything, your need a testing environment to use linked package. Just follow steps.
101
+
102
+ #### Link package
103
+
104
+ We asoume you are in `lib` directory. Right. You can open a **tmux** or in another terminal to cd in `test` directory.
105
+
106
+ In `lib` directory enter link command:
107
+
108
+ ```shell
109
+ $ npm link
110
+ ```
111
+
112
+ So, in other terminal, or other tmux part, link your development package to your `test` directory. If you are in the `test` directory ok, if not, just say `cd test` and enter the linking command:
113
+
114
+ ```shell
115
+ $ npm link rayid
116
+ ```
117
+
118
+ Linking step is done.
119
+
120
+ #### Test
121
+
122
+ Your test app is linked. Change anything in package and test it in `test` directory.
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import RayID from "./lib/rayid.js";
2
+
3
+ export default RayID;
package/lib/rayid.js ADDED
@@ -0,0 +1,37 @@
1
+ const values = {
2
+ digit: "0123456789",
3
+ lower: "abcdefghijklmnopqrstuvwxyz",
4
+ upper: "abcdefghijklmnopqrstuvwxyz".toUpperCase(),
5
+ };
6
+
7
+ class RayID {
8
+ constructor(type) {
9
+ this.type = type;
10
+ }
11
+
12
+ characters = () => {
13
+ if (values[this.type] !== undefined) return values[this.type];
14
+ else {
15
+ let chars = "";
16
+
17
+ Object.values(values).map((value) => (chars += value));
18
+
19
+ return chars;
20
+ }
21
+ };
22
+
23
+ gen = (length) => {
24
+ let result = "";
25
+
26
+ const characters = this.characters();
27
+ const charactersLength = characters.length;
28
+
29
+ for (let i = 0; i < length; i++) {
30
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
31
+ }
32
+
33
+ return result;
34
+ };
35
+ }
36
+
37
+ export default RayID;
package/package.json ADDED
@@ -0,0 +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
+ }
package/test/test.js ADDED
@@ -0,0 +1,5 @@
1
+ import RayID from "rayid";
2
+
3
+ const ray = new RayID("lower");
4
+
5
+ console.log(ray.gen(50));