@mondaycom/apps-cli
Version:
A cli tool to manage apps (and monday-code projects) in monday.com
40 lines (39 loc) • 1.34 kB
JavaScript
import { TIME_IN_MILLISECONDS } from './time-utils.js';
export const isDate = (value) => {
if (!value) {
return false;
}
return new Date(value).toString() !== 'Invalid Date';
};
export const getDayDiff = (fromDate, toDate) => {
if (!fromDate.getTime || !toDate.getTime) {
return null;
}
const diffInMS = toDate.getTime() - fromDate.getTime();
return diffInMS / TIME_IN_MILLISECONDS.DAY;
};
export function isDefined(input) {
return input !== null && input !== undefined;
}
export function isDefinedAndNotEmpty(input) {
if (!isDefined(input))
return false;
if (typeof input === 'string')
return input.trim() !== '';
if (Array.isArray(input))
return input.length > 0;
if (typeof input === 'object')
return Object.keys(input).length > 0;
return true;
}
/***
* This function receives an input (string or number) and returns true if it is a number
* @param input - The input to check if it is a number
* @returns true if the input is a number
*/
export function isANumber(input) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
return isDefined(input) && `${Number(input)}` === `${input}` && Number.isFinite(input);
}