my-first-npm-bijnis
A comprehensive cross-platform utility library for React Native and Node.js applications. Features greeting utilities and advanced device intelligence for optimal cross-platform development.
✨ Features
🎉 Greeting Utilities
- 🎯 TypeScript Support - Full type definitions and IntelliSense
- 🚀 Modern ES6+ - Built with modern JavaScript features
- 🧪 Well Tested - Comprehensive test coverage with Jest
- 📦 Tree Shakeable - Optimized for modern bundlers
- 🔧 Zero Dependencies - No external runtime dependencies
- 📚 Well Documented - Comprehensive API documentation
🧠 Device Intelligence System (NEW!)
- 📱 Cross-Platform Detection - Unified platform detection for iOS, Android, Web, and more
- ⚡ Performance Monitoring - Real-time performance tracking and analysis
- 🎯 Smart Optimization - AI-powered recommendations based on device capabilities
- 🔋 Battery Awareness - Battery level and power mode detection
- 🌐 Network Intelligence - Connection type and quality assessment
- 📊 Device Capabilities - Memory, CPU, screen, and storage analysis
- 🚀 React Native Ready - Optimized for React Native and mobile development
📦 Installation
npm install my-first-npm-bijnis
Or with yarn:
yarn add my-first-npm-bijnis
🚀 Quick Start
JavaScript (CommonJS)
const { greet, greetBatch, getDeviceCapabilities, getOptimizationRecommendations } = require('my-first-npm-bijnis');
// Basic greeting
console.log(greet('World')); // Hello, World! 👋
// Excited greeting
console.log(greet('World', { excited: true })); // HELLO, WORLD! 👋 🎉
// Device Intelligence
const capabilities = await getDeviceCapabilities();
console.log(`Platform: ${capabilities.platform}`);
console.log(`Performance Tier: ${capabilities.performanceTier}`);
const recommendations = await getOptimizationRecommendations();
console.log(`Recommended Image Quality: ${recommendations.imageQuality}%`);
TypeScript / ES Modules
import {
greet,
greetBatch,
GreetOptions,
DeviceIntelligence,
getDeviceCapabilities,
getOptimizationRecommendations,
DeviceCapabilities,
OptimizationRecommendations
} from 'my-first-npm-bijnis';
// Basic greeting
console.log(greet('World')); // Hello, World! 👋
// With options
const options: GreetOptions = {
excited: true,
emoji: '🚀',
includeName: true
};
console.log(greet('Alice', options)); // HELLO, ALICE! 🚀 🎉
📖 API Reference
greet(name, options?)
Returns a personalized greeting message.
Parameters:
name
(string): The name to greetoptions
(GreetOptions, optional): Configuration options
Returns:
string
: A greeting message
Throws:
Error
: When name is not a non-empty string
greetBatch(names, options?)
Creates greetings for multiple names.
Parameters:
names
(string[]): Array of names to greetoptions
(GreetOptions, optional): Configuration options
Returns:
string[]
: Array of greeting messages
Throws:
Error
: When names is not an array
GreetOptions
interface GreetOptions {
/** Whether to make the greeting excited */
excited?: boolean;
/** Custom emoji to use in the greeting */
emoji?: string;
/** Whether to include the name in the greeting */
includeName?: boolean;
}
💡 Examples
Basic Usage
import { greet } from 'my-first-npm-bijnis';
// Simple greeting
greet('Alice'); // "Hello, Alice! 👋"
// Excited greeting
greet('Bob', { excited: true }); // "HELLO, BOB! 👋 🎉"
// Custom emoji
greet('Charlie', { emoji: '🌟' }); // "Hello, Charlie! 🌟"
// Without name
greet('World', { includeName: false }); // "Hello! 👋"
Batch Greetings
import { greetBatch } from 'my-first-npm-bijnis';
const names = ['Alice', 'Bob', 'Charlie'];
const greetings = greetBatch(names, { excited: true });
console.log(greetings);
// ['HELLO, ALICE! 👋 🎉', 'HELLO, BOB! 👋 🎉', 'HELLO, CHARLIE! 👋 🎉']
Error Handling
import { greet } from 'my-first-npm-bijnis';
try {
greet(''); // Throws: Name must be a non-empty string
greet(null); // Throws: Name must be a non-empty string
} catch (error) {
console.error(error.message);
}
🧠 Device Intelligence System
The Device Intelligence System is a unique cross-platform utility that provides unified device detection, performance metrics, and optimization recommendations for React Native and web applications.
Basic Usage
import {
DeviceIntelligence,
getDeviceCapabilities,
getOptimizationRecommendations
} from 'my-first-npm-bijnis';
// Get device capabilities
const capabilities = await getDeviceCapabilities();
console.log('Platform:', capabilities.platform);
console.log('Performance Tier:', capabilities.performanceTier);
console.log('Memory:', capabilities.memoryMB, 'MB');
console.log('CPU Cores:', capabilities.cpuCores);
// Get optimization recommendations
const recommendations = await getOptimizationRecommendations();
console.log('Image Quality:', recommendations.imageQuality, '%');
console.log('Animation FPS:', recommendations.animationFPS);
console.log('Hardware Acceleration:', recommendations.hardwareAcceleration);
Advanced Usage with Performance Monitoring
import { DeviceIntelligence } from 'my-first-npm-bijnis';
const deviceIntelligence = DeviceIntelligence.getInstance();
// Monitor performance
deviceIntelligence.recordPerformance(85);
deviceIntelligence.recordPerformance(90);
deviceIntelligence.recordPerformance(88);
// Get performance insights
const insights = deviceIntelligence.getPerformanceInsights();
console.log('Average Performance:', insights.average);
console.log('Trend:', insights.trend);
console.log('Recommendations:', insights.recommendations);
React Native Integration
import React, { useEffect, useState } from 'react';
import { View, Text } from 'react-native';
import { getDeviceCapabilities, getOptimizationRecommendations } from 'my-first-npm-bijnis';
const MyComponent = () => {
const [capabilities, setCapabilities] = useState(null);
const [recommendations, setRecommendations] = useState(null);
useEffect(() => {
const loadDeviceInfo = async () => {
const caps = await getDeviceCapabilities();
const recs = await getOptimizationRecommendations();
setCapabilities(caps);
setRecommendations(recs);
};
loadDeviceInfo();
}, []);
if (!capabilities || !recommendations) {
return <Text>Loading device information...</Text>;
}
return (
<View>
<Text>Platform: {capabilities.platform}</Text>
<Text>Performance: {capabilities.performanceTier}</Text>
<Text>Recommended Image Quality: {recommendations.imageQuality}%</Text>
<Text>Animation FPS: {recommendations.animationFPS}</Text>
</View>
);
};
API Reference
DeviceCapabilities Interface
interface DeviceCapabilities {
platform: 'ios' | 'android' | 'web' | 'windows' | 'macos' | 'linux' | 'unknown';
performanceTier: 'low' | 'medium' | 'high' | 'premium';
memoryMB: number;
cpuCores: number;
screenSize: {
width: number;
height: number;
density: number;
};
networkType: 'wifi' | 'cellular' | 'ethernet' | 'unknown';
batteryLevel: number;
lowPowerMode: boolean;
storageMB: number;
deviceModel: string;
osVersion: string;
}
OptimizationRecommendations Interface
interface OptimizationRecommendations {
imageQuality: number; // 0-100
animationFPS: number; // 24, 30, or 60
hardwareAcceleration: boolean;
cacheSizeMB: number;
backgroundProcessing: boolean;
networkTimeout: number; // milliseconds
dataCompression: boolean;
batchSize: number;
}
DeviceIntelligence Class Methods
class DeviceIntelligence {
// Get singleton instance
static getInstance(): DeviceIntelligence;
// Detect current platform
detectPlatform(): Platform;
// Get comprehensive device capabilities
getDeviceCapabilities(): Promise<DeviceCapabilities>;
// Get optimization recommendations
getOptimizationRecommendations(): Promise<OptimizationRecommendations>;
// Record performance score (0-100)
recordPerformance(score: number): void;
// Get performance insights
getPerformanceInsights(): {
average: number;
trend: 'improving' | 'declining' | 'stable';
recommendations: string[];
};
// Clear performance history (useful for testing)
clearPerformanceHistory(): void;
}
Use Cases
- React Native Apps: Optimize performance based on device capabilities
- Progressive Web Apps: Adapt UI/UX based on device and network conditions
- Cross-Platform Development: Unified device detection across platforms
- Performance Monitoring: Track and analyze app performance over time
- Adaptive UI: Adjust image quality, animations, and features based on device tier
🛠️ Development
Prerequisites
- Node.js (version 12 or higher)
- npm or yarn
Setup
Clone the repository:
git clone https://github.com/bijnis/my-first-npm.git cd my-first-npm
Install dependencies:
npm install
Build the project:
npm run build
Available Scripts
npm run build
- Build the TypeScript sourcenpm run build:watch
- Build in watch modenpm test
- Run testsnpm run test:watch
- Run tests in watch modenpm run test:coverage
- Run tests with coveragenpm run lint
- Run ESLintnpm run lint:fix
- Fix ESLint issuesnpm run format
- Format code with Prettiernpm run type-check
- Run TypeScript type checking
Testing
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Development Guidelines
- Follow the existing code style
- Add tests for new features
- Ensure all tests pass
- Update documentation as needed
- Follow conventional commit messages
📝 Changelog
See CHANGELOG.md for a list of changes and version history.
🐛 Issues
If you find any issues or have suggestions, please open an issue on the GitHub repository.
📊 Stats
Made with ❤️ by bijnis