devanagari-fonts
v1.0.0
Published
A comprehensive package for Devanagari text rendering and font utilities
Maintainers
Readme
Devanagari Fonts
A comprehensive npm package for working with Devanagari text and fonts, providing utilities for text rendering, font loading, and text processing.
Features
- 📝 Sample Devanagari Text: Pre-built collection of common phrases, greetings, and text samples
- 🔤 Font Loading: Easy integration with popular Devanagari fonts
- 🎨 Text Rendering: Utilities for styling and displaying Devanagari text
- 🔧 Text Processing: Convert numbers, validate text, and analyze characters
- 🌐 Unicode Support: Full Unicode range support for Devanagari script
Installation
npm install devanagari-fontsQuick Start
import { DevanagariText, FontLoader, TextRenderer } from 'devanagari-fonts';
// Get sample text
const samples = DevanagariText.getSamplesByCategory('greetings');
console.log(samples[0].text); // "नमस्ते"
// Load fonts
const fontLoader = new FontLoader();
await fontLoader.loadFont({
name: 'Noto Sans Devanagari',
url: 'https://fonts.googleapis.com/css2?family=Noto+Sans+Devanagari:wght@400&display=swap',
format: 'woff2'
});
// Render text
const element = TextRenderer.createTextElement('नमस्ते', {
fontFamily: 'Noto Sans Devanagari',
fontSize: '24px',
color: '#2563eb'
});API Reference
DevanagariText
Static methods for working with Devanagari text samples and number conversion.
// Get samples by category
const greetings = DevanagariText.getSamplesByCategory('greetings');
const religious = DevanagariText.getSamplesByCategory('religious');
// Convert numbers
const devanagariNum = DevanagariText.convertNumbersToDevanagari('123'); // "१२३"
const arabicNum = DevanagariText.convertNumbersToArabic('१२३'); // "123"
// Check if text is Devanagari
const isDevanagari = DevanagariText.isDevanagari('नमस्ते'); // trueFontLoader
Load and manage Devanagari fonts.
const fontLoader = new FontLoader();
// Load single font
await fontLoader.loadFont({
name: 'Noto Sans Devanagari',
url: 'path/to/font.woff2',
format: 'woff2'
});
// Load multiple fonts
await fontLoader.loadFonts([font1, font2, font3]);
// Check if font is loaded
const isLoaded = fontLoader.isFontLoaded('Noto Sans Devanagari');
// Generate CSS
const css = fontLoader.generateFontCSS(fontConfig);TextRenderer
Render and style Devanagari text.
// Create styled element
const element = TextRenderer.createTextElement('देवनागरी', {
fontFamily: 'Noto Sans Devanagari',
fontSize: '20px',
color: '#1f2937',
textAlign: 'center'
});
// Generate CSS
const css = TextRenderer.generateCSS('.devanagari-text', {
fontFamily: 'Noto Sans Devanagari',
fontSize: '18px'
});DevanagariUtils
Utility functions for text analysis and processing.
// Get character information
const info = DevanagariUtils.getCharacterInfo('क');
// { character: 'क', unicode: 'U+0915', name: 'DEVANAGARI LETTER KA', category: 'consonant' }
// Get Unicode point
const unicode = DevanagariUtils.getUnicodePoint('न'); // "U+0928"
// Count Devanagari characters
const count = DevanagariUtils.countDevanagariCharacters('नमस्ते world'); // 5
// Validate Devanagari text
const isValid = DevanagariUtils.isValidDevanagari('नमस्ते'); // trueSample Text Categories
The package includes sample text in various categories:
greetings: Common greetings and polite expressionsreligious: Religious phrases and mantrasphilosophy: Philosophical sayings and quotesmotto: National and cultural mottos
Font Recommendations
Popular Devanagari fonts that work well with this package:
- Noto Sans Devanagari: Modern, clean font from Google Fonts
- Mukti: Traditional style font
- Samarkan Normal: Decorative font for headings
Browser Support
- Modern browsers with FontFace API support
- Node.js environments (returns HTML strings)
- Full Unicode support for Devanagari range (U+0900-U+097F)
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
License
MIT License - see LICENSE file for details.
