summaryrefslogtreecommitdiff
path: root/node_modules/moment/src/lib/parse/token.js
blob: ede35782e906308fb3215ece310494e7cff40d74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import hasOwnProp from '../utils/has-own-prop';
import isNumber from '../utils/is-number';
import toInt from '../utils/to-int';

var tokens = {};

export function addParseToken(token, callback) {
    var i,
        func = callback,
        tokenLen;
    if (typeof token === 'string') {
        token = [token];
    }
    if (isNumber(callback)) {
        func = function (input, array) {
            array[callback] = toInt(input);
        };
    }
    tokenLen = token.length;
    for (i = 0; i < tokenLen; i++) {
        tokens[token[i]] = func;
    }
}

export function addWeekParseToken(token, callback) {
    addParseToken(token, function (input, array, config, token) {
        config._w = config._w || {};
        callback(input, config._w, config, token);
    });
}

export function addTimeToArrayFromToken(token, input, config) {
    if (input != null && hasOwnProp(tokens, token)) {
        tokens[token](input, config._a, config, token);
    }
}