@20syldev/api 3.4.0 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +1 -1
- package/.github/workflows/publish.yml +27 -27
- package/LICENSE +27 -27
- package/README.md +110 -110
- package/app.js +818 -817
- package/modules/v3/algorithms.js +217 -217
- package/modules/v3/captcha.js +54 -54
- package/modules/v3/chat.js +108 -108
- package/modules/v3/color.js +40 -40
- package/modules/v3/convert.js +38 -38
- package/modules/v3/domain.js +38 -38
- package/modules/v3/hash.js +15 -15
- package/modules/v3/hyperplanning.js +50 -50
- package/modules/v3/levenshtein.js +45 -45
- package/modules/v3/personal.js +126 -126
- package/modules/v3/qrcode.js +19 -19
- package/modules/v3/tic_tac_toe.js +166 -166
- package/modules/v3/time.js +86 -86
- package/modules/v3/token.js +47 -47
- package/modules/v3/username.js +31 -31
- package/modules/v3/utils.js +65 -65
- package/modules/v3.js +14 -14
- package/package.json +53 -53
- package/robots.txt +73 -73
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculate the Levenshtein distance between two strings.
|
|
3
|
-
*
|
|
4
|
-
* @param {string} str1 - The first string
|
|
5
|
-
* @param {string} str2 - The second string
|
|
6
|
-
* @returns {object} - Object containing the strings and their Levenshtein distance
|
|
7
|
-
* @throws {Error} - If inputs are invalid
|
|
8
|
-
*/
|
|
9
|
-
export default function levenshtein(str1, str2) {
|
|
10
|
-
// Input validation
|
|
11
|
-
if (!str1 || typeof str1 !== 'string') {
|
|
12
|
-
throw new Error('Please provide a valid first string');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (!str2 || typeof str2 !== 'string') {
|
|
16
|
-
throw new Error('Please provide a valid second string');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (str1.length > 1000) {
|
|
20
|
-
throw new Error('First string exceeds 1000 characters');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (str2.length > 1000) {
|
|
24
|
-
throw new Error('Second string exceeds 1000 characters');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Calculate Levenshtein distance
|
|
28
|
-
const m = Array.from({ length: str1.length + 1 }, (_, i) => [i]);
|
|
29
|
-
for (let j = 0; j <= str2.length; j++) m[0][j] = j;
|
|
30
|
-
|
|
31
|
-
for (let i = 1; i <= str1.length; i++) {
|
|
32
|
-
for (let j = 1; j <= str2.length; j++) {
|
|
33
|
-
m[i][j] = Math.min(
|
|
34
|
-
m[i - 1][j] + 1,
|
|
35
|
-
m[i][j - 1] + 1,
|
|
36
|
-
m[i - 1][j - 1] + (str1[i - 1] !== str2[j - 1] ? 1 : 0)
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
str1,
|
|
43
|
-
str2,
|
|
44
|
-
distance: m[str1.length][str2.length]
|
|
45
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Calculate the Levenshtein distance between two strings.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str1 - The first string
|
|
5
|
+
* @param {string} str2 - The second string
|
|
6
|
+
* @returns {object} - Object containing the strings and their Levenshtein distance
|
|
7
|
+
* @throws {Error} - If inputs are invalid
|
|
8
|
+
*/
|
|
9
|
+
export default function levenshtein(str1, str2) {
|
|
10
|
+
// Input validation
|
|
11
|
+
if (!str1 || typeof str1 !== 'string') {
|
|
12
|
+
throw new Error('Please provide a valid first string');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!str2 || typeof str2 !== 'string') {
|
|
16
|
+
throw new Error('Please provide a valid second string');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (str1.length > 1000) {
|
|
20
|
+
throw new Error('First string exceeds 1000 characters');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (str2.length > 1000) {
|
|
24
|
+
throw new Error('Second string exceeds 1000 characters');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Calculate Levenshtein distance
|
|
28
|
+
const m = Array.from({ length: str1.length + 1 }, (_, i) => [i]);
|
|
29
|
+
for (let j = 0; j <= str2.length; j++) m[0][j] = j;
|
|
30
|
+
|
|
31
|
+
for (let i = 1; i <= str1.length; i++) {
|
|
32
|
+
for (let j = 1; j <= str2.length; j++) {
|
|
33
|
+
m[i][j] = Math.min(
|
|
34
|
+
m[i - 1][j] + 1,
|
|
35
|
+
m[i][j - 1] + 1,
|
|
36
|
+
m[i - 1][j - 1] + (str1[i - 1] !== str2[j - 1] ? 1 : 0)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
str1,
|
|
43
|
+
str2,
|
|
44
|
+
distance: m[str1.length][str2.length]
|
|
45
|
+
};
|
|
46
46
|
}
|
package/modules/v3/personal.js
CHANGED
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
import { random, randomNumber } from './utils.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Generate random personal information
|
|
5
|
-
*
|
|
6
|
-
* @returns {Object} Comprehensive personal profile with contact info, financial data, and more
|
|
7
|
-
*/
|
|
8
|
-
export default function personal() {
|
|
9
|
-
const people = [
|
|
10
|
-
{ name: 'John Doe', social: 'john_doe', email: 'john@example.com', country: 'US' },
|
|
11
|
-
{ name: 'Jane Martin', social: 'jane_martin', email: 'jane@example.com', country: 'FR' },
|
|
12
|
-
{ name: 'Michael Johnson', social: 'mike_johnson', email: 'michael@example.com', country: 'UK' },
|
|
13
|
-
{ name: 'Emily Davis', social: 'emily_davis', email: 'emily@example.com', country: 'ES' },
|
|
14
|
-
{ name: 'Alexis Barbos', social: 'alexis_barbos', email: 'alexis@example.com', country: 'DE' },
|
|
15
|
-
{ name: 'Sarah Williams', social: 'sarah_williams', email: 'sarah@example.com', country: 'IT' },
|
|
16
|
-
{ name: 'Daniel Brown', social: 'daniel_brown', email: 'daniel@example.com', country: 'JP' },
|
|
17
|
-
{ name: 'Sophia Wilson', social: 'sophia_wilson', email: 'sophia@example.com', country: 'BR' },
|
|
18
|
-
{ name: 'James Taylor', social: 'james_taylor', email: 'james@example.com', country: 'CA' },
|
|
19
|
-
{ name: 'Olivia Thomas', social: 'olivia_thomas', email: 'olivia@example.com', country: 'AU' }
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
const countries = {
|
|
23
|
-
US: { tel: '123-456-7890', code: '1', lang: 'English' },
|
|
24
|
-
FR: { tel: '06 78 90 12 34', code: '33', lang: 'French' },
|
|
25
|
-
UK: { tel: '7911 123456', code: '44', lang: 'English' },
|
|
26
|
-
ES: { tel: '678 901 234', code: '34', lang: 'Spanish' },
|
|
27
|
-
DE: { tel: '163 555 1584', code: '49', lang: 'German' },
|
|
28
|
-
IT: { tel: '345 678 9012', code: '39', lang: 'Italian' },
|
|
29
|
-
JP: { tel: '080-1234-5678', code: '81', lang: 'Japanese' },
|
|
30
|
-
BR: { tel: '(11) 98765-4321', code: '55', lang: 'Portuguese' },
|
|
31
|
-
CA: { tel: '416-123-4567', code: '1', lang: 'English' },
|
|
32
|
-
AU: { tel: '0412 345 678', code: '61', lang: 'English' }
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const jobs = ['Writer', 'Artist', 'Musician', 'Explorer', 'Scientist', 'Engineer', 'Athlete', 'Doctor'];
|
|
36
|
-
const hobbies = ['Reading', 'Traveling', 'Gaming', 'Cooking', 'Fitness', 'Music', 'Photography', 'Writing'];
|
|
37
|
-
const cities = ['New York', 'Paris', 'London', 'Madrid', 'Berlin', 'Rome', 'Tokyo', 'Los Angeles', 'Sydney', 'São Paulo', 'Toronto'];
|
|
38
|
-
const streets = ['Main St', '2nd Ave', 'Broadway', 'Park Lane', 'Elm St', 'Sunset Blvd', 'Maple St', 'Highland Rd'];
|
|
39
|
-
|
|
40
|
-
const card = Array.from({ length: 4 }, () => randomNumber(1000, 9999)).join(' ');
|
|
41
|
-
const cvc = randomNumber(100, 999);
|
|
42
|
-
const expiration = `${String(randomNumber(1, 12)).padStart(2, '0')}/${(new Date().getFullYear() + randomNumber(0, 3)).toString().slice(-2)}`;
|
|
43
|
-
|
|
44
|
-
const person = random(people);
|
|
45
|
-
const social = person.social;
|
|
46
|
-
const country = person.country;
|
|
47
|
-
const phone = countries[country].tel;
|
|
48
|
-
const lang = countries[country].lang;
|
|
49
|
-
|
|
50
|
-
const age = randomNumber(18, 67);
|
|
51
|
-
const birthday = new Date(Date.now() - randomNumber(18, 67) * 365.25 * 24 * 60 * 60 * 1000).toISOString();
|
|
52
|
-
|
|
53
|
-
let emergencyContacts = [];
|
|
54
|
-
let yearIncome = randomNumber(20000, 100000);
|
|
55
|
-
let subscriptions = [];
|
|
56
|
-
let pets = [];
|
|
57
|
-
let vehicles = [];
|
|
58
|
-
let civilStatus = 'Single';
|
|
59
|
-
let children = 0;
|
|
60
|
-
|
|
61
|
-
if (age >= 21 && Math.random() > 0.7) civilStatus = 'Married';
|
|
62
|
-
|
|
63
|
-
if (civilStatus === 'Married' && age >= 25) children = randomNumber(0, 3);
|
|
64
|
-
|
|
65
|
-
while (emergencyContacts.length < randomNumber(1, 3)) {
|
|
66
|
-
let emergencyContact = random(people);
|
|
67
|
-
while (
|
|
68
|
-
emergencyContact.email === person.email ||
|
|
69
|
-
emergencyContacts.some(e => e.email === emergencyContact.email)
|
|
70
|
-
) {
|
|
71
|
-
emergencyContact = random(people);
|
|
72
|
-
}
|
|
73
|
-
const emergencyPhone = `${randomNumber(100, 999)}-${randomNumber(100, 999)}-${randomNumber(1000, 9999)}`;
|
|
74
|
-
emergencyContacts.push({
|
|
75
|
-
name: emergencyContact.name,
|
|
76
|
-
relationship: random(['Spouse', 'Parent', 'Sibling', 'Friend']),
|
|
77
|
-
phone: `+${countries[country].code} ${emergencyPhone}`
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
while (subscriptions.length < randomNumber(1, 3)) {
|
|
82
|
-
let subscription = random(['Netflix', 'Spotify', 'Amazon Prime', 'Disney+', 'Hulu']);
|
|
83
|
-
if (!subscriptions.includes(subscription)) subscriptions.push(subscription);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
while (pets.length < randomNumber(1, 3)) {
|
|
87
|
-
let pet = random(['Dog', 'Cat', 'Fish', 'Bird', 'None']);
|
|
88
|
-
if (!pets.includes(pet)) pets.push(pet);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
while (vehicles.length < randomNumber(1, 3)) {
|
|
92
|
-
let vehicle = random(['Car', 'Bike', 'Motorcycle', 'Bus', 'None']);
|
|
93
|
-
if (!vehicles.includes(vehicle)) vehicles.push(vehicle);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
name: person.name,
|
|
98
|
-
email: person.email,
|
|
99
|
-
localisation: country,
|
|
100
|
-
phone: `+${countries[country].code} ${phone}`,
|
|
101
|
-
job: random(jobs),
|
|
102
|
-
hobbies: random(hobbies),
|
|
103
|
-
language: lang,
|
|
104
|
-
card,
|
|
105
|
-
cvc,
|
|
106
|
-
expiration,
|
|
107
|
-
address: `${randomNumber(1, 9999)} ${random(streets)}, ${random(cities)}`,
|
|
108
|
-
birthday,
|
|
109
|
-
civil_status: civilStatus,
|
|
110
|
-
children,
|
|
111
|
-
vehicle: vehicles,
|
|
112
|
-
social_profiles: {
|
|
113
|
-
twitter: `@${social}`,
|
|
114
|
-
facebook: `facebook.com/${social}`,
|
|
115
|
-
linkedin: `linkedin.com/in/${social}`,
|
|
116
|
-
instagram: `instagram.com/${social}`
|
|
117
|
-
},
|
|
118
|
-
year_income: `${yearIncome} USD/year`,
|
|
119
|
-
month_income: `${(yearIncome / 12).toFixed(2)} USD/month`,
|
|
120
|
-
education: random(['High School', 'Bachelor\'s', 'Master\'s', 'PhD']),
|
|
121
|
-
work_experience: `${randomNumber(0, 20)} years`,
|
|
122
|
-
health_status: random(['Healthy', 'Minor Issues', 'Chronic Conditions']),
|
|
123
|
-
emergency_contacts: emergencyContacts,
|
|
124
|
-
subscriptions,
|
|
125
|
-
pets,
|
|
126
|
-
};
|
|
1
|
+
import { random, randomNumber } from './utils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate random personal information
|
|
5
|
+
*
|
|
6
|
+
* @returns {Object} Comprehensive personal profile with contact info, financial data, and more
|
|
7
|
+
*/
|
|
8
|
+
export default function personal() {
|
|
9
|
+
const people = [
|
|
10
|
+
{ name: 'John Doe', social: 'john_doe', email: 'john@example.com', country: 'US' },
|
|
11
|
+
{ name: 'Jane Martin', social: 'jane_martin', email: 'jane@example.com', country: 'FR' },
|
|
12
|
+
{ name: 'Michael Johnson', social: 'mike_johnson', email: 'michael@example.com', country: 'UK' },
|
|
13
|
+
{ name: 'Emily Davis', social: 'emily_davis', email: 'emily@example.com', country: 'ES' },
|
|
14
|
+
{ name: 'Alexis Barbos', social: 'alexis_barbos', email: 'alexis@example.com', country: 'DE' },
|
|
15
|
+
{ name: 'Sarah Williams', social: 'sarah_williams', email: 'sarah@example.com', country: 'IT' },
|
|
16
|
+
{ name: 'Daniel Brown', social: 'daniel_brown', email: 'daniel@example.com', country: 'JP' },
|
|
17
|
+
{ name: 'Sophia Wilson', social: 'sophia_wilson', email: 'sophia@example.com', country: 'BR' },
|
|
18
|
+
{ name: 'James Taylor', social: 'james_taylor', email: 'james@example.com', country: 'CA' },
|
|
19
|
+
{ name: 'Olivia Thomas', social: 'olivia_thomas', email: 'olivia@example.com', country: 'AU' }
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const countries = {
|
|
23
|
+
US: { tel: '123-456-7890', code: '1', lang: 'English' },
|
|
24
|
+
FR: { tel: '06 78 90 12 34', code: '33', lang: 'French' },
|
|
25
|
+
UK: { tel: '7911 123456', code: '44', lang: 'English' },
|
|
26
|
+
ES: { tel: '678 901 234', code: '34', lang: 'Spanish' },
|
|
27
|
+
DE: { tel: '163 555 1584', code: '49', lang: 'German' },
|
|
28
|
+
IT: { tel: '345 678 9012', code: '39', lang: 'Italian' },
|
|
29
|
+
JP: { tel: '080-1234-5678', code: '81', lang: 'Japanese' },
|
|
30
|
+
BR: { tel: '(11) 98765-4321', code: '55', lang: 'Portuguese' },
|
|
31
|
+
CA: { tel: '416-123-4567', code: '1', lang: 'English' },
|
|
32
|
+
AU: { tel: '0412 345 678', code: '61', lang: 'English' }
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const jobs = ['Writer', 'Artist', 'Musician', 'Explorer', 'Scientist', 'Engineer', 'Athlete', 'Doctor'];
|
|
36
|
+
const hobbies = ['Reading', 'Traveling', 'Gaming', 'Cooking', 'Fitness', 'Music', 'Photography', 'Writing'];
|
|
37
|
+
const cities = ['New York', 'Paris', 'London', 'Madrid', 'Berlin', 'Rome', 'Tokyo', 'Los Angeles', 'Sydney', 'São Paulo', 'Toronto'];
|
|
38
|
+
const streets = ['Main St', '2nd Ave', 'Broadway', 'Park Lane', 'Elm St', 'Sunset Blvd', 'Maple St', 'Highland Rd'];
|
|
39
|
+
|
|
40
|
+
const card = Array.from({ length: 4 }, () => randomNumber(1000, 9999)).join(' ');
|
|
41
|
+
const cvc = randomNumber(100, 999);
|
|
42
|
+
const expiration = `${String(randomNumber(1, 12)).padStart(2, '0')}/${(new Date().getFullYear() + randomNumber(0, 3)).toString().slice(-2)}`;
|
|
43
|
+
|
|
44
|
+
const person = random(people);
|
|
45
|
+
const social = person.social;
|
|
46
|
+
const country = person.country;
|
|
47
|
+
const phone = countries[country].tel;
|
|
48
|
+
const lang = countries[country].lang;
|
|
49
|
+
|
|
50
|
+
const age = randomNumber(18, 67);
|
|
51
|
+
const birthday = new Date(Date.now() - randomNumber(18, 67) * 365.25 * 24 * 60 * 60 * 1000).toISOString();
|
|
52
|
+
|
|
53
|
+
let emergencyContacts = [];
|
|
54
|
+
let yearIncome = randomNumber(20000, 100000);
|
|
55
|
+
let subscriptions = [];
|
|
56
|
+
let pets = [];
|
|
57
|
+
let vehicles = [];
|
|
58
|
+
let civilStatus = 'Single';
|
|
59
|
+
let children = 0;
|
|
60
|
+
|
|
61
|
+
if (age >= 21 && Math.random() > 0.7) civilStatus = 'Married';
|
|
62
|
+
|
|
63
|
+
if (civilStatus === 'Married' && age >= 25) children = randomNumber(0, 3);
|
|
64
|
+
|
|
65
|
+
while (emergencyContacts.length < randomNumber(1, 3)) {
|
|
66
|
+
let emergencyContact = random(people);
|
|
67
|
+
while (
|
|
68
|
+
emergencyContact.email === person.email ||
|
|
69
|
+
emergencyContacts.some(e => e.email === emergencyContact.email)
|
|
70
|
+
) {
|
|
71
|
+
emergencyContact = random(people);
|
|
72
|
+
}
|
|
73
|
+
const emergencyPhone = `${randomNumber(100, 999)}-${randomNumber(100, 999)}-${randomNumber(1000, 9999)}`;
|
|
74
|
+
emergencyContacts.push({
|
|
75
|
+
name: emergencyContact.name,
|
|
76
|
+
relationship: random(['Spouse', 'Parent', 'Sibling', 'Friend']),
|
|
77
|
+
phone: `+${countries[country].code} ${emergencyPhone}`
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
while (subscriptions.length < randomNumber(1, 3)) {
|
|
82
|
+
let subscription = random(['Netflix', 'Spotify', 'Amazon Prime', 'Disney+', 'Hulu']);
|
|
83
|
+
if (!subscriptions.includes(subscription)) subscriptions.push(subscription);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
while (pets.length < randomNumber(1, 3)) {
|
|
87
|
+
let pet = random(['Dog', 'Cat', 'Fish', 'Bird', 'None']);
|
|
88
|
+
if (!pets.includes(pet)) pets.push(pet);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
while (vehicles.length < randomNumber(1, 3)) {
|
|
92
|
+
let vehicle = random(['Car', 'Bike', 'Motorcycle', 'Bus', 'None']);
|
|
93
|
+
if (!vehicles.includes(vehicle)) vehicles.push(vehicle);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
name: person.name,
|
|
98
|
+
email: person.email,
|
|
99
|
+
localisation: country,
|
|
100
|
+
phone: `+${countries[country].code} ${phone}`,
|
|
101
|
+
job: random(jobs),
|
|
102
|
+
hobbies: random(hobbies),
|
|
103
|
+
language: lang,
|
|
104
|
+
card,
|
|
105
|
+
cvc,
|
|
106
|
+
expiration,
|
|
107
|
+
address: `${randomNumber(1, 9999)} ${random(streets)}, ${random(cities)}`,
|
|
108
|
+
birthday,
|
|
109
|
+
civil_status: civilStatus,
|
|
110
|
+
children,
|
|
111
|
+
vehicle: vehicles,
|
|
112
|
+
social_profiles: {
|
|
113
|
+
twitter: `@${social}`,
|
|
114
|
+
facebook: `facebook.com/${social}`,
|
|
115
|
+
linkedin: `linkedin.com/in/${social}`,
|
|
116
|
+
instagram: `instagram.com/${social}`
|
|
117
|
+
},
|
|
118
|
+
year_income: `${yearIncome} USD/year`,
|
|
119
|
+
month_income: `${(yearIncome / 12).toFixed(2)} USD/month`,
|
|
120
|
+
education: random(['High School', 'Bachelor\'s', 'Master\'s', 'PhD']),
|
|
121
|
+
work_experience: `${randomNumber(0, 20)} years`,
|
|
122
|
+
health_status: random(['Healthy', 'Minor Issues', 'Chronic Conditions']),
|
|
123
|
+
emergency_contacts: emergencyContacts,
|
|
124
|
+
subscriptions,
|
|
125
|
+
pets,
|
|
126
|
+
};
|
|
127
127
|
}
|
package/modules/v3/qrcode.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { toDataURL } from 'qrcode';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Generate a QR code for the provided URL.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} url - The URL to encode in the QR code
|
|
7
|
-
* @returns {Promise<string>} - Base64 encoded QR code image
|
|
8
|
-
* @throws {Error} - If URL is invalid or QR code generation fails
|
|
9
|
-
*/
|
|
10
|
-
export default async function qrcode(url) {
|
|
11
|
-
// Input validation
|
|
12
|
-
if (!url || typeof url !== 'string') throw new Error('Please provide a valid URL');
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
// Generate QR code
|
|
16
|
-
return await toDataURL(url);
|
|
17
|
-
} catch (error) {
|
|
18
|
-
throw new Error(`Failed to generate QR code: ${error.message}`);
|
|
19
|
-
}
|
|
1
|
+
import { toDataURL } from 'qrcode';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate a QR code for the provided URL.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} url - The URL to encode in the QR code
|
|
7
|
+
* @returns {Promise<string>} - Base64 encoded QR code image
|
|
8
|
+
* @throws {Error} - If URL is invalid or QR code generation fails
|
|
9
|
+
*/
|
|
10
|
+
export default async function qrcode(url) {
|
|
11
|
+
// Input validation
|
|
12
|
+
if (!url || typeof url !== 'string') throw new Error('Please provide a valid URL');
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
// Generate QR code
|
|
16
|
+
return await toDataURL(url);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw new Error(`Failed to generate QR code: ${error.message}`);
|
|
19
|
+
}
|
|
20
20
|
}
|