官术网_书友最值得收藏!

Using the _.isString utility

To use the _.isString utility, we'll add console.log in app.js to show the result to the screen and we'll use _.isString, passing in a couple of values. Let's pass in true first, then we can duplicate this line and we'll pass in a string such as Gary, as shown here:

console.log('Starting app.js');

const fs = require('fs');
const os = require('os');
const _ = require('lodash');
const notes = require('./notes.js');

console.log(_.isString(true));
console.log(_.isString('Gary'));

// console.log('Result:', notes.add(9, -2));

// var user = os.userInfo();
//
// fs.appendFile('greetings.txt', `Hello ${user.username}! You are ${notes.age}.`);

We can run our project over in the Terminal using the same command we've used previously, node app.js, to run our file:

When we run the file, we get our two prompts that we've started both files, and we get false and then true. false comes because the Boolean is not a string, and true comes up because Gary is indeed a string, so it passes the test of _.isString. This is one of the many utility functions that comes bundled with lodash.

Now, lodash can do a lot more than simple type checking. It comes with a bunch of other utility methods we can take advantage of. Let's explore one more utility.

主站蜘蛛池模板: 亳州市| 定州市| 横山县| 和平区| 呼和浩特市| 平潭县| 皮山县| 元阳县| 海口市| 博兴县| 平潭县| 和林格尔县| 灵石县| 芒康县| 秭归县| 林口县| 霍城县| 赤壁市| 蛟河市| 涿州市| 龙川县| 兴文县| 瑞金市| 千阳县| 百色市| 河东区| 江安县| 永泰县| 潼南县| 阜城县| 十堰市| 海南省| 朝阳市| 湘潭市| 会东县| 柞水县| 金溪县| 沈丘县| 怀化市| 武冈市| 邵阳县|