cscg24-guacamole

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

aliases.js (1687B)


      1import hasOwnProp from '../utils/has-own-prop';
      2
      3var aliases = {
      4    D: 'date',
      5    dates: 'date',
      6    date: 'date',
      7    d: 'day',
      8    days: 'day',
      9    day: 'day',
     10    e: 'weekday',
     11    weekdays: 'weekday',
     12    weekday: 'weekday',
     13    E: 'isoWeekday',
     14    isoweekdays: 'isoWeekday',
     15    isoweekday: 'isoWeekday',
     16    DDD: 'dayOfYear',
     17    dayofyears: 'dayOfYear',
     18    dayofyear: 'dayOfYear',
     19    h: 'hour',
     20    hours: 'hour',
     21    hour: 'hour',
     22    ms: 'millisecond',
     23    milliseconds: 'millisecond',
     24    millisecond: 'millisecond',
     25    m: 'minute',
     26    minutes: 'minute',
     27    minute: 'minute',
     28    M: 'month',
     29    months: 'month',
     30    month: 'month',
     31    Q: 'quarter',
     32    quarters: 'quarter',
     33    quarter: 'quarter',
     34    s: 'second',
     35    seconds: 'second',
     36    second: 'second',
     37    gg: 'weekYear',
     38    weekyears: 'weekYear',
     39    weekyear: 'weekYear',
     40    GG: 'isoWeekYear',
     41    isoweekyears: 'isoWeekYear',
     42    isoweekyear: 'isoWeekYear',
     43    w: 'week',
     44    weeks: 'week',
     45    week: 'week',
     46    W: 'isoWeek',
     47    isoweeks: 'isoWeek',
     48    isoweek: 'isoWeek',
     49    y: 'year',
     50    years: 'year',
     51    year: 'year',
     52};
     53
     54export function normalizeUnits(units) {
     55    return typeof units === 'string'
     56        ? aliases[units] || aliases[units.toLowerCase()]
     57        : undefined;
     58}
     59
     60export function normalizeObjectUnits(inputObject) {
     61    var normalizedInput = {},
     62        normalizedProp,
     63        prop;
     64
     65    for (prop in inputObject) {
     66        if (hasOwnProp(inputObject, prop)) {
     67            normalizedProp = normalizeUnits(prop);
     68            if (normalizedProp) {
     69                normalizedInput[normalizedProp] = inputObject[prop];
     70            }
     71        }
     72    }
     73
     74    return normalizedInput;
     75}