abc-router
v0.0.7
Published
router
Readme
abc-router
Router utilities package for generating URLs and managing routing in the ABC system. This package provides functions for creating consistent URL patterns across different application types.
📦 Installation
pnpm add abc-router🚀 Key Features
1. URL Generation
- Generate consistent router paths for applications
- Support for different app types (single, state, parent)
- Query parameter handling and URL encoding
2. Study Link Generation
- Create study links for practice tests
- Support for full-length tests
- State-specific URL generation
3. Flexible Routing
- Dynamic path building based on parameters
- Clean URL generation with proper formatting
- Support for nested routing structures
📚 API Reference
generateRouterApp(options)
Generate a router path based on provided parameters.
import { generateRouterApp } from "abc-router";
const path = generateRouterApp({
app: "test-app",
state: "california",
linkTo: "resolve",
payload: { resultId: 123, attemptNumber: 1 },
});
// Returns: "/test-app/california/resolve?resultId=123&attemptNumber=1"Parameters:
app?: string- The application namestate?: string- The state parameterlinkTo?: string- The target link (will be cleaned if starts with '/')payload?: Record<string, any>- Query parameters to append to the URL
Examples:
// Basic app routing
generateRouterApp({
app: "asvab",
linkTo: "practice",
});
// Returns: "/asvab/practice"
// State-specific routing
generateRouterApp({
app: "cdl",
state: "california",
linkTo: "test",
});
// Returns: "/cdl/california/test"
// With query parameters
generateRouterApp({
app: "asvab",
linkTo: "result",
payload: { score: 85, time: "30min" },
});
// Returns: "/asvab/result?score=85&time=30min"
// Clean linkTo (removes leading slash)
generateRouterApp({
app: "test",
linkTo: "/resolve",
});
// Returns: "/test/resolve"genStudyLink(options)
Generate study links for practice tests and full-length tests.
import { genStudyLink } from "abc-router";
const studyLink = genStudyLink({
appShortName: "asvab",
tag: "practice-questions",
fullTest: false,
});
// Returns: "asvab-practice-questions-practice-test"Parameters:
appShortName: string- Short name of the applicationtag: string- Tag to categorize the testfullTest?: boolean- Whether it's a full-length test (default: false)state?: string- State parameter (optional)isParent?: boolean- Whether it's a parent app (default: false)
Examples:
// Practice test link
genStudyLink({
appShortName: "asvab",
tag: "math",
fullTest: false,
});
// Returns: "asvab-math-practice-test"
// Full-length test link
genStudyLink({
appShortName: "asvab",
tag: "comprehensive",
fullTest: true,
});
// Returns: "full-length-asvab-comprehensive-practice-test"
// State-specific link
genStudyLink({
appShortName: "cdl",
tag: "general",
state: "california",
});
// Returns: "cdl-california-general-questions"
// Parent app link (cleaned URL)
genStudyLink({
appShortName: "easyprep",
tag: "practice",
isParent: true,
});
// Returns: "practice-practice-test"handleLink(options)
Handle link generation for state-specific routing.
import { handleLink } from "abc-router";
const link = handleLink({
appShortName: "asvab",
tag: "math",
state: "california",
});
// Returns: "california/asvab-math-questions"Parameters:
appShortName: string- Short name of the applicationtag: string- Tag to categorize the teststate?: string- State parameter (optional)
genStateLink(options)
Generate state-specific links with leading slash.
import { genStateLink } from "abc-router";
const stateLink = genStateLink({
appShortName: "asvab",
tag: "math",
state: "california",
});
// Returns: "/california/asvab-math-questions"Parameters:
appShortName: string- Short name of the applicationtag: string- Tag to categorize the teststate?: string- State parameter (optional)
🔧 URL Patterns
Application Routing Patterns
- Basic App:
/app/link - State App:
/app/state/link - With Query:
/app/link?param=value
Study Link Patterns
- Practice Test:
appShortName-tag-practice-test - Full Test:
full-length-appShortName-tag-practice-test - State Specific:
appShortName-state-tag-questions - Parent App:
tag-practice-test(cleaned)
🧪 Testing
# Run tests
pnpm test
# Run tests with coverage
pnpm test:coverage
# Run tests once
pnpm test:run🔧 Development
# Build package
pnpm build
# Development mode with watch
pnpm dev
# Type checking
pnpm check-types
# Lint
pnpm lint
# Clean dist
pnpm clean📦 Dependencies
Production Dependencies
query-string- Query string parsing and formattingabc-constants- Constants and configurationsabc-model- Data models and types
Development Dependencies
@repo/eslint-config- ESLint configuration@types/node- Node.js typesvitest- Testing framework@vitest/coverage-v8- Coverage reportingjsdom- DOM environment for tests
📋 Type Definitions
interface IPropsRouterApp {
app?: string;
state?: string;
linkTo?: string;
payload?: Record<string, any>;
}
interface IPropsGenStudyLink {
appShortName: string;
appName?: string;
tag: string;
fullTest?: boolean;
state?: string;
isParent?: boolean;
}🔄 Usage Examples
Complete Workflow Example
import { generateRouterApp, genStudyLink, genStateLink } from "abc-router";
// Generate app router path
const appPath = generateRouterApp({
app: "asvab",
state: "california",
linkTo: "practice",
payload: { topic: "math", level: "intermediate" },
});
// Generate study link
const studyLink = genStudyLink({
appShortName: "asvab",
tag: "math-practice",
fullTest: false,
state: "california",
});
// Generate state link
const stateLink = genStateLink({
appShortName: "asvab",
tag: "math",
state: "california",
});
console.log(appPath); // "/asvab/california/practice?topic=math&level=intermediate"
console.log(studyLink); // "asvab-california-math-practice-questions"
console.log(stateLink); // "/california/asvab-math-questions"📄 License
MIT
