mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
added is(Not)Null and Undefined methods to empty.util because they're deprecated in the node core
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
ChangeDetectionStrategy, ChangeDetectorRef, Component, DoCheck, OnChanges, OnDestroy,
|
ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy,
|
||||||
OnInit, SimpleChanges
|
OnInit
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { ActivatedRoute, Params } from '@angular/router';
|
import { ActivatedRoute, Params } from '@angular/router';
|
||||||
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
|
||||||
import { Subscription } from 'rxjs/Subscription';
|
import { Subscription } from 'rxjs/Subscription';
|
||||||
|
|
||||||
import { Collection } from '../core/shared/collection.model';
|
import { Collection } from '../core/shared/collection.model';
|
||||||
|
@@ -1,4 +1,8 @@
|
|||||||
import { isEmpty, hasNoValue, hasValue, isNotEmpty } from './empty.util';
|
import {
|
||||||
|
isEmpty, hasNoValue, hasValue, isNotEmpty, isNull, isNotNull,
|
||||||
|
isUndefined
|
||||||
|
isNotUndefined,
|
||||||
|
} from './empty.util';
|
||||||
|
|
||||||
describe('Empty Utils', () => {
|
describe('Empty Utils', () => {
|
||||||
const strng = 'string';
|
const strng = 'string';
|
||||||
@@ -10,6 +14,180 @@ describe('Empty Utils', () => {
|
|||||||
const fullMap: Map<string, string> = new Map();
|
const fullMap: Map<string, string> = new Map();
|
||||||
fullMap.set('foo', 'bar');
|
fullMap.set('foo', 'bar');
|
||||||
|
|
||||||
|
describe('isNull', () => {
|
||||||
|
it('should return true for null', () => {
|
||||||
|
expect(isNull(null)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for undefined', () => {
|
||||||
|
expect(isNull(undefined)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for an empty String', () => {
|
||||||
|
expect(isNull('')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for true', () => {
|
||||||
|
expect(isNull(true)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for false', () => {
|
||||||
|
expect(isNull(false)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for a String', () => {
|
||||||
|
expect(isNull(strng)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for a Function', () => {
|
||||||
|
expect(isNull(fn)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for 0', () => {
|
||||||
|
expect(isNull(0)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for an empty Array', () => {
|
||||||
|
expect(isNull([])).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for an empty Object', () => {
|
||||||
|
expect(isNull({})).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isNotNull', () => {
|
||||||
|
|
||||||
|
it('should return false for null', () => {
|
||||||
|
expect(isNotNull(null)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for undefined', () => {
|
||||||
|
expect(isNotNull(undefined)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for an empty String', () => {
|
||||||
|
expect(isNotNull('')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for false', () => {
|
||||||
|
expect(isNotNull(false)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for true', () => {
|
||||||
|
expect(isNotNull(true)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for a String', () => {
|
||||||
|
expect(isNotNull(strng)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for a Function', () => {
|
||||||
|
expect(isNotNull(fn)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for 0', () => {
|
||||||
|
expect(isNotNull(0)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for an empty Array', () => {
|
||||||
|
expect(isNotNull([])).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for an empty Object', () => {
|
||||||
|
expect(isNotNull({})).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isUndefined', () => {
|
||||||
|
it('should return false for null', () => {
|
||||||
|
expect(isUndefined(null)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for undefined', () => {
|
||||||
|
expect(isUndefined(undefined)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for an empty String', () => {
|
||||||
|
expect(isUndefined('')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for true', () => {
|
||||||
|
expect(isUndefined(true)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for false', () => {
|
||||||
|
expect(isUndefined(false)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for a String', () => {
|
||||||
|
expect(isUndefined(strng)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for a Function', () => {
|
||||||
|
expect(isUndefined(fn)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for 0', () => {
|
||||||
|
expect(isUndefined(0)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for an empty Array', () => {
|
||||||
|
expect(isUndefined([])).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for an empty Object', () => {
|
||||||
|
expect(isUndefined({})).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isNotUndefined', () => {
|
||||||
|
|
||||||
|
it('should return true for null', () => {
|
||||||
|
expect(isNotUndefined(null)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for undefined', () => {
|
||||||
|
expect(isNotUndefined(undefined)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for an empty String', () => {
|
||||||
|
expect(isNotUndefined('')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for false', () => {
|
||||||
|
expect(isNotUndefined(false)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for true', () => {
|
||||||
|
expect(isNotUndefined(true)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for a String', () => {
|
||||||
|
expect(isNotUndefined(strng)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for a Function', () => {
|
||||||
|
expect(isNotUndefined(fn)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for 0', () => {
|
||||||
|
expect(isNotUndefined(0)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for an empty Array', () => {
|
||||||
|
expect(isNotUndefined([])).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for an empty Object', () => {
|
||||||
|
expect(isNotUndefined({})).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('hasNoValue', () => {
|
describe('hasNoValue', () => {
|
||||||
it('should return true for null', () => {
|
it('should return true for null', () => {
|
||||||
expect(hasNoValue(null)).toBe(true);
|
expect(hasNoValue(null)).toBe(true);
|
||||||
|
@@ -1,14 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* Returns true if the passed value is null.
|
||||||
|
* isNull(); // false
|
||||||
|
* isNull(null); // true
|
||||||
|
* isNull(undefined); // false
|
||||||
|
* isNull(''); // false
|
||||||
|
* isNull({}); // false
|
||||||
|
* isNull([]); // false
|
||||||
|
* isNull(function() {}); // false
|
||||||
|
*/
|
||||||
|
export function isNull(obj?: any): boolean {
|
||||||
|
return obj === null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the passed value is not null.
|
||||||
|
* isNotNull(); // true
|
||||||
|
* isNotNull(null); // false
|
||||||
|
* isNotNull(undefined); // true
|
||||||
|
* isNotNull(''); // true
|
||||||
|
* isNotNull({}); // true
|
||||||
|
* isNotNull([]); // true
|
||||||
|
* isNotNull(function() {}); // true
|
||||||
|
*/
|
||||||
|
export function isNotNull(obj?: any): boolean {
|
||||||
|
return obj !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the passed value is undefined.
|
||||||
|
* isUndefined(); // true
|
||||||
|
* isUndefined(null); // false
|
||||||
|
* isUndefined(undefined); // true
|
||||||
|
* isUndefined(''); // false
|
||||||
|
* isUndefined({}); // false
|
||||||
|
* isUndefined([]); // false
|
||||||
|
* isUndefined(function() {}); // false
|
||||||
|
*/
|
||||||
|
export function isUndefined(obj?: any): boolean {
|
||||||
|
return obj === undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the passed value is not undefined.
|
||||||
|
* isNotUndefined(); // false
|
||||||
|
* isNotUndefined(null); // true
|
||||||
|
* isNotUndefined(undefined); // false
|
||||||
|
* isNotUndefined(''); // true
|
||||||
|
* isNotUndefined({}); // true
|
||||||
|
* isNotUndefined([]); // true
|
||||||
|
* isNotUndefined(function() {}); // true
|
||||||
|
*/
|
||||||
|
export function isNotUndefined(obj?: any): boolean {
|
||||||
|
return obj !== undefined;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the passed value is null or undefined.
|
* Returns true if the passed value is null or undefined.
|
||||||
* hasNoValue(); // true
|
* hasNoValue(); // true
|
||||||
* hasNoValue(null); // true
|
* hasNoValue(null); // true
|
||||||
* hasNoValue(undefined); // true
|
* hasNoValue(undefined); // true
|
||||||
* hasNoValue(''); // false
|
* hasNoValue(''); // false
|
||||||
|
* hasNoValue({}); // false
|
||||||
* hasNoValue([]); // false
|
* hasNoValue([]); // false
|
||||||
* hasNoValue(function() {}); // false
|
* hasNoValue(function() {}); // false
|
||||||
*/
|
*/
|
||||||
export function hasNoValue(obj?: any): boolean {
|
export function hasNoValue(obj?: any): boolean {
|
||||||
return obj === null || obj === undefined;
|
return isUndefined(obj) || isNull(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,11 +74,12 @@ export function hasNoValue(obj?: any): boolean {
|
|||||||
* hasValue(null); // false
|
* hasValue(null); // false
|
||||||
* hasValue(undefined); // false
|
* hasValue(undefined); // false
|
||||||
* hasValue(''); // true
|
* hasValue(''); // true
|
||||||
|
* hasValue({}); // true
|
||||||
* hasValue([]); // true
|
* hasValue([]); // true
|
||||||
* hasValue(function() {}); // true
|
* hasValue(function() {}); // true
|
||||||
*/
|
*/
|
||||||
export function hasValue(obj?: any): boolean {
|
export function hasValue(obj?: any): boolean {
|
||||||
return !hasNoValue(obj);
|
return isNotUndefined(obj) && isNotNull(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -24,8 +24,6 @@ import { SortDirection, SortOptions } from '../../core/cache/models/sort-options
|
|||||||
import { hasValue } from '../empty.util';
|
import { hasValue } from '../empty.util';
|
||||||
import { PageInfo } from '../../core/shared/page-info.model';
|
import { PageInfo } from '../../core/shared/page-info.model';
|
||||||
import { isUndefined } from 'util';
|
import { isUndefined } from 'util';
|
||||||
import { Store } from '@ngrx/store';
|
|
||||||
import { ObjectCacheState } from '../../core/cache/object-cache.reducer';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default pagination controls component.
|
* The default pagination controls component.
|
||||||
|
Reference in New Issue
Block a user