Skip to content
Snippets Groups Projects
Commit e499f792 authored by Chris Wilper's avatar Chris Wilper
Browse files

DS-4107 Use isUndefined and isNotUndefined where appropriate

parent 4c8747a3
No related branches found
No related tags found
No related merge requests found
import { isUndefined } from '../../shared/empty.util';
import { MetadataValue, MetadataValueFilter } from './metadata.interfaces';
import { Metadata } from './metadata.model';
const mdValue = (value: string, language?: string): MetadataValue => {
return { value: value, language: language === undefined ? null : language };
return { value: value, language: isUndefined(language) ? null : language };
}
const dcDescription = mdValue('Some description');
......@@ -24,12 +25,12 @@ const multiMap = {
const testMethod = (fn, resultKind, mapOrMaps, keyOrKeys, expected, filter?) => {
const keys = keyOrKeys instanceof Array ? keyOrKeys : [ keyOrKeys ];
describe('and key' + (keys.length === 1 ? (' ' + keys[0]) : ('s ' + JSON.stringify(keys)))
+ ' with ' + (filter === undefined ? 'no filter' : 'filter ' + JSON.stringify(filter)), () => {
+ ' with ' + (isUndefined(filter) ? 'no filter' : 'filter ' + JSON.stringify(filter)), () => {
const result = fn(mapOrMaps, keys, filter);
let shouldReturn;
if (resultKind === 'boolean') {
shouldReturn = expected;
} else if (expected === undefined) {
} else if (isUndefined(expected)) {
shouldReturn = 'undefined';
} else if (expected instanceof Array) {
shouldReturn = 'an array with ' + expected.length + ' ' + (expected.length > 1 ? 'ordered ' : '')
......@@ -152,7 +153,7 @@ describe('Metadata', () => {
const testValueMatches = (value: MetadataValue, expected: boolean, filter?: MetadataValueFilter) => {
describe('with value ' + JSON.stringify(value) + ' and filter '
+ (filter === undefined ? 'undefined' : JSON.stringify(filter)), () => {
+ (isUndefined(filter) ? 'undefined' : JSON.stringify(filter)), () => {
const result = Metadata.valueMatches(value, filter);
it('should return ' + expected, () => {
expect(result).toEqual(expected);
......
import { isEmpty } from '../../shared/empty.util';
import { isEmpty, isNotUndefined, isUndefined } from '../../shared/empty.util';
import { MetadataMap, MetadataValue, MetadataValueFilter } from './metadata.interfaces';
/**
......@@ -93,7 +93,7 @@ export class Metadata {
public static firstValue(mdMapOrMaps: MetadataMap | MetadataMap[], keyOrKeys: string | string[],
filter?: MetadataValueFilter): string {
const value = Metadata.first(mdMapOrMaps, keyOrKeys, filter);
return value === undefined ? undefined : value.value;
return isUndefined(value) ? undefined : value.value;
}
/**
......@@ -106,7 +106,7 @@ export class Metadata {
*/
public static has(mdMapOrMaps: MetadataMap | MetadataMap[], keyOrKeys: string | string[],
filter?: MetadataValueFilter): boolean {
return Metadata.first(mdMapOrMaps, keyOrKeys, filter) !== undefined;
return isNotUndefined(Metadata.first(mdMapOrMaps, keyOrKeys, filter));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment