dist/modules/to.js
function toDate(val, format, def) {
    if (is_1.isDate(format)) {
        def = format;
        format = undefined;
    }
    var opts = format;
    // Date format options a simple timezine
    // ex: 'America/Los_Angeles'.
    if (is_1.isString(opts)) {
        opts = {
            timeZone: format
        };
    }
    // This just checks loosely if string is
    // date like string, below parse should
    // catch majority of scenarios.
    function canParse() {
        return !/^[0-9]+$/.test(val) &&
            (is_1.isString(val) && /[0-9]/g.test(val) &&
                /(\.|\/|-|:)/g.test(val));
    }
    function parseDate() {
        var epoch = Date.parse(val);
        if (!isNaN(epoch)) {
            var date = from_1.fromEpoch(epoch);
            if (opts) {
                opts.locales = opts.locales || 'en-US';
                date = new Date(date.toLocaleString(opts.locales, opts));
            }
            return date;
        }
        return toDefault(null, def);
    }
    if (is_1.isDate(val))
        return val;
    if (!canParse())
        return toDefault(null, def);
    return function_1.tryWrap(parseDate)(def);
}
function toDate(val, format, def) {
    if (is_1.isDate(format)) {
        def = format;
        format = undefined;
    }
    var opts = format;
    // Date format options a simple timezine
    // ex: 'America/Los_Angeles'.
    if (is_1.isString(opts)) {
        opts = {
            timeZone: format
        };
    }
    // This just checks loosely if string is
    // date like string, below parse should
    // catch majority of scenarios.
    function canParse() {
        return !/^[0-9]+$/.test(val) &&
            (is_1.isString(val) && /[0-9]/g.test(val) &&
                /(\.|\/|-|:)/g.test(val));
    }
    function parseDate() {
        var epoch = Date.parse(val);
        if (!isNaN(epoch)) {
            var date = from_1.fromEpoch(epoch);
            if (opts) {
                opts.locales = opts.locales || 'en-US';
                date = new Date(date.toLocaleString(opts.locales, opts));
            }
            return date;
        }
        return toDefault(null, def);
    }
    if (is_1.isDate(val))
        return val;
    if (!canParse())
        return toDefault(null, def);
    return function_1.tryWrap(parseDate)(def);
}
function toDate ( val , format , def ) { if ( is_1 . isDate ( format ) ) { def = format ; format = undefined ; } var opts = format ; // Date format options a simple timezine // ex: 'America/Los_Angeles'. if ( is_1 . isString ( opts ) ) { opts = { timeZone : format } ; } // This just checks loosely if string is // date like string, below parse should // catch majority of scenarios. function canParse ( ) { return ! / ^[0-9]+$ / . test ( val ) && ( is_1 . isString ( val ) && / [0-9] / g . test ( val ) && / (\.|\/|-|:) / g . test ( val ) ) ; } function parseDate ( ) { var epoch = Date . parse ( val ) ; if ( ! isNaN ( epoch ) ) { var date = from_1 . fromEpoch ( epoch ) ; if ( opts ) { opts . locales = opts . locales || 'en-US' ; date = new Date ( date . toLocaleString ( opts . locales , opts ) ) ; } return date ; } return toDefault ( null , def ) ; } if ( is_1 . isDate ( val ) ) return val ; if ( ! canParse ( ) ) return toDefault ( null , def ) ; return function_1 . tryWrap ( parseDate ) ( def ) ; }
To Date
Converts value to date using Date.parse when string.
Optionally you can pass a format object containing
Intl.DateFormatOptions and locales. You may also pass
the timezone ONLY as a string. In this case locale en-US
is assumed.

@param val the value to be converted to date.
@param format date locale format options.
@param def a default date when null.
To Date Converts value to date using Date . parse when string . Optionally you can pass a format object containing Intl . DateFormatOptions and locales . You may also pass the timezone ONLY as a string . In this case locale en - US is assumed .