Kent walks through the solution to the Creating the Library exercise. The code for the solution is located on the FEM/03.1-create-lib branch.
- [Instructor] Just to quickly review the solutions so we're all on the same page, so what we're doing here, actually, I'm going to go ahead and check out the next branch; and we'll review that solution because that's what we're going to have going forward because it might have been a slightly different. Oh yeah, of course, use strict because, like, we got to do that when we're just in ES5 land. Although this is node six, so we're actually in ES6 land here. But, yeah, so unique random array, we're pulling that from the unique random array module, which was, basically its whole purpose is to take an array and give you back a function you can call to get a random item out of that array.
So this is micro libraries to the max, but it's nice because now we don't have to test any of our functionality around a function to get a random item out of an array, which is cool. Then we also get Star Wars names from the .json file. Our Star Wars name's JSON, so this is all running in Node. We're not doing anything with the browser yet, and so we can just pull that right from, from the file system; and then we export an object with an all property and a random property so that we can use those; and then by running Node, we can simply require source, which will default to the index.
And then just say random, and we'll get a random Star Wars name. We can say all and get all of the characters. So that is that for actually creating the library. We're not going to add any more functionality really. Well, when we start transplanting with ES6, then we'll start playing around with some ES6 features; but, yeah, for now, this is pretty much it, maybe a little anti-climatic; but it's a macro library, so there you go, and we're not, like, I'm not teaching you how to make a Star Wars names library.
I'm teaching you how to make a library, so hopefully this is sufficient.
Note: This course was created by Frontend Masters. It was originally released on 08/09/2016. We're pleased to host this training in our library.
- Creating an open-source library
- Linting and testing
- Code coverage
- Installing and configuring Babel
- Peer dependencies
- Forking and renaming
- Continuous integration and automating releases