basic usage of 1.inspect functions
Util.inspect (Object,[showhidden],[depth],[colors]) is a function that converts any object to a string, typically for debugging and error output. It accepts at least one parameter, object, which is to be converted, and we learn its simple usage. Use the following syntax:
- var util = require(' util ');
- var result = util. Inspect(object);
- Console. Log(result);
basic usage of 2.format functions
The Format function returns a formatted string based on the first argument, which is a string that can contain 0 or more placeholders. Each placeholder is replaced with its corresponding converted value, and the supported placeholders are: "%s (String)", "%d (numeric < integer and floating point >)", "%j (JSON)", "%" (a single percent of a semicolon is not a parameter).
1: If the placeholder does not have a corresponding parameter, the placeholder will not be replaced. As an example:
- var util = require(' util ');
- var result = util. Format('%s:%s ', ' foo ');
- Console. Log(result);
Operation Result:
- ' foo:%s '
2: If there are more than one parameter placeholder, the extra parameter will call Util.inspect () to the string. These strings are concatenated together and separated by a space. As an example:
- var util = require ( ' util '
- var result Span class= "pun" >= Util. ( '%s:%s ' , ' foo ' , ' bar ' , ' Baz '
- console.result
Operation Result:
- ' Foo:bar Baz '
3: If the first argument is a non-formatted string, all arguments are converted to a string and stitched together in a space, and the string is returned. As an example:
- var util = require(' util ');
- var result = util. Format(1, 2, 3);
- Console. Log(result);
Operation Result:
- ' 1 2 3 '
basic usage of 3.isArray functions
The IsArray function can determine whether an object is an array type, or it returns ture, otherwise false. The syntax is as follows:
- var util = require(' util ');
- var result = util. IsArray(object);
- Console. Log(result);
basic usage of 4.isDate functions
The IsDate function can determine whether the object is a date type, or return ture, otherwise false. The syntax is as follows:
- var util = require(' util ');
- var result = util. IsDate(object);
- Console. Log(result);
basic usage of 5.ISREGEXP functions
The ISREGEXP function can determine whether the object is a regular type, or return ture, otherwise false. The syntax is as follows:
- var util = require(' util ');
- var result = util. Isregexp(object);
- Console. Log(result);
node. JS (vi) UTIL module