@nemigo/helpers 0.0.2 → 0.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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Генератор случайных кодов
3
+ */
4
+ export declare const rand: (length?: number) => string;
5
+ /**
6
+ * Генератор случайных ID ( {@link Date.now}:{@link rand} )
7
+ */
8
+ export declare const randID: (length?: number) => string;
9
+ /**
10
+ * Генератор случайных UID
11
+ */
12
+ export declare const randUID: (table?: string, length?: number) => string;
package/dist/random.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Генератор случайных кодов
3
+ */
4
+ export const rand = (length = 6) => {
5
+ const min = Math.pow(10, length - 1);
6
+ return Math.floor(min + Math.random() * 9 * min).toString();
7
+ };
8
+ /**
9
+ * Генератор случайных ID ( {@link Date.now}:{@link rand} )
10
+ */
11
+ export const randID = (length = 7) => `${Date.now()}:${rand(length)}`;
12
+ /**
13
+ * Генератор случайных UID
14
+ */
15
+ export const randUID = (table, length = 20) => {
16
+ const UID = "abcdefghijklmnopqrstuvwxyz0123456789"; // 36 символов
17
+ let uid = "";
18
+ for (let i = 0; i < length; i++)
19
+ uid += UID[Math.floor(Math.random() * 36)];
20
+ return table ? `${table}:${uid}` : uid;
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/helpers",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Vlad Logvin",
@@ -12,7 +12,8 @@
12
12
  "check": "tsc --noemit",
13
13
  "lint": "eslint ./",
14
14
  "test": "vitest --run",
15
- "format": "prettier --write ./"
15
+ "format": "prettier --write ./",
16
+ "publish": "npm publish"
16
17
  },
17
18
  "exports": {
18
19
  "./msgpack": {