All files / src/Content TypeGuards.ts

100% Statements 12/12
100% Branches 23/23
100% Functions 6/6
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41  1x               1x 14296x             1x 9216x             1x 46x             1x 5075x     1x 40x    
import { DeferredObject } from '../ComplexTypes';
import { ContentInternal } from './ContentInternal';
import { IContent } from './IContent';
import { SavedContent } from './Types';
 
/**
 * Typeguard that determines if the specified Object is a DeferredObject
 * @param fieldObject The object that needs to be checked
 */
export const isDeferred = (fieldObject: any): fieldObject is DeferredObject => {
    return fieldObject && fieldObject.__deferred && fieldObject.__deferred.uri && fieldObject.__deferred.uri.length > 0 || false;
};
 
/**
 * Typeguard that determines if the specified Object is an IContentOptions instance
 * @param object The object that needs to be checked
 */
export const isIContent = (object: any): object is IContent => {
    return object && object.Id && object.Path && object.Type && object.Type.length > 0 || false;
};
 
/**
 * Typeguard that determines if the specified Object is a Content instance
 * @param object The object that needs to be checked
 */
export const isContent = <T extends IContent = IContent>(object: any): object is ContentInternal<T> => {
    return object instanceof ContentInternal;
};
 
/**
 * Typeguard that determines if the specified Object is an IContentOptions array
 * @param {any[]} objectList The object that needs to be checked
 */
export const isIContentList = (objectList: any[]): objectList is IContent[] => {
    return objectList && objectList.length !== undefined && objectList.find((o) => !isIContent(o)) === undefined || false;
};
 
export const isSavedContent = <T extends IContent>(c: ContentInternal<T>): c is SavedContent<T> => {
    return c && isContent(c) && c.Id && c.Path && c.Path.length && c.Name && c.Name.length > 0 || false;
};