-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.ts
132 lines (119 loc) · 4.76 KB
/
code.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
const availableCharcters = "abcdefghijklmnopqrstuvwxyz0123456789";
const emailProvider = ["gmail", "yahoo", "hotmail", "outlook", "icloud"];
const firstName = ["Aabesh","Aabishkar","Aadesh","Aaryan","Abhinav","Achut","Adarsh","Akhil","Anish","Babik","Badal","Bappa","Bhaskar","Bhupal","Bibidh","Bishwaraj","Brijesh","Cheetri","Chetan","Dawa","Deepson","Denis","Dev","Dharma","Fanindra","Gagan","Ganesh","Gaurav","Girish","Gyanu","Haridas","Hem","Indra","Ishwar","Jagadish","Jeevan","Kabir","Kamal","Kanchan","Kapil","Karun","Ketan","Kirtiman","Kovid","Krsna","Kumar","Lokesh","Maansa","Madan","Madhav","Mahindra","Mangal","Manzil","Meera","Milan","Mukti","Mukul","Murali","Naval","Neel","Nehan","Nigam","Nimish","Niral","Nirav","Omprakash","Pabitra","Paresh","Pavan","Prabal","Pradeep","Pratik","Puru","Rabin","Rahul","Rakshek","Rama","Ranjit","Raz","Resham","Ridam","Rituraj","Roshan","Rudra","Sabir","Ada","Anupama","Akrodinni","Bagh","Bairagi","Bijayata","Chet","Chaitna","Charushri","Daxa","Deena","Dipika","Eakveera","Ferika","Faleesha","Gita","Ganga","Garima","Himani","Hreeta","Irsia","Ireshi","Jahan","Jwala","Januka","Jenisha","Koel","Khavia","Karishma","Laksmi","Mina","Myra","Mithu","Mahini","Mandira","Neeta","Nisha","Ojmana","Ojasini","Pihu","Puja","Priti","Pragya","Rim","Reya","Richika","Sani","Soma","Shila","Suhana","Tulsi","Tripati","Ulyana","Veerata","Vrushali"];
const lastName = ["Adhikari","Buddhacharya","Bishwakarma","Chaudhary","Chowdhury","Chhetri","Chetry","Gurung","Magar","Maharjan","Pokharel","Rai","Shah","Shrestha","Singh","Tamang","Thapa","Tharu"];
// This shows the HTML page in "ui.html".
figma.showUI(__html__);
// Calls to "parent.postMessage" from within the HTML page will trigger this
// callback. The callback will be passed the "pluginMessage" property of the
// posted message.
figma.ui.onmessage = async (msg) => {
// currently only ui is designed
// message has not yet been passed
let message: string = "";
switch (msg.type) {
case "first-name":
message = getFirstName();
break;
case "last-name":
message = getLastName();
break;
case "full-name":
message = getFullName();
break;
case "email":
message = getEmail();
break;
case "phn":
message = getPhoneNumber();
break;
case "address":
message = "Zero K.M, Pokhara";
break;
case "date":
message = getRandomDate();
break;
default:
// code
}
const text = figma.createText();
text.x = figma.viewport.center.x;
text.y = figma.viewport.center.y;
await figma.loadFontAsync(text.fontName as FontName);
text.characters = message;
};
/**
* Function to get first name
* @returns {string} first name
*/
const getFirstName = (): string => {
const randomNumber = getRandomInt(0, firstName.length);
const fName: string = firstName[randomNumber];
return fName;
};
/**
* Function to get last name
* @returns {string} last name
*/
const getLastName = (): string => {
const randomNumber = getRandomInt(0, lastName.length);
const lName: string = lastName[randomNumber];
return lName;
};
/**
* Function to get full name
* @returns {string} full name
*/
const getFullName = (): string => {
const fName = getFirstName();
const lName = getLastName();
const fullName: string = `${fName} ${lName}`;
return fullName;
};
/**
* Function to generate a random phone number
* @returns {string} phone number
*/
const getPhoneNumber = (): string => {
let phnNumber: string = `+977 984`
for (let i = 0; i < 7; i++) {
phnNumber += `${getRandomInt(0, 9)}`;
}
return phnNumber;
}
/**
* Funtion to generate a random email address
* @returns {string} email address
*/
const getEmail = (): string => {
let emailLength = getRandomInt(10, 15);
let email: string = "";
while(emailLength>0){
emailLength--;
email += availableCharcters[getRandomInt(0, availableCharcters.length)];
}
email += `@${emailProvider[getRandomInt(0, emailProvider.length)]}.com`;
return email;
}
/**
* Function to generate a random date
* @returns {string} date
*/
const getRandomDate = (): string => {
const year = getRandomInt(1970, 2020);
const month = getRandomInt(1, 12);
const day = getRandomInt(1, 28);
const date = `${year}-${month}-${day}`;
return date;
}
/**
* Function to generate a random number within a range
* @param {number} min - Minimum range
* @param {number} max - Maximum range
* @returns {number} between min and max
*/
const getRandomInt = (min, max): number => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
};