- Create a few folder and initalize npm inside it. The name of the project should be set to
Practical 10
and the author should be your own name`
Paste screenshot here
- Now, add a field
"type":"module"
to thepackage.json
file
Paste screenshot here
- Install the packages
chalk
andvalidator
from the npm registry
- Now, create a
index.js
file and write the code to solve each of the following questions:
- Email Validation with Color Feedback: Check if a string is a valid email using validator.isEmail. Output "Valid Email" in green if true, or "Invalid Email" in red if false.
- URL Verification and Styling: Use validator.isURL to validate a URL. Print "Valid URL" in blue and underlined for a valid URL, or "Invalid URL" in magenta and italicized for an invalid one.
- Credit Card Number Check: Validate a credit card number with validator.isCreditCard. Display "Valid Credit Card" in bold green for a valid number, or "Invalid Credit Card" in bold red for an invalid number.
- Port Number Validation: Use validator.isPort to check if a string is a valid port number. Output "Valid Port" in cyan with a bold style for valid, or "Invalid Port" in yellow with a background color for invalid.
- Numeric String Evaluation: Verify if a string is numeric using validator.isNumeric. Print "Numeric String" in bright yellow for true, or "Non-Numeric String" in grey for false.
- Alphanumeric String Assessment: Check if a string is alphanumeric using validator.isAlphanumeric. Output "Alphanumeric" in purple if true, or "Not Alphanumeric" in orange if false.
- Lowercase String Confirmation: Use validator.isLowercase to determine if a string is all lowercase. Display "All Lowercase" in blue if true, or "Contains Uppercase" in red if false.
- String Length Validation: Validate a string's length to be between 10 and 20 characters using validator.isLength. Print "Valid Length" in cyan with underline for valid, or "Invalid Length" in red with strikethrough for invalid.
- Empty String Detection with Styling: Detect if a string is empty using validator.isEmpty. Output "Empty String" in red, or "Non-Empty String" in green, each with respective background colors for emphasis.
- Date String Validation: Validate a date string with validator.isISO8601. Display "Valid Date" in bright green or "Invalid Date" in bright red, using an underlined format
Bonus. How will you use nodemon
package to experiment with the solutions to any of the above problems