WEBVTT 0 00:00.410 --> 00:00.680 All right. 1 00:00.690 --> 00:03.620 So here comes the next problem that we have to solve. 2 00:03.810 --> 00:11.670 As I showed you before, if we head over to compose and we created a new post that just had a title of 3 00:11.670 --> 00:19.980 Test an our URL if we type posts/Test spelt at exactly the same way as our title when we hit 4 00:20.010 --> 00:23.280 enter then we get match found 5 00:23.280 --> 00:23.720 right? 6 00:23.910 --> 00:30.900 But here's a problem. Let's say if I go into my Atom and if the requestedTitle is not equal to any of 7 00:30.900 --> 00:34.070 the store title I have, I'm going to use else 8 00:34.110 --> 00:37.270 and then I'm going to log not a match. 9 00:37.680 --> 00:41.380 So now if I again go and create my Test post 10 00:41.700 --> 00:47.140 and now inside my home page I've got home and test. I can see that I've got that there 11 00:47.160 --> 00:48.420 but in the URL 12 00:48.450 --> 00:57.750 if I put /posts/test with a lowercase 't', in this case once I hit enter inside my 13 00:57.750 --> 01:00.690 console you can see I get not a match. 14 01:00.960 --> 01:08.160 And that is because in our code we're testing to see if storedTitle is equal to requestedTitle. 15 01:08.400 --> 01:14.680 And if the requestedTitle had a lowercase t and our storedTitle because it's a title right? 16 01:14.790 --> 01:16.860 It probably has a title case right? 17 01:16.850 --> 01:19.600 So most of the words are capitalized. Then 18 01:19.650 --> 01:21.550 this is not going to be true. 19 01:21.870 --> 01:27.630 But in most cases, URLs should be lowercase. so it doesn't really make sense to put in a capital 20 01:27.630 --> 01:30.630 T in there, it looks very very weird. 21 01:30.630 --> 01:35.610 The other problem we have is that when you look at some of the blog posts say medium right? 22 01:35.760 --> 01:41.070 You can see that they use word - word as their formatting for the URL. 23 01:41.340 --> 01:44.880 And this is what we call kebab case in programming. 24 01:44.880 --> 01:52.530 Now if I had a post that has two words in his title and I tried to use kebab case on it, say / 25 01:52.530 --> 01:54.540 posts/ 26 01:54.540 --> 01:57.810 Another-post, 27 01:57.810 --> 02:00.770 then it's also going to be not a match 28 02:00.780 --> 02:02.100 right? 29 02:02.160 --> 02:03.750 How do we solve this? 30 02:03.780 --> 02:11.110 I want to introduce you to something that developers use a lot with Node which is something called Lodash. 31 02:11.430 --> 02:20.020 And this is simply a utility library that makes it easier to work with Javascript inside your Node apps. 32 02:20.340 --> 02:27.850 If you head over here to lodash.com you can see how to install it, how to use it inside Node. 33 02:28.050 --> 02:29.600 Now here comes the challenge. 34 02:29.610 --> 02:34.290 The goal of this challenge is for you to read through the documentation of Lodash 35 02:34.500 --> 02:38.930 and I want you to have experience and practice in implementing the documentation. 36 02:39.210 --> 02:46.500 We've already used a couple of libraries now such as Express, EJS, Requests and I want you to have practice 37 02:46.590 --> 02:51.010 of implementing the documentation in a safe kind of environment 38 02:51.030 --> 02:53.620 right? Because I'll show you how to do it very soon. 39 02:53.730 --> 02:55.250 But I want you to give it a go. 40 02:55.350 --> 03:01.300 And once you've installed it and required it, then I want you to head over to the documentation. And if 41 03:01.300 --> 03:09.930 you search for lowercase then you can see that they have a method that allows you to turn all strings 42 03:10.020 --> 03:11.640 into a lower case. 43 03:11.920 --> 03:17.850 And if you look at the example it actually goes much further than that. It will in fact ignore all of 44 03:17.850 --> 03:24.630 the hyphens or the underscores and it will simply just give you a pure string to work with. 45 03:24.630 --> 03:32.130 So you should be able to use this library in order to make this URL actually give us a match for this 46 03:32.190 --> 03:33.620 particular title. 47 03:33.660 --> 03:37.930 When I type in this URL after you are done with implementing Lodash 48 03:38.370 --> 03:46.780 and when I hit enter, in our console we should see match found. Pause the video and try to complete this challenge. 49 03:48.060 --> 03:50.770 So here's hint number 1. 50 03:50.820 --> 03:56.640 If you check out lodash.com you can see they tell you how to install it and it shows you how to do 51 03:56.640 --> 03:57.800 it using NPM. 52 03:57.800 --> 04:02.990 And this is pretty familiar to us by now. We just have to install Lodash right? 53 04:03.000 --> 04:04.200 So let's go ahead and do that. 54 04:04.200 --> 04:10.750 Let's head over to hyper and let's Control + C to quit our current nodemon session. And 55 04:11.100 --> 04:15.780 we're going to use npm i or npm install whichever way you prefer. 56 04:16.020 --> 04:21.420 And then we're going to spell out lodash and make sure that you have the right spelling. 57 04:21.420 --> 04:22.470 Then we hit enter 58 04:22.530 --> 04:25.980 and that gets installed to our current project. 59 04:25.980 --> 04:32.280 The next thing you see here in the documentation is how to use it using Node.js which is perfect 60 04:32.280 --> 04:32.950 right? 61 04:33.060 --> 04:37.120 And you can see this familiar require thing that we've got going on. 62 04:37.320 --> 04:44.970 And the thing about Lodash is that a Lodash actually refers to this which is known to some people 63 04:45.000 --> 04:46.710 as an underscore. 64 04:46.710 --> 04:53.690 And so their preferred way of working with Node is to create a new variable or constant 65 04:53.700 --> 05:00.750 if you're using your versions of Javascript that is simply just a underscore and you set that to be 66 05:00.780 --> 05:02.420 the Lodash library. 67 05:02.790 --> 05:09.420 And then when you go to the documentation and you want to use one of its methods say the one we want 68 05:09.420 --> 05:17.060 which is lower case, then you simply have underscore or lodash .lowercase and then in between 69 05:17.130 --> 05:20.330 you pass in the string that you want to change into lowercase. 70 05:20.550 --> 05:24.470 See if that is enough of a hint to be able to complete the challenge. 71 05:26.290 --> 05:27.290 So here comes hint 72 05:27.310 --> 05:35.560 number 2. In order for our requestedTitle to match with our storedTitle we need to reformat them so they're 73 05:35.650 --> 05:38.120 both in the same format. 74 05:38.380 --> 05:44.590 And it doesn't matter whatever it is that the user typed in here. It could be uppercase, lowercase, kebab 75 05:44.590 --> 05:47.400 case, snake case, whatever it may be. 76 05:47.440 --> 05:52.750 We want to convert it to the same format in order to work with it and compare it. 77 05:52.750 --> 05:58.660 And that means that we have to format the storedTitle using that same lowercase method as well so that 78 05:58.660 --> 06:00.200 they are equatable. 79 06:00.250 --> 06:04.300 Pause the video now and see if you can now complete the challenge.