Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/utils / dist / module / getActualDate.js
Size: Mime:
const months = [
    'January',
    'February',
    'March',
    'April',
    'May',
    'June',
    'July',
    'August',
    'September',
    'October',
    'November',
    'December',
];
const seperateDate = (x) => {
    // @todo @fixme @@perf
    x = x || '';
    const dateSplitter = x && x.includes('/') ? '/' : x && x.includes('-') ? '-' : '';
    const dateSplit = x.split(dateSplitter);
    const year = dateSplit[0];
    const month = parseInt(dateSplit[1], 10) || 0;
    const matchedDate = dateSplit[2] || '';
    const date = matchedDate.includes(' ')
        ? matchedDate.split(' ').shift() || ''
        : matchedDate;
    const dateObj = {
        year,
        month,
        date,
    };
    return dateObj;
};
/**
 * @note this was unsafe previously, now it is safe with typescript
 */
function getActualDate(actualDate, dateFormat) {
    const { year, month, date } = seperateDate(actualDate);
    const monthName = months[month];
    if (dateFormat.includes('yyyy')) {
        dateFormat = dateFormat.replace('yyyy', year);
    }
    if (dateFormat.includes('mmm')) {
        dateFormat = dateFormat.replace('mmm', monthName.substring(0, 3));
    }
    if (dateFormat.includes('dd')) {
        dateFormat = dateFormat.replace('dd', date);
    }
    return dateFormat;
}
export { getActualDate };
export default getActualDate;
//# sourceMappingURL=getActualDate.js.map