integreat
Version:
Node.js integration layer
28 lines • 2.03 kB
JavaScript
import { IdentType, } from '../types.js';
const OK_STATUSES = ['ok', 'noaction', 'queued'];
export const isObject = (value) => Object.prototype.toString.call(value) === '[object Object]';
export const isDate = (value) => Object.prototype.toString.call(value) === '[object Date]';
export const isEmptyObject = (value) => isObject(value) && Object.keys(value).length === 0;
export const isTypedData = (value) => isObject(value) && Object.prototype.hasOwnProperty.call(value, '$type');
export const isReference = (value) => isObject(value) && Object.prototype.hasOwnProperty.call(value, '$ref');
export const isShape = (value) => isObject(value) && !Object.prototype.hasOwnProperty.call(value, '$type');
export const isFieldDefinition = (value) => isObject(value) && typeof value.$type === 'string';
export const isNullOrUndefined = (value) => value === null || value === undefined;
export const isNotNullOrUndefined = (value) => !isNullOrUndefined(value);
export const isAction = (action) => isObject(action) &&
typeof action.type === 'string' &&
isObject(action.payload);
export const isOkStatus = (status) => typeof status === 'string' && OK_STATUSES.includes(status);
export const isOkResponse = (response) => isOkStatus(response?.status);
export const isErrorResponse = (response) => typeof response?.status === 'string' && !OK_STATUSES.includes(response.status);
export const isTruthy = (value) => !!value;
export const isFalsy = (value) => !value;
export const not = isFalsy;
export const isDuplicate = (error, index, errors) => errors.indexOf(error) === index;
export const isCustomIdent = (ident) => (ident?.type === undefined || ident?.type === IdentType.Custom) &&
!ident?.root;
export const isInternalIdent = (ident) => !isCustomIdent(ident);
export const isRootIdent = (ident) => ident?.type === IdentType.Root || ident?.root;
export const isSchedulerIdent = (ident) => ident?.type === IdentType.Scheduler;
export const isAnonIdent = (ident) => ident?.type === IdentType.Anon;
//# sourceMappingURL=is.js.map