Browse Source

feat(core): add a utility function that checks if a value is undefined or empty string

pull/3262/head
Arman Ozak 7 years ago
parent
commit
5655ce4331
  1. 18
      npm/ng-packs/packages/core/src/lib/tests/common-utils.spec.ts
  2. 4
      npm/ng-packs/packages/core/src/lib/utils/common-utils.ts

18
npm/ng-packs/packages/core/src/lib/tests/common-utils.spec.ts

@ -1,4 +1,4 @@
import { noop } from '../utils';
import { isUndefinedOrEmptyString, noop } from '../utils';
describe('CommonUtils', () => {
describe('#noop', () => {
@ -7,4 +7,20 @@ describe('CommonUtils', () => {
expect(noop()()).toBeUndefined();
});
});
describe('#isUndefinedOrEmptyString', () => {
test.each`
value | expected
${null} | ${false}
${0} | ${false}
${true} | ${false}
${'x'} | ${false}
${{}} | ${false}
${[]} | ${false}
${undefined} | ${true}
${''} | ${true}
`('should return $expected when given parameter is $value', ({ value, expected }) => {
expect(isUndefinedOrEmptyString(value)).toBe(expected);
});
});
});

4
npm/ng-packs/packages/core/src/lib/utils/common-utils.ts

@ -3,3 +3,7 @@ export function noop() {
const fn = function() {};
return fn;
}
export function isUndefinedOrEmptyString(value: unknown): boolean {
return value === undefined || value === '';
}

Loading…
Cancel
Save