@togatherlabs/shared-utils 1.0.0 → 1.0.1
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 +175 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -1 +1,175 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @togatherlabs/shared-utils
|
|
2
|
+
|
|
3
|
+
A collection of **shared TypeScript utilities, constants, and types** used across ToGather microservices.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@togatherlabs/shared-utils)
|
|
6
|
+
[](https://www.npmjs.com/package/@togatherlabs/shared-utils)
|
|
7
|
+
[](./LICENSE)
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
1. [Directory Structure](#directory-structure)
|
|
12
|
+
2. [Package Development](#package-development)
|
|
13
|
+
|
|
14
|
+
* [Adding New Utilities](#adding-new-utilities)
|
|
15
|
+
* [Linting](#linting)
|
|
16
|
+
* [Building](#building)
|
|
17
|
+
* [Publishing Package](#publishing-package)
|
|
18
|
+
3. [Using the Utilities](#using-the-utilities)
|
|
19
|
+
|
|
20
|
+
* [TypeScript](#typescript)
|
|
21
|
+
4. [Best Practices](#best-practices)
|
|
22
|
+
5. [Troubleshooting](#troubleshooting)
|
|
23
|
+
6. [License](#license)
|
|
24
|
+
|
|
25
|
+
## Directory Structure
|
|
26
|
+
|
|
27
|
+
The package follows a **clear folder structure** for maintainability:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
src/
|
|
31
|
+
├── constants/
|
|
32
|
+
│ └── index.ts
|
|
33
|
+
├── utils/
|
|
34
|
+
│ └── index.ts
|
|
35
|
+
├── types/
|
|
36
|
+
│ └── index.ts
|
|
37
|
+
└── index.ts
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
* **constants**: Shared constants across services
|
|
41
|
+
* **utils**: Reusable utility functions
|
|
42
|
+
* **types**: Shared TypeScript types and interfaces
|
|
43
|
+
* **index.ts**: Exports all public utilities
|
|
44
|
+
|
|
45
|
+
## Package Development
|
|
46
|
+
|
|
47
|
+
### Adding New Utilities
|
|
48
|
+
|
|
49
|
+
1. Add your function, constant, or type in the appropriate folder (`utils`, `constants`, or `types`).
|
|
50
|
+
2. Export it from the folder’s `index.ts`.
|
|
51
|
+
3. Re-export from the root `index.ts` for public usage.
|
|
52
|
+
|
|
53
|
+
**Example:** Adding a new utility `capitalize`:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
// src/utils/capitalize.ts
|
|
57
|
+
export function capitalize(str: string): string {
|
|
58
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/utils/index.ts
|
|
62
|
+
export * from './capitalize';
|
|
63
|
+
|
|
64
|
+
// src/index.ts
|
|
65
|
+
export * from './utils';
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Linting
|
|
69
|
+
|
|
70
|
+
Check code style and catch errors using Biome:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pnpm lint
|
|
74
|
+
pnpm lint:fix
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Building
|
|
78
|
+
|
|
79
|
+
Compile TypeScript into the `dist/` folder:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pnpm build
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Check types without generating output:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pnpm typecheck
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Publishing Package
|
|
92
|
+
|
|
93
|
+
To publish the package to npm:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pnpm run release
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
This script performs:
|
|
100
|
+
|
|
101
|
+
* Builds the package
|
|
102
|
+
* Commits changes
|
|
103
|
+
* Updates version (patch/minor/major)
|
|
104
|
+
* Publishes to npm with public access
|
|
105
|
+
|
|
106
|
+
Ensure all changes are committed and tests pass before publishing.
|
|
107
|
+
|
|
108
|
+
## Using the Utilities
|
|
109
|
+
|
|
110
|
+
### TypeScript
|
|
111
|
+
|
|
112
|
+
Install the package:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
pnpm add @togatherlabs/shared-utils
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Example usage:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { formatDate, generateId, logger } from '@togatherlabs/shared-utils';
|
|
122
|
+
|
|
123
|
+
// Format a date
|
|
124
|
+
console.log(formatDate(new Date()));
|
|
125
|
+
|
|
126
|
+
// Generate a unique ID
|
|
127
|
+
const id = generateId();
|
|
128
|
+
console.log(id);
|
|
129
|
+
|
|
130
|
+
// Log messages
|
|
131
|
+
logger.info('Service started');
|
|
132
|
+
logger.error('Failed to fetch data', { error: new Error('Network error') });
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Best Practices
|
|
136
|
+
|
|
137
|
+
* Keep utilities small and focused – each function should have a single responsibility.
|
|
138
|
+
* Type safety – use TypeScript types/interfaces, avoid `any`.
|
|
139
|
+
* Documentation – add JSDoc comments for each utility.
|
|
140
|
+
* Testing – write unit tests for every new utility.
|
|
141
|
+
* Consistent exports – always export utilities through `index.ts` files.
|
|
142
|
+
|
|
143
|
+
## Troubleshooting
|
|
144
|
+
|
|
145
|
+
**Cannot find module '@togatherlabs/shared-utils'**
|
|
146
|
+
|
|
147
|
+
* Ensure the package is installed
|
|
148
|
+
* Check `tsconfig.json` paths if using path aliases
|
|
149
|
+
* Delete `node_modules` and reinstall dependencies
|
|
150
|
+
|
|
151
|
+
**Property 'myFunction' does not exist**
|
|
152
|
+
|
|
153
|
+
* Ensure the function is exported correctly
|
|
154
|
+
* Verify the import path matches the package export
|
|
155
|
+
|
|
156
|
+
**Build errors**
|
|
157
|
+
|
|
158
|
+
* Check for missing peer dependencies
|
|
159
|
+
* Ensure relative imports are correct
|
|
160
|
+
* Clean and rebuild the project
|
|
161
|
+
|
|
162
|
+
**Version mismatches across services**
|
|
163
|
+
|
|
164
|
+
* Make sure all services use compatible versions of shared-utils
|
|
165
|
+
* Check changelog for breaking changes
|
|
166
|
+
|
|
167
|
+
**TypeScript declaration errors**
|
|
168
|
+
|
|
169
|
+
* Ensure `declaration: true` is set in `tsconfig.json`
|
|
170
|
+
* Verify the `types` field in `package.json` points to the correct declaration file
|
|
171
|
+
* Run `pnpm build` to regenerate type definitions
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT © ToGather Labs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@togatherlabs/shared-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Shared utility functions, constants, and types for ToGather microservices",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -55,7 +55,11 @@
|
|
|
55
55
|
"test:ui": "vitest --ui",
|
|
56
56
|
"commit": "git-cz",
|
|
57
57
|
"package:patch": "pnpm version patch",
|
|
58
|
+
"package:minor": "pnpm version minor",
|
|
59
|
+
"package:major": "pnpm version major",
|
|
58
60
|
"package:publish": "pnpm publish --access public",
|
|
59
|
-
"release": "pnpm build && git add . && pnpm commit && pnpm package:patch && git push --follow-tags && pnpm package:publish"
|
|
61
|
+
"release:patch": "pnpm build && git add . && pnpm commit && pnpm package:patch && git push --follow-tags && pnpm package:publish",
|
|
62
|
+
"release:minor": "pnpm build && git add . && pnpm commit && pnpm package:minor && git push --follow-tags && pnpm package:publish",
|
|
63
|
+
"release:major": "pnpm build && git add . && pnpm commit && pnpm package:major && git push --follow-tags && pnpm package:publish"
|
|
60
64
|
}
|
|
61
65
|
}
|