diff --git a/CHANGELOG b/CHANGELOG index 5cd4220..74fcd4a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +#1.18.0 +- feat: isUndefined + #1.17.0 - feat: assignWith - feat: clone diff --git a/README.md b/README.md index 0cd6ddd..491b941 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Currently supported utils: - `isObjectLike` - Checks if passed `value` is object-like. A value is object-like if it's not `null` - `isPlainObject` - checks if input is object, not null object and not array object - `isString` - checks if input is a string +- `isUndefined` - checks if an input is undefined - `mapKeys` - creates new object with the same values but with keys mapped by the provided function - `mapValues` - Maps the values of an object or array using the provided iteratee function or property path - `max` - computes the maximum value of array. If array is empty or falsey, undefined is returned diff --git a/index.d.ts b/index.d.ts index f2dd67d..8fae2ab 100644 --- a/index.d.ts +++ b/index.d.ts @@ -24,6 +24,7 @@ export function isObject (verifiable: any): Boolean export function isObjectLike(value: any): boolean export function isPlainObject (val: any): boolean export function isString (val: any): boolean +export function isUndefined (val: any): boolean export function mapKeys(obj: Object, mapper: (val: any, key: string) => string): Object export function mapValues(obj: Object, mapper: (val: any, key: string) => any): Object export function max (array: Array): any diff --git a/index.js b/index.js index 8d51fbf..92a6ffa 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,7 @@ const isObject = require('./src/isObject') const isObjectLike = require('./src/isObjectLike') const isPlainObject = require('./src/isPlainObject') const isString = require('./src/isString') +const isUndefined = require('./src/isUndefined') const mapKeys = require('./src/mapKeys') const mapValues = require('./src/mapValues') const max = require('./src/max') @@ -75,6 +76,7 @@ module.exports = { isObjectLike, isPlainObject, isString, + isUndefined, mapKeys, mapValues, max, diff --git a/package.json b/package.json index 5af873f..bb4a294 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bitfinexcom/lib-js-util-base", - "version": "1.17.0", + "version": "1.18.0", "description": "general utils", "main": "index.js", "scripts": { diff --git a/src/isUndefined.js b/src/isUndefined.js new file mode 100644 index 0000000..d13bd06 --- /dev/null +++ b/src/isUndefined.js @@ -0,0 +1,7 @@ +'use strict' + +const isUndefined = (val) => { + return val === undefined +} + +module.exports = isUndefined diff --git a/test/isUndefined.js b/test/isUndefined.js new file mode 100644 index 0000000..302cc3e --- /dev/null +++ b/test/isUndefined.js @@ -0,0 +1,39 @@ +'use strict' + +/* eslint-env mocha */ +const assert = require('assert') +const isUndefined = require('../src/isUndefined') + +describe('isUndefined', () => { + it('should return true for undefined', () => { + assert.ok(isUndefined(undefined)) + }) + + it('should return true for no param', () => { + assert.ok(isUndefined()) + }) + + it('should return false for empty object', () => { + assert.equal(isUndefined({}), false) + }) + + it('should return false for empty array', () => { + assert.equal(isUndefined([]), false) + }) + + it('should return false for null', () => { + assert.equal(isUndefined(null), false) + }) + + it('should return false for false', () => { + assert.equal(isUndefined(false), false) + }) + + it('should return false for empty string', () => { + assert.equal(isUndefined(''), false) + }) + + it('should return false for zero', () => { + assert.equal(isUndefined(0), false) + }) +})