-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfrnds.ts
136 lines (122 loc) · 5.26 KB
/
frnds.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { Command } from 'commander';
const ASCII_ART = `
\x1b[35m
··································································
: :
: # # :
: # # ## ##### ##### # # :
: # # # # # # # # # # :
: ####### # # # # # # # :
: # # ###### ##### ##### # :
: # # # # # # # :
: # # # # # # # :
: :
: ####### :
: # ##### # ###### # # ##### #### # # # ##### :
: # # # # # ## # # # # # # # # # :
: ##### # # # ##### # # # # # #### ###### # # # :
: # ##### # # # # # # # # # # # ##### :
: # # # # # # ## # # # # # # # # :
: # # # # ###### # # ##### #### # # # # :
: :
: ###### :
: # # ## # # :
: # # # # # # :
: # # # # # :
: # # ###### # :
: # # # # # :
: ###### # # # :
: :
··································································
\x1b[0m
`;
const QUOTES = [
"True friends are those who lift you up when you have forgotten how to fly ❤️",
"Friendship is like a rainbow between two hearts, shining with love and joy 👋",
"A friend is someone who sees the magic in you, even when you can't see it yourself 🌟",
"In the garden of life, friends are the flowers that make it bloom with joy 🎁",
"Friendship is a treasure chest filled with memories and laughter ❤️",
"Friendship is the compass that guides us through life's storm 🌟",
"Friends are the greatest gifts of life. You will always be a significant part of my life ❤️",
"The love of friends makes life's toughest moments more bearable 🎁",
"Friendship is like a star We truly realize how bright and valuable it is during the darkest times 🌟",
];
function slugify(input: string): string {
return input
.trim()
.toLowerCase()
.replace(/\s+/g, '-')
.replace(/[^a-z0-9-]/g, '')
.replace(/--+/g, '-');
}
function cleanSpecialCharacters(input: string): string {
const cleaned = input.replace(/[^a-zA-Z0-9 ]/g, '').trim();
return cleaned.length > 36 ? cleaned.substring(0, 36) : cleaned;
}
function validateName(name: string): boolean {
const trimmedName = name.trim();
return /^[a-zA-Z0-9\s]+$/.test(trimmedName) && trimmedName.length >= 2 && trimmedName.length <= 36;
}
function generatePersonalizedGreeting(name: string) {
if (!validateName(name)) {
console.error('\x1b[31mError: Invalid name. Please use letters, numbers, and spaces only, and ensure the name is between 2 and 36 characters long.\n\x1b[0m');
return;
}
const cleanedName = cleanSpecialCharacters(name);
const slugifiedName = slugify(cleanedName);
const url = `https://searchquotes.quest/wish/web?name=${slugifiedName}`;
console.log(`
\x1b[32m👋 Happy Friendship Day, \x1b[36m${cleanedName}\x1b[32m 🌟\n\x1b[0m
\x1b[36m✔ Your personalized greeting URL: \x1b[33m${url}\x1b[0m
`);
}
function printGreeting(message: string | undefined, name: string | undefined) {
if (message) {
console.log(`
\x1b[32m👋 ${message} 🌟\x1b[0m
`);
} else if (name) {
generatePersonalizedGreeting(name);
} else {
console.log(`
\x1b[32m👋 Happy Friendship Day 🌟\x1b[0m
`);
}
}
async function printRandomQuote() {
const randomIndex = Math.floor(Math.random() * QUOTES.length);
console.log(`
\x1b[36m✅ Here's a special quote for you:\n\x1b[0m
\x1b[36m${QUOTES[randomIndex]}\x1b[0m
`);
}
function printAsciiArt() {
console.log(`
\x1b[35m✅ Happy Friendship Day ASCII art:\x1b[0m
${ASCII_ART}
`);
}
const program = new Command();
program
.option('-m, --message <message>', 'Custom message to display')
.option('-n, --name <name>', 'Your name for a personalized greeting')
.option('-q, --quote', 'Display a random Friendship Day quote')
.option('-a, --art', 'Display ASCII art')
.action(async (options) => {
try {
printGreeting(options.message, options.name);
if (options.quote) {
await printRandomQuote();
}
if (options.art) {
printAsciiArt();
}
} catch (error: unknown) {
if (error instanceof Error) {
console.error('\x1b[31mError:', error.message, '\x1b[0m');
} else {
console.error('\x1b[31mAn unknown error occurred.\x1b[0m');
}
}
});
program.parse(process.argv);