From 377135a632af56e38f3996e7227c5baa34df2821 Mon Sep 17 00:00:00 2001 From: Sergio LR Date: Wed, 20 Nov 2024 17:27:58 +0100 Subject: [PATCH 1/4] feat: isUndefined --- CHANGELOG | 3 +++ README.md | 1 + index.d.ts | 1 + index.js | 2 ++ package.json | 2 +- src/isUndefined.js | 7 +++++++ test/isUndefined.js | 16 ++++++++++++++++ 7 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/isUndefined.js create mode 100644 test/isUndefined.js diff --git a/CHANGELOG b/CHANGELOG index 67f8188..8873ca6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +#1.16.0 +- feat: isUndefined + #1.15.0 - feat: snakeCase - feat: promiseResolveCb diff --git a/README.md b/README.md index a5b4fe1..d2a929f 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Currently supported utils: - `isObject` - checks if the input is not a nullable object instance - `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 c8bb38d..59fae90 100644 --- a/index.d.ts +++ b/index.d.ts @@ -19,6 +19,7 @@ export function isNumber (val: any): boolean export function isObject (verifiable: 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 45ee650..d7b4bd6 100644 --- a/index.js +++ b/index.js @@ -21,6 +21,7 @@ const isNumber = require('./src/isNumber') const isObject = require('./src/isObject') 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') @@ -59,6 +60,7 @@ module.exports = { isObject, isPlainObject, isString, + isUndefined, flow, mapKeys, mapValues, diff --git a/package.json b/package.json index b45f0d3..0a9b1f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bitfinexcom/lib-js-util-base", - "version": "1.15.0", + "version": "1.16.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..de6162d --- /dev/null +++ b/test/isUndefined.js @@ -0,0 +1,16 @@ +'use strict' + +/* eslint-env mocha */ + +const assert = require('assert') +const { isUndefined } = require('../index') + +describe('isUndefined', () => { + it('should return true for undefined', () => { + assert.ok(isUndefined(undefined)) + }) + + it('should return true for no param', () => { + assert.ok(isUndefined()) + }) +}) From a26163093bf5a12e076c5fe69b6f5701b87e87f9 Mon Sep 17 00:00:00 2001 From: Sergio LR Date: Wed, 20 Nov 2024 18:17:51 +0100 Subject: [PATCH 2/4] fix: re-exporting same flow --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 779c742..8c59eee 100644 --- a/index.js +++ b/index.js @@ -57,7 +57,6 @@ module.exports = { cloneDeep, difference, findLastIndex, - flow, freezeDeep, get, getArrayHasIntersect, From 20ae66d2a5f1c941bb0c130e6c1b2c51ab82a511 Mon Sep 17 00:00:00 2001 From: Sergio LR Date: Wed, 20 Nov 2024 20:29:32 +0100 Subject: [PATCH 3/4] feat: add more test cases --- test/isUndefined.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/test/isUndefined.js b/test/isUndefined.js index de6162d..302cc3e 100644 --- a/test/isUndefined.js +++ b/test/isUndefined.js @@ -1,9 +1,8 @@ 'use strict' /* eslint-env mocha */ - const assert = require('assert') -const { isUndefined } = require('../index') +const isUndefined = require('../src/isUndefined') describe('isUndefined', () => { it('should return true for undefined', () => { @@ -13,4 +12,28 @@ describe('isUndefined', () => { 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) + }) }) From 9ad524d6659b2ea1dafde5bdc8805f884747d6fb Mon Sep 17 00:00:00 2001 From: Sergio LR Date: Wed, 20 Nov 2024 20:31:47 +0100 Subject: [PATCH 4/4] refactor: reorder flow export --- CHANGELOG | 1 + index.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a76b60c..74fcd4a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ #1.18.0 - feat: isUndefined + #1.17.0 - feat: assignWith - feat: clone diff --git a/index.js b/index.js index 8c59eee..92a6ffa 100644 --- a/index.js +++ b/index.js @@ -57,6 +57,7 @@ module.exports = { cloneDeep, difference, findLastIndex, + flow, freezeDeep, get, getArrayHasIntersect, @@ -76,7 +77,6 @@ module.exports = { isPlainObject, isString, isUndefined, - flow, mapKeys, mapValues, max,