Welcome to the World of nodedig
nodedig is a powerful toolkit for Node.js. It offers dozens of useful APIs to perform various tasks ranging from simple operations to complex tasks with ease. Let’s dive deeper into its features and functionalities through examples.
Getting Started with nodedig
First, you’ll need to install nodedig via npm:
npm install nodedig
Example APIs
1. Generate UUID
Generate a unique identifier with nodedig:
const nodedig = require('nodedig'); const uuid = nodedig.generateUUID(); console.log(uuid);
2. Hashing Function
Create a hash from a string:
const hash = nodedig.hashString('example string'); console.log(hash);
3. Random Number Generation
Generate a random number within a specific range:
const randomNumber = nodedig.randomNumber(1, 100); console.log(randomNumber);
4. Validate Email
Check if an email address is valid:
const isValidEmail = nodedig.validateEmail('test@example.com'); console.log(isValidEmail);
5. Encrypt and Decrypt
Encrypt and decrypt messages:
const encrypted = nodedig.encrypt('Hello World', 'secret_key'); const decrypted = nodedig.decrypt(encrypted, 'secret_key'); console.log(`Encrypted: ${encrypted}, Decrypted: ${decrypted}`);
6. JSON to CSV
Convert JSON data to CSV format:
const json = [{"name": "John Doe", "age": 30}, {"name": "Jane Doe", "age": 25}]; const csv = nodedig.jsonToCsv(json); console.log(csv);
7. CSV to JSON
Convert CSV data to JSON format:
const csvData = "name,age\nJohn Doe,30\nJane Doe,25"; const jsonArr = nodedig.csvToJson(csvData); console.log(jsonArr);
8. Fetch Data from URL
Fetch data from a remote URL:
nodedig.fetchData('https://api.example.com/data') .then(data => console.log(data)) .catch(error => console.error(error));
Complete Example Application
Here’s a simple example that utilizes multiple nodedig APIs to build an application:
const nodedig = require('nodedig'); // Generate a UUID const userId = nodedig.generateUUID(); // Validate email const email = 'user@example.com'; if (nodedig.validateEmail(email)) { console.log('Valid Email'); } else { console.log('Invalid Email'); } // Encrypt and decrypt data const secretKey = 'my_secret_key'; const message = 'Hello User'; const encryptedMessage = nodedig.encrypt(message, secretKey); const decryptedMessage = nodedig.decrypt(encryptedMessage, secretKey); console.log(`Encrypted Message: ${encryptedMessage}`); console.log(`Decrypted Message: ${decryptedMessage}`); // Fetch user data nodedig.fetchData(`https://api.example.com/users/${userId}`) .then(userData => console.log(`User Data: ${JSON.stringify(userData)}`)) .catch(error => console.error(error));
By integrating these APIs into your application, you can create powerful and efficient solutions with ease. nodedig makes it simple to implement advanced functionalities with minimal effort.
Hash: 019098d64f5f90926519615d38e3891b46067933ff064268e7364125f8493cb5