@cocrepo/constants
v1.3.6
Published
Shared Constants and Configuration Values
Downloads
23
Readme
@cocrepo/constants
Shared constants and configuration values for the Cocrepo monorepo.
Overview
@cocrepo/constants provides centralized constant values, configuration options, and shared constants used across all applications and packages. This ensures consistency and makes it easy to update values in one place.
Features
- 🎯 Centralized Constants - Single source of truth for shared values
- 🔒 Type-Safe - Full TypeScript support
- 📦 Tree-Shakeable - Import only what you need
- ⚙️ Environment-Aware - Different values for dev/staging/production
- 🎨 Theme Constants - Colors, spacing, breakpoints
Installation
pnpm add @cocrepo/constantsUsage
API Configuration
import { API_BASE_URL, API_TIMEOUT, API_ENDPOINTS } from '@cocrepo/constants';
const fetchUsers = async () => {
const response = await fetch(`${API_BASE_URL}${API_ENDPOINTS.USERS}`, {
timeout: API_TIMEOUT
});
return response.json();
};Application Constants
import {
APP_NAME,
APP_VERSION,
DEFAULT_LOCALE,
SUPPORTED_LOCALES
} from '@cocrepo/constants';
function AppHeader() {
return (
<header>
<h1>{APP_NAME}</h1>
<span>v{APP_VERSION}</span>
</header>
);
}Theme & Design Tokens
import {
COLORS,
SPACING,
BREAKPOINTS,
FONT_SIZES,
Z_INDEX
} from '@cocrepo/constants';
const styles = {
padding: SPACING.md,
color: COLORS.primary[500],
fontSize: FONT_SIZES.lg,
zIndex: Z_INDEX.modal
};Validation Constants
import {
PASSWORD_MIN_LENGTH,
USERNAME_PATTERN,
EMAIL_PATTERN,
MAX_FILE_SIZE
} from '@cocrepo/constants';
const validatePassword = (password: string) => {
if (password.length < PASSWORD_MIN_LENGTH) {
return `Password must be at least ${PASSWORD_MIN_LENGTH} characters`;
}
return null;
};Route Constants
import { ROUTES, ADMIN_ROUTES, API_ROUTES } from '@cocrepo/constants';
function Navigation() {
return (
<nav>
<Link to={ROUTES.HOME}>Home</Link>
<Link to={ROUTES.DASHBOARD}>Dashboard</Link>
<Link to={ADMIN_ROUTES.USERS}>Users</Link>
</nav>
);
}Available Constants
Application
APP_NAME- Application nameAPP_VERSION- Current versionAPP_DESCRIPTION- Application descriptionDEFAULT_LOCALE- Default languageSUPPORTED_LOCALES- Supported languages
API Configuration
API_BASE_URL- Base API URLAPI_TIMEOUT- Request timeout (ms)API_RETRY_COUNT- Retry attemptsAPI_ENDPOINTS- Endpoint paths
Theme & Design
COLORS- Color paletteSPACING- Spacing scale (xs, sm, md, lg, xl)BREAKPOINTS- Responsive breakpointsFONT_SIZES- Font size scaleFONT_WEIGHTS- Font weight valuesBORDER_RADIUS- Border radius valuesSHADOWS- Box shadow presetsZ_INDEX- Z-index layers
Validation
PASSWORD_MIN_LENGTH- Minimum password lengthPASSWORD_MAX_LENGTH- Maximum password lengthUSERNAME_MIN_LENGTH- Minimum username lengthUSERNAME_PATTERN- Username regex patternEMAIL_PATTERN- Email regex patternPHONE_PATTERN- Phone number regex patternMAX_FILE_SIZE- Maximum file upload sizeALLOWED_FILE_TYPES- Permitted file types
Routes
ROUTES- Public route pathsADMIN_ROUTES- Admin route pathsAUTH_ROUTES- Authentication route pathsAPI_ROUTES- API endpoint paths
Feature Flags
FEATURES- Enabled/disabled featuresFEATURE_FLAGS- Environment-specific flags
Pagination
DEFAULT_PAGE_SIZE- Default items per pageMAX_PAGE_SIZE- Maximum items per pagePAGE_SIZE_OPTIONS- Available page sizes
Date & Time
DATE_FORMAT- Default date formatTIME_FORMAT- Default time formatDATETIME_FORMAT- Default datetime formatTIMEZONE- Default timezone
Environment-Specific Values
Values can change based on environment:
import { API_BASE_URL } from '@cocrepo/constants';
// Development: http://localhost:3006
// Staging: https://stg.cocdev.co.kr
// Production: https://cocdev.co.kr
console.log(API_BASE_URL);Best Practices
- Use Constants - Avoid magic numbers and strings
- Centralize Values - Don't duplicate constants across files
- Name Clearly - Use descriptive, uppercase names
- Group Logically - Organize by domain or purpose
- Document Usage - Add comments for complex values
Example: Feature Flag Pattern
import { FEATURES } from '@cocrepo/constants';
function FeatureComponent() {
if (!FEATURES.NEW_DASHBOARD) {
return <LegacyDashboard />;
}
return <NewDashboard />;
}Example: Responsive Design
import { BREAKPOINTS } from '@cocrepo/constants';
const mediaQueries = {
mobile: `@media (max-width: ${BREAKPOINTS.sm})`,
tablet: `@media (max-width: ${BREAKPOINTS.md})`,
desktop: `@media (min-width: ${BREAKPOINTS.lg})`
};Build
# Build the package
pnpm build
# Development mode with watch
pnpm start:devTypeScript Support
All constants are fully typed:
import type { ColorPalette, Spacing, Breakpoint } from '@cocrepo/constants';
const customColors: ColorPalette = {
primary: { 500: '#3b82f6' },
secondary: { 500: '#8b5cf6' }
};Adding New Constants
When adding new constants:
- Choose appropriate category - Add to existing or create new
- Use TypeScript - Define types for complex constants
- Document usage - Add JSDoc comments
- Export properly - Export from index
- Update README - Document the new constant
Example:
/**
* Maximum number of items to display in search results
* @default 50
*/
export const MAX_SEARCH_RESULTS = 50;
/**
* Debounce delay for search input in milliseconds
* @default 300
*/
export const SEARCH_DEBOUNCE_DELAY = 300;Testing
When changing constants, verify:
- [ ] No breaking changes in consuming apps
- [ ] Environment-specific values are correct
- [ ] TypeScript types are accurate
- [ ] Documentation is updated
Migration Guide
If a constant is renamed:
// Before
import { OLD_CONSTANT } from '@cocrepo/constants';
// After
import { NEW_CONSTANT } from '@cocrepo/constants';
// Deprecated (add temporary alias)
export const OLD_CONSTANT = NEW_CONSTANT;Performance
- ✅ Zero runtime overhead for most constants
- ✅ Tree-shakeable exports
- ✅ Optimized bundle size
- ✅ No circular dependencies
Contributing
Follow these guidelines:
- Constants should be truly shared (used in 2+ packages)
- Avoid package-specific values
- Use uppercase with underscores
- Group related constants
- Add types for complex structures
License
ISC
