@grest-ts/common
v0.0.20
Published
Common utility functions and types shared across all GG packages
Maintainers
Readme
Part of the grest-ts framework. Documentation | All packages
@grest-ts/common
Common utility functions and types shared across all GG packages.
Purpose
This package contains utility functions and types that are used across multiple packages in the Grest framework. By consolidating them here, we:
- Eliminate code duplication
- Ensure consistency across packages
- Make maintenance easier
- Reduce package dependencies
Utilities
deepFreeze<T>(obj: T): T
Recursively freezes an object and all its nested properties, making it immutable.
import { deepFreeze } from '@grest-ts/common';
const config = deepFreeze({
name: 'app',
settings: {
debug: true
}
});
// This will throw an error in strict mode
config.settings.debug = false;withTimeout<T>(promise: Promise<T>, timeoutMs: number, errorMessage: string): Promise<T>
Wraps a promise with a timeout. If the promise doesn't resolve/reject within the specified timeout, the returned promise will reject with an error.
import { withTimeout } from '@grest-ts/common';
const result = await withTimeout(
fetch('https://api.example.com'),
5000,
'API request timed out'
);Types
DeepPartial<T>
Recursively makes all properties of an object optional. Useful for partial matching in tests and validation.
import { DeepPartial } from '@grest-ts/common';
interface User {
id: string;
profile: {
name: string;
email: string;
};
}
// All properties are optional
const partialUser: DeepPartial<User> = {
profile: {
name: 'Alice'
// email is optional
}
};Adding New Utilities
When adding new utilities to this package:
- Create a new file in
src/for the utility - Export it from
src/index.ts - Add JSDoc comments explaining usage
- Update this README with examples
- Ensure the utility is truly reusable across multiple packages
