dev-utils-all-in-one
v1.0.2
Published
All-in-one developer utility package with intelligent search, API response normalization, and automatic CRUD generation
Downloads
100
Maintainers
Readme
All-in-One Developer Utility Package
A comprehensive, production-ready TypeScript utility package providing intelligent search, API response normalization, and automatic CRUD generation. Built with zero dependencies (except dev dependencies) and optimized for performance.
Features
🔍 Smart Search Engine
- Fuzzy search - Find matches even with typos
- Typo-tolerant search - Handles spelling mistakes intelligently
- Weighted field-based search - Prioritize certain fields
- Multi-language search - Support for multiple languages
- Context-aware search - Search across primary and context fields
- Case insensitive search - Works regardless of case
- Partial matching - Finds partial word matches
- Phonetic matching - Matches similar-sounding words
- Synonym matching - Expand queries with synonyms
- Highlighted results - Get highlighted match text
🔄 Universal Data Adapter
- Automatic format detection - Works with any API response format
- REST API support - Standard REST responses
- GraphQL support - GraphQL response structures
- Custom backend formats - Handles custom API structures
- Pagination detection - Automatically finds pagination info
- Nested structure support - Works with deeply nested data
⚡ Auto CRUD Generator
- Automatic CRUD operations - Generate full CRUD service layer
- Pagination support - Built-in pagination handling
- Error handling - Comprehensive error management
- Response normalization - Uses universal data adapter
- Caching layer - Optional in-memory caching
- Retry mechanism - Automatic retry on failures
- Timeout handling - Request timeout support
- Query builder - Easy filtering and sorting
- Request cancellation - AbortController support
Installation
npm install dev-utils-all-in-oneQuick Start
Smart Search Engine
import { smartSearchEngine } from 'dev-utils-all-in-one';
const users = [
{ id: 1, name: 'John Doe', email: '[email protected]' },
{ id: 2, name: 'Jane Smith', email: '[email protected]' },
];
const results = smartSearchEngine(users, 'john', {
fields: ['name', 'email'],
highlightMatches: true,
typoTolerance: true,
});
results.forEach(result => {
console.log(`Score: ${result.score}`);
console.log(`Name: ${result.item.name}`);
console.log(`Matches: ${result.matches.join(', ')}`);
});Universal Data Adapter
import { adaptResponse } from 'dev-utils-all-in-one';
// Works with any API response format
const apiResponse = {
data: [{ id: 1, name: 'Item 1' }],
total: 100,
page: 1,
limit: 10,
};
const normalized = adaptResponse(apiResponse);
// Returns: { data: [...], pagination: {...}, success: true }Auto CRUD Generator
import { autoCrudGenerator } from 'dev-utils-all-in-one';
const userService = autoCrudGenerator({
baseUrl: 'https://api.example.com/users',
caching: true,
pagination: true,
});
// Get all users
const response = await userService.getAll({
page: 1,
limit: 10,
filter: { role: 'admin' },
});
// Get by ID
const user = await userService.getById(1);
// Create
const newUser = await userService.create({
name: 'John Doe',
email: '[email protected]',
});
// Update
const updated = await userService.update(1, {
name: 'John Updated',
});
// Delete
await userService.delete(1);API Reference
Smart Search Engine
smartSearchEngine<T>(data, query, options)
Parameters:
data: T[]- Array of items to searchquery: string- Search queryoptions: SmartSearchOptions- Search configuration
Options:
fields: string[]- Fields to search (required)weights?: Record<string, number>- Field weights (default: 1.0)language?: string- Language code (default: 'en')typoTolerance?: boolean- Enable typo tolerance (default: true)fuzzyLevel?: number- Max Levenshtein distance (default: 2)enableSynonyms?: boolean- Enable synonym matching (default: false)contextFields?: string[]- Context fields (lower weight)highlightMatches?: boolean- Include highlighted text (default: false)
Returns: SmartSearchResult<T>[] - Sorted by score (descending)
Result Structure:
interface SmartSearchResult<T> {
item: T;
score: number;
matches: string[];
highlightedText?: string;
}Universal Data Adapter
adaptResponse(response)
Parameters:
response: any- API response in any format
Returns: StandardResponse<T>
Response Structure:
interface StandardResponse<T> {
data: T[];
pagination?: {
total: number;
page: number;
limit: number;
totalPages: number;
};
message?: string;
success: boolean;
errors?: any;
}Auto CRUD Generator
autoCrudGenerator<T>(options)
Parameters:
options: CrudGeneratorOptions- Configuration
Options:
baseUrl: string- API base URL (required)caching?: boolean- Enable caching (default: false)pagination?: boolean- Enable pagination (default: true)httpClient?: HttpClient- Custom HTTP clienttimeout?: number- Request timeout in ms (default: 30000)retries?: number- Retry count (default: 3)retryDelay?: number- Retry delay in ms (default: 1000)
Returns: CrudService<T>
Service Methods:
getAll(options?)- Get all items with pagination/filteringgetById(id, config?)- Get item by IDcreate(data, config?)- Create new itemupdate(id, data, config?)- Update itemdelete(id, config?)- Delete item
Advanced Usage
Custom HTTP Client
import axios from 'axios';
const customClient = {
get: (url, config) => axios.get(url, config).then(r => r.data),
post: (url, data, config) => axios.post(url, data, config).then(r => r.data),
put: (url, data, config) => axios.put(url, data, config).then(r => r.data),
patch: (url, data, config) => axios.patch(url, data, config).then(r => r.data),
delete: (url, config) => axios.delete(url, config).then(r => r.data),
};
const service = autoCrudGenerator({
baseUrl: 'https://api.example.com',
httpClient: customClient,
});Request Cancellation
const controller = new AbortController();
// Cancel after 1 second
setTimeout(() => controller.abort(), 1000);
const response = await service.getAll({
signal: controller.signal,
});Weighted Search
const results = smartSearchEngine(data, 'query', {
fields: ['name', 'description', 'tags'],
weights: {
name: 2.0, // Name matches are 2x more important
description: 1.5, // Description matches are 1.5x
tags: 0.5, // Tags are less important
},
});Tree Shaking
The package supports tree-shaking. Import only what you need:
// Import specific modules
import { smartSearchEngine } from 'dev-utils-all-in-one/smartSearchEngine';
import { adaptResponse } from 'dev-utils-all-in-one/universalDataAdapter';
import { autoCrudGenerator } from 'dev-utils-all-in-one/autoCrudGenerator';Performance
- Optimized for large datasets - Handles 10k+ records efficiently
- Zero dependencies - Minimal bundle size
- Fast algorithms - Optimized Levenshtein distance and search algorithms
- Memory efficient - Smart caching with TTL
Browser Support
- Modern browsers with ES2020 support
- Node.js 14+
TypeScript
Full TypeScript support with comprehensive type definitions.
Testing
npm test
npm run test:coverageBuilding
npm run buildLicense
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Examples
See the examples/ directory for more usage examples:
smartSearchExample.ts- Search engine examplesdataAdapterExample.ts- Data adapter examplescrudGeneratorExample.ts- CRUD generator examples
