@owlmeans/basic-ids 0.1.2 → 0.1.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.
Files changed (3) hide show
  1. package/README.md +28 -116
  2. package/package.json +3 -2
  3. package/tsconfig.json +5 -9
package/README.md CHANGED
@@ -1,146 +1,58 @@
1
- # OwlMeans Basic IDs — Basic ID Generating Libraries
1
+ # @owlmeans/basic-ids
2
2
 
3
- A lightweight TypeScript library for generating various types of random and semi-random identifiers. This package is primarily used by the OwlMeans Authentication Subsystem and provides utilities for creating secure, random prefixes and IDs in different encoding formats.
3
+ Utilities for generating cryptographically secure random IDs and UUIDs.
4
+
5
+ ## Overview
6
+
7
+ - Fixed-length random IDs in Base58 or Base64 encoding
8
+ - UUID v4 generation
9
+ - Used throughout OwlMeans for generating run IDs, listener IDs, and entity identifiers
4
10
 
5
11
  ## Installation
6
12
 
7
13
  ```bash
8
- npm install @owlmeans/basic-ids
14
+ bun add @owlmeans/basic-ids
9
15
  ```
10
16
 
11
17
  ## Usage
12
18
 
13
19
  ```typescript
14
- import { createRandomPrefix, createIdOfLength, uuid, IdStyle } from '@owlmeans/basic-ids';
15
-
16
- // Generate a random prefix (default: 6 bytes, Base58 encoded)
17
- const prefix = createRandomPrefix();
18
-
19
- // Generate a specific length ID
20
- const shortId = createIdOfLength(8, IdStyle.Base58);
21
-
22
- // Generate a UUID v4
23
- const id = uuid();
24
- ```
25
-
26
- ## API Reference
20
+ import { createIdOfLength, createRandomPrefix, uuid } from '@owlmeans/basic-ids'
27
21
 
28
- ### IdStyle Enum
22
+ // Generate a 12-character Base58 ID (default encoding)
23
+ const runId = createIdOfLength(12)
29
24
 
30
- Defines the available encoding formats for generated IDs.
25
+ // Generate a random prefix (useful for namespaced IDs)
26
+ const prefix = createRandomPrefix(6)
31
27
 
32
- ```typescript
33
- enum IdStyle {
34
- Base58 = 'base58',
35
- Base64 = 'base64'
36
- }
28
+ // Standard UUID v4
29
+ const id = uuid()
37
30
  ```
38
31
 
39
- **Values:**
40
- - `Base58`: Uses Base58 encoding (default) - more compact, URL-safe, and avoids ambiguous characters
41
- - `Base64`: Uses Base64 URL-safe encoding without padding - standard web-safe encoding
42
-
43
- ### createRandomPrefix(length?, format?)
44
-
45
- Creates a random prefix using cryptographically secure random bytes.
46
-
47
- **Parameters:**
48
- - `length` (optional): `number` - Number of random bytes to generate (default: 6)
49
- - `format` (optional): `IdStyle` - Encoding format (default: `IdStyle.Base58`)
50
-
51
- **Returns:** `string` - The encoded random prefix
52
-
53
- **Example:**
54
- ```typescript
55
- // Generate 6-byte Base58 prefix (default)
56
- const prefix1 = createRandomPrefix();
57
-
58
- // Generate 10-byte Base64 prefix
59
- const prefix2 = createRandomPrefix(10, IdStyle.Base64);
60
-
61
- // Generate 4-byte Base58 prefix
62
- const prefix3 = createRandomPrefix(4, IdStyle.Base58);
63
- ```
64
-
65
- ### createIdOfLength(length?, format?)
66
-
67
- Creates an ID of a specific character length by generating random bytes and truncating the encoded result.
32
+ With explicit encoding:
68
33
 
69
- **Parameters:**
70
- - `length` (optional): `number` - Desired character length of the final ID (default: 6)
71
- - `format` (optional): `IdStyle` - Encoding format (default: `IdStyle.Base58`)
72
-
73
- **Returns:** `string` - The encoded ID trimmed to the specified length
74
-
75
- **Example:**
76
34
  ```typescript
77
- // Generate 6-character Base58 ID (default)
78
- const id1 = createIdOfLength();
79
-
80
- // Generate 12-character Base64 ID
81
- const id2 = createIdOfLength(12, IdStyle.Base64);
35
+ import { createIdOfLength, IdStyle } from '@owlmeans/basic-ids'
82
36
 
83
- // Generate 8-character Base58 ID
84
- const id3 = createIdOfLength(8, IdStyle.Base58);
37
+ const base64Id = createIdOfLength(16, IdStyle.Base64)
85
38
  ```
86
39
 
87
- **Note:** This function generates `length * 2` random bytes and then truncates the encoded result to the desired length to ensure sufficient entropy.
40
+ ## API
88
41
 
89
- ### uuid()
42
+ ### `createIdOfLength(length?, format?): string`
90
43
 
91
- Generates a standard UUID version 4 (random UUID).
44
+ Returns a random ID of exactly `length` characters (default: 6) in `format` encoding (default: Base58).
92
45
 
93
- **Returns:** `string` - A UUID v4 string in the format `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`
46
+ ### `createRandomPrefix(length?, format?): string`
94
47
 
95
- **Example:**
96
- ```typescript
97
- const id = uuid();
98
- // Example output: "f47ac10b-58cc-4372-a567-0e02b2c3d479"
99
- ```
48
+ Returns a random string encoded from `length` random bytes (default: 6 bytes).
100
49
 
101
- ## Use Cases
50
+ ### `uuid(): string`
102
51
 
103
- ### Authentication Tokens
104
- ```typescript
105
- // Generate a session prefix
106
- const sessionPrefix = createRandomPrefix(8, IdStyle.Base58);
52
+ Returns a UUID v4 string.
107
53
 
108
- // Generate a short API key
109
- const apiKey = createIdOfLength(32, IdStyle.Base64);
110
- ```
54
+ ### `IdStyle`
111
55
 
112
- ### Resource Identifiers
113
56
  ```typescript
114
- // Generate short resource IDs
115
- const resourceId = createIdOfLength(10);
116
-
117
- // Generate unique request IDs
118
- const requestId = uuid();
57
+ enum IdStyle { Base58 = 'base58', Base64 = 'base64' }
119
58
  ```
120
-
121
- ### Database Keys
122
- ```typescript
123
- // Generate compact database keys
124
- const dbKey = createRandomPrefix(12, IdStyle.Base58);
125
- ```
126
-
127
- ## Security Considerations
128
-
129
- - All random functions use cryptographically secure random number generation via `@noble/hashes`
130
- - Base58 encoding avoids ambiguous characters (0, O, l, I) making IDs more user-friendly
131
- - Base64 encoding provides standard web-safe encoding
132
- - The `createIdOfLength` function generates extra entropy to compensate for truncation
133
-
134
- ## Dependencies
135
-
136
- - `@noble/hashes` - Cryptographic hashing and random number generation
137
- - `@scure/base` - Base encoding utilities (Base58, Base64)
138
- - `uuid` - UUID generation
139
-
140
- ## Part of OwlMeans Common
141
-
142
- This package is part of the OwlMeans Common library ecosystem. For more information about the overall architecture and concepts, see the [main README](../../README.md).
143
-
144
- ## License
145
-
146
- See the [LICENSE](../../LICENSE) file in the root directory.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/basic-ids",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -21,9 +21,10 @@
21
21
  }
22
22
  },
23
23
  "devDependencies": {
24
+ "@owlmeans/dep-config": "workspace:*",
24
25
  "@types/uuid": "^10.0.0",
25
26
  "nodemon": "^3.1.11",
26
- "typescript": "^5.8.3"
27
+ "typescript": "^6.0.2"
27
28
  },
28
29
  "dependencies": {
29
30
  "@noble/hashes": "^1.5.0",
package/tsconfig.json CHANGED
@@ -1,14 +1,10 @@
1
1
  {
2
2
  "extends": [
3
- "../tsconfig.default.json",
3
+ "@owlmeans/dep-config/tsconfig.base.json"
4
4
  ],
5
5
  "compilerOptions": {
6
- "rootDir": "./src/", /* Specify the root folder within your source files. */
7
- "outDir": "./build/", /* Specify an output folder for all emitted files. */
6
+ "rootDir": "./src/",
7
+ "outDir": "./build/"
8
8
  },
9
- "exclude": [
10
- "./dist/**/*",
11
- "./build/**/*",
12
- "./*.ts"
13
- ]
14
- }
9
+ "exclude": ["./dist/**/*", "./build/**/*", "./*.ts"]
10
+ }