@intelehealth/ayu-core
v0.0.1
Published
Intelehealth Ayu Core
Readme
@intelehealth/intelehealth-ayu-core
A universal React library for healthcare applications 🏥
Intelehealth's core library for React.js and React Native applications. A comprehensive universal library that provides essential utilities and services for healthcare applications, focusing on business logic without platform-specific dependencies.
✨ Why Choose This Library?
- 🚀 Universal Compatibility - Works seamlessly with React.js and React Native
- 🔒 TypeScript First - Full TypeScript implementation with strict type checking
- 🏥 Healthcare Focused - Built specifically for healthcare applications
- 📦 Tree-shakable - Import only what you need for optimal bundle size
- 🧪 Well Tested - Comprehensive test coverage with Jest and React Testing Library
- 🔧 Developer Friendly - Excellent developer experience with hot reloading and debugging
- 📚 Well Documented - Complete API documentation and examples
- 🛡️ Production Ready - Battle-tested in production healthcare applications
🚀 Features
- Universal Compatibility: Works with React.js and React Native
- TypeScript Support: Full TypeScript implementation with strict type checking
- Business Logic Focus: No platform-specific dependencies
- Testing Setup: Jest and React Testing Library configuration
- Build System: Rollup for efficient bundling
- Code Quality: ESLint, Prettier, and Husky for code standards
- Git Hooks: Pre-commit and pre-push hooks for quality assurance
- Documentation: Auto-generated API documentation
- CI/CD Ready: GitHub Actions workflow included
- NPM Publishing: Complete publishing setup
- Code Ownership: GitHub CODEOWNERS for proper review process
🧩 Core Components
- Storage: Simple, platform-agnostic storage utility for React and React Native
- ApiService: HTTP client using Axios with retry logic and hooks
- AuthService: Authentication state management
- useLocalStorage: React hook for localStorage synchronization (React only)
- useDebounce: React hooks for debouncing values and callbacks
- Utility Functions: Date, string, and object manipulation utilities
📦 Installation
NPM
npm install @intelehealth/intelehealth-ayu-coreYarn
yarn add @intelehealth/intelehealth-ayu-corePNPM
pnpm add @intelehealth/intelehealth-ayu-coreRequirements
- Node.js >= 20.0.0
- React >= 18.0.0
- TypeScript >= 5.0.0 (recommended)
What's Included in NPM Package
The published NPM package contains only the essential files:
dist/- Compiled JavaScript and TypeScript definitionsREADME.md- This documentationLICENSE- MIT License file
Development files (source code, tests, configs, .vscode, etc.) are excluded to keep the package lightweight.
Package Size
- Minified + Gzipped: ~15KB
- Tree-shakable: Import only what you need
- Zero dependencies: Only peer dependencies (React)
🚀 Quick Start
Get started in minutes with our comprehensive examples:
React (Web) Usage
import {
Storage,
ApiService,
AuthService,
useLocalStorage,
useDebounce,
} from '@intelehealth/intelehealth-ayu-core';
// useLocalStorage works in React web apps
const [value, setValue] = useLocalStorage('key', 'default');React Native Usage
import {
Storage,
ApiService,
AuthService,
useDebounce,
} from '@intelehealth/intelehealth-ayu-core';
// useLocalStorage is not available in React Native
// Use the Storage class instead for persistent storage
const storage = new Storage('app_');
await storage.set('key', 'value');
const value = await storage.get('key');Full Import
import {
Storage,
ApiService,
AuthService,
} from '@intelehealth/intelehealth-ayu-core';
// Use the Storage utility
const storage = new Storage('app_');
await storage.set('user', { id: 1, name: 'John' });
// Use the API service
const api = new ApiService({ baseURL: 'https://api.example.com' });
const response = await api.get('/users');
// Use the Auth service
const auth = new AuthService();
await auth.login({ email: '[email protected]', password: 'password' });Folder-wise Imports (Tree-shaking friendly)
// Import only what you need from specific folders
import { Storage, appStorage } from '@intelehealth/intelehealth-ayu-core/core';
import { ApiService } from '@intelehealth/intelehealth-ayu-core/services';
import {
useLocalStorage,
useDebounce,
} from '@intelehealth/intelehealth-ayu-core/hooks';
import {
formatDate,
deepClone,
} from '@intelehealth/intelehealth-ayu-core/utils';
import type {
ApiResponse,
User,
} from '@intelehealth/intelehealth-ayu-core/types';📚 API Documentation
Storage Class
A platform-agnostic storage utility that works with both React and React Native.
import { Storage } from '@intelehealth/intelehealth-ayu-core';
const storage = new Storage('app_');
// Set a value
await storage.set('user', { id: 1, name: 'John' });
// Get a value
const user = await storage.get('user');
// Remove a value
await storage.remove('user');
// Clear all values
await storage.clear();ApiService Class
HTTP client with retry logic and error handling.
import { ApiService } from '@intelehealth/intelehealth-ayu-core';
const api = new ApiService({
baseURL: 'https://api.example.com',
timeout: 5000,
retries: 3,
});
// GET request
const users = await api.get('/users');
// POST request
const newUser = await api.post('/users', {
name: 'John',
email: '[email protected]',
});
// PUT request
const updatedUser = await api.put('/users/1', { name: 'John Updated' });
// DELETE request
await api.delete('/users/1');AuthService Class
Authentication state management.
import { AuthService } from '@intelehealth/intelehealth-ayu-core';
const auth = new AuthService();
// Login
await auth.login({ email: '[email protected]', password: 'password' });
// Check if user is authenticated
const isAuthenticated = auth.isAuthenticated();
// Get current user
const user = auth.getCurrentUser();
// Logout
await auth.logout();React Hooks
useLocalStorage (React only)
import { useLocalStorage } from '@intelehealth/intelehealth-ayu-core';
function MyComponent() {
const [value, setValue] = useLocalStorage('key', 'defaultValue');
return (
<div>
<p>Value: {value}</p>
<button onClick={() => setValue('new value')}>
Update Value
</button>
</div>
);
}useDebounce
import { useDebounce } from '@intelehealth/intelehealth-ayu-core';
function SearchComponent() {
const [searchTerm, setSearchTerm] = useState('');
const debouncedSearchTerm = useDebounce(searchTerm, 500);
useEffect(() => {
if (debouncedSearchTerm) {
// Perform search
performSearch(debouncedSearchTerm);
}
}, [debouncedSearchTerm]);
return (
<input
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
placeholder="Search..."
/>
);
}Utility Functions
import {
formatDate,
deepClone,
capitalize,
generateId,
} from '@intelehealth/intelehealth-ayu-core/utils';
// Date utilities
const formattedDate = formatDate(new Date(), 'YYYY-MM-DD');
// Object utilities
const cloned = deepClone(originalObject);
// String utilities
const capitalized = capitalize('hello world'); // "Hello world"
// Generate unique ID
const id = generateId(); // "abc123def456"🔧 Configuration
TypeScript Configuration
Add to your tsconfig.json:
{
"compilerOptions": {
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
}React Native Configuration
For React Native projects, ensure you have the required peer dependencies:
npm install react react-native🐛 Troubleshooting
Common Issues
1. TypeScript errors with imports
- Ensure you have TypeScript 5.0+ installed
- Check your
tsconfig.jsonconfiguration
2. React Native compatibility
- Make sure you're using React Native 0.70+
- Some hooks like
useLocalStorageare not available in React Native
3. Build errors
- Clear your node_modules and reinstall
- Check your bundler configuration
Getting Help
- 📖 Documentation: Check our full API docs
- 🐛 Bug Reports: GitHub Issues
- 💡 Feature Requests: GitHub Discussions
- 📧 Email Support: [email protected]
📄 License
MIT License - see LICENSE file for details.
