How to use the isInteger function from lodash

Find comprehensive JavaScript lodash.isInteger code examples handpicked from public code repositorys.

lodash.isInteger is a method that checks whether a given value is an integer or not, returning a boolean value.

195
196
197
198
199
200
201
202
203
204
module.exports.isFloat             = _.isFloat;
module.exports.isFunction          = _.isFunction;
module.exports.isIncreasing        = _.isIncreasing;
module.exports.isIndexed           = _.isIndexed;
module.exports.isInstanceOf        = _.isInstanceOf;
module.exports.isInteger           = _.isInteger;
module.exports.isJSON              = _.isJSON;
module.exports.isLength            = _.isLength;
module.exports.isMap               = _.isMap;
module.exports.isMatch             = _.isMatch;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

158
159
160
161
162
163
164
165
166
167

  wait(60).then(() => vss.sessions.restart(device.id))
},

toDb: (device) => {
  int = (x) => _.isInteger(x) && x !== -999 && x !== 999 ? x : undefined

  log.info(`Syncing deviceId=${device.id} from VSS to DB ...`)
  vss.devices.get(device.id, dayjs().subtract(config.refreshInterval).unix()).then(res => {
    const statuses = res.data.map(r => { return {
fork icon0
star icon28
watch icon1

+ 10 other calls in file

How does lodash.isInteger work?

lodash.isInteger is a method that takes in a value and checks if it is an integer or not.

It returns true if the value is a finite integer, meaning it is not NaN or Infinity, and if it is of the type "number" in JavaScript, and if its value is the same when rounded down to the nearest integer. Otherwise, it returns false.

434
435
436
437
438
439
440
441
442
443
444
445
446
console.log(isFinite); // => true


const isFunction = _.isFunction(() => {});
console.log(isFunction); // => true


const isInteger = _.isInteger(1);
console.log(isInteger); // => true


const isLength = _.isLength(3);
console.log(isLength); // => true
fork icon0
star icon4
watch icon0

+ 15 other calls in file

580
581
582
583
584
585
586
587
588
589
case "array":
  hasCorrectType = _.isArray(value);
  sanitizedValue = sanitize(JSON.stringify(value));
  break;
case "number":
  hasCorrectType = _.isInteger(value);
  sanitizedValue = value;
  break;
case "focusMode":
  hasCorrectType =
fork icon0
star icon3
watch icon1

Ai Example

1
2
3
4
5
const _ = require("lodash");

console.log(_.isInteger(5)); // true
console.log(_.isInteger(5.5)); // false
console.log(_.isInteger("5")); // false

In this example, lodash.isInteger is used to check if a value is an integer number. The function returns true if the input is an integer, and false otherwise.

31
32
33
34
35
36
37
38
39
40
    return null;
} else if (_.isNumber(obj)) {
    const intNum = _.toNumber(obj);
    // if the number is negative it means it's an event before 1970
    // but from a business perspective this is not accepted
    if (!_.isNaN(intNum) && intNum >= 0 && _.isInteger(intNum)) {
        if (Dates.isValidDate(new Date(intNum))) {
            return new Date(intNum);
        }
    }
fork icon0
star icon0
watch icon1

+ 23 other calls in file

9
10
11
12
13
14
15
16
17
18
19
  SUPPORTED_ALGS.splice(3, 0, 'PS256', 'PS384', 'PS512');
}


const sign_options_schema = {
  expiresIn: { isValid: function(value) { return isInteger(value) || (isString(value) && value); }, message: '"expiresIn" should be a number of seconds or string representing a timespan' },
  notBefore: { isValid: function(value) { return isInteger(value) || (isString(value) && value); }, message: '"notBefore" should be a number of seconds or string representing a timespan' },
  audience: { isValid: function(value) { return isString(value) || Array.isArray(value); }, message: '"audience" must be a string or array' },
  algorithm: { isValid: includes.bind(null, SUPPORTED_ALGS), message: '"algorithm" must be a valid string enum value' },
  header: { isValid: isPlainObject, message: '"header" must be an object' },
  encoding: { isValid: isString, message: '"encoding" must be a string' },
fork icon0
star icon0
watch icon1

35
36
37
38
39
40
41
42
43
44
45
 * @param {boolean} options.isDraft
 *
 * @returns {StringSchema}
 */
const addMinLengthValidator = (validator, { attr }, { isDraft }) =>
  _.isInteger(attr.minLength) && !isDraft ? validator.min(attr.minLength) : validator;


/**
 * Adds maxLength validator
 * @param {StringSchema} validator yup validator
fork icon0
star icon0
watch icon1

+ 7 other calls in file

72
73
74
75
76
77
78
79
80
81
let where = parameters;

for (const key in where) {
  if (where.hasOwnProperty.call(where, key)) {
    const element = where[key];
    if (element.length || isInteger(element) || element === Object(element)) {
      where[key] = element;
    } else {
      delete where[key];
    }
fork icon0
star icon0
watch icon1

167
168
169
170
171
172
173
174
175
176
 * @param {string} [errorMessage] the error message. If defined and the predicate is not fulfilled an error with the message will be thrown
 * @param {string|number|(string|number)[]} [messageArgs] values for placeholders in the errorMessage
 * @returns {boolean} the result of the predicate
 */
anInteger(errorMessage, messageArgs) {
    let success = _.isInteger(this.#contextValue);
    if (Debug.enabled) {
        this.#printDebug(this.anInteger.name, success);
    }
    return this.#handleError(success, errorMessage, messageArgs);
fork icon0
star icon0
watch icon1

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)