cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

valid.js (1486B)


      1import extend from '../utils/extend';
      2import { createUTC } from './utc';
      3import getParsingFlags from '../create/parsing-flags';
      4import some from '../utils/some';
      5
      6export function isValid(m) {
      7    var flags = null,
      8        parsedParts = false,
      9        isNowValid = m._d && !isNaN(m._d.getTime());
     10    if (isNowValid) {
     11        flags = getParsingFlags(m);
     12        parsedParts = some.call(flags.parsedDateParts, function (i) {
     13            return i != null;
     14        });
     15        isNowValid =
     16            flags.overflow < 0 &&
     17            !flags.empty &&
     18            !flags.invalidEra &&
     19            !flags.invalidMonth &&
     20            !flags.invalidWeekday &&
     21            !flags.weekdayMismatch &&
     22            !flags.nullInput &&
     23            !flags.invalidFormat &&
     24            !flags.userInvalidated &&
     25            (!flags.meridiem || (flags.meridiem && parsedParts));
     26        if (m._strict) {
     27            isNowValid =
     28                isNowValid &&
     29                flags.charsLeftOver === 0 &&
     30                flags.unusedTokens.length === 0 &&
     31                flags.bigHour === undefined;
     32        }
     33    }
     34    if (Object.isFrozen == null || !Object.isFrozen(m)) {
     35        m._isValid = isNowValid;
     36    } else {
     37        return isNowValid;
     38    }
     39    return m._isValid;
     40}
     41
     42export function createInvalid(flags) {
     43    var m = createUTC(NaN);
     44    if (flags != null) {
     45        extend(getParsingFlags(m), flags);
     46    } else {
     47        getParsingFlags(m).userInvalidated = true;
     48    }
     49
     50    return m;
     51}