In the last video we left off having just created a class User right here once again if you see a warning
around this class definition that's totally fine.
We're going to fix it up in just a second.
So in this video I want to focus on our implementation of a user.
Remember we had said that a user should have a couple of different properties assigned to it.
There will be randomly generated that should probably be like a user's name and their location as well.
To get started I think that we should define a couple of different fields on our User class.
Then we can figure out how to randomly generate those properties all right.
I'm gonna flip back over to my class definition and inside of here I'm going to assign two different
properties to my user.
I'm going to say that every user is going to have a name property that has a string and a location property
that's going to be an object that has a latitude that is a number and a longitude that is a number as
well.
So that stands for latitude.
LNG stands for longitude.
Remember we can use latitude and longitude to model a physical location in the world.
So we're going to eventually randomly generate a latitude and longitude assign it to this user and use
that data to decide where to map a user on our Google Map interface.
Okay.
So now that we've defined these properties right here we need to eventually initialize them.
Remember every time we define a property we need to in either initialize it on the same exact line or
inside the constructor.
Usually we will initialize the property on the same line if it's gonna be some hardcoded value.
But in this case we want to randomly generate a name and a latitude and longitude so we will instead
do our initialization inside of a constructor function instead.
So I'm going to define my constructor function right here.
Like so all right.
So we've got our place to initialize the name latitude longitude.
All we need now is our randomly generated data.
So for that let's take a look at some documentation for a library that we're going to use to generate
that information all right.
So quick link right here.
We're gonna go to NPM J.S. dot com and take a look at the documentation for a package called Faker The
fake or package gives us the ability to randomly generate a bunch of different types of information
which makes it really well suited for the project we are working on right now.
So I'm going to go to NPM J.S. dot com once here I'm going to search for faker at the top and I should
see it as one the first results on here.
All right so here's the documentation.
You can scroll down a little bit.
And underneath API right here or some not API next section down here we go.
API methods.
This is the absolute extent of all the documentation we get.
Unfortunately it's not super detailed.
So what this is essentially saying is that the faker package has a module inside of it called address
and we can use the address module to randomly generate a zip code a city street name a county a country
state latitude longitude.
Well those look really relevant.
And so on likewise there is a company module that we can use to randomly generate a catchphrase or a
company name and so on if you scroll down a little bit more you'll also find a section inside of here
called name.
And we can use this module to generate a first name last name and so on.
So as you might guess we're gonna use this name module to generate some information for our user.
We'll use the company module backup here to generate some random information for the companies we create
inside of our app.
And finally for both the user and the company we'll use the address module to generate a random latitude
and longitude.
So looks like the faker module is really going to take care of all of our data requirements for our
application.
So all we have to do is install this thing.
So to install this package I need to flip back or add my terminal inside of my project directory.
I'm going to stop the running partial server with control C then I'll do an npm install Baker like so.
And that's pretty much it.
Now the package is pretty small so it should complete installation rather quickly once it's all done
it will start up partial once again with partial index.
Each demo All right.
So now we can flip back over to our Ed and make use of faker to do so I'm gonna go to the top of the
file inside my user file and I'm going to import the faker module import statements inside of typescript
look identical to import statements in yes 2015.
So if you've ever worked on a react or angular application you're probably gonna be right at home.
In other words to access a module that we install with NPM.
We have to do is write out import faker from faker like so that's going to reach into our package to
me node modules directory right here.
It's gonna find that faker module that we just installed and it's going to give us access to all the
code inside there through a variable called faker.
Now there's just one little issue here.
If we hover over faker we're going to see a little error message right here it says could not find a
declaration file for module faker.
Now this is an error or a warning that you're going to see many many many times as you start to work
on types of projects.
So let's take a quick pause right here and talk about why we are seeing this little warning message.