all files / documents/util/ internal.js

100% Statements 15/15
100% Branches 12/12
100% Functions 0/0
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18      620× 24× 34×         218×   218× 84×    
import InternalBase from '../document/internal/base';
 
export const isDocumentModel = 'isDocumentModel';
 
export const isInternal = arg => arg instanceof InternalBase;
export const isInternalArray = value => value && isInternal(value) && value.constructor.type === 'array';
export const isInternalObject = value => value && isInternal(value) && value.constructor.type === 'object';
 
export const markModel = Class => Class.reopenClass({
  [isDocumentModel]: true
});
 
export const isModel = instance => instance && instance.constructor[isDocumentModel] === true;
 
export const toInternal = value => isModel(value) ? value._internal : value;
export const toModel = value => isInternal(value) ? value.model(true) : value;