| 1 |
import hasOwnProp from '../utils/has-own-prop'; |
| 2 |
import isNumber from '../utils/is-number'; |
| 3 |
import toInt from '../utils/to-int'; |
| 4 |
|
| 5 |
var tokens = {}; |
| 6 |
|
| 7 |
export function addParseToken(token, callback) { |
| 8 |
var i, |
| 9 |
func = callback, |
| 10 |
tokenLen; |
| 11 |
if (typeof token === 'string') { |
| 12 |
token = [token]; |
| 13 |
} |
| 14 |
if (isNumber(callback)) { |
| 15 |
func = function (input, array) { |
| 16 |
array[callback] = toInt(input); |
| 17 |
}; |
| 18 |
} |
| 19 |
tokenLen = token.length; |
| 20 |
for (i = 0; i < tokenLen; i++) { |
| 21 |
tokens[token[i]] = func; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
export function addWeekParseToken(token, callback) { |
| 26 |
addParseToken(token, function (input, array, config, token) { |
| 27 |
config._w = config._w || {}; |
| 28 |
callback(input, config._w, config, token); |
| 29 |
}); |
| 30 |
} |
| 31 |
|
| 32 |
export function addTimeToArrayFromToken(token, input, config) { |
| 33 |
if (input != null && hasOwnProp(tokens, token)) { |
| 34 |
tokens[token](input, config._a, config, token); |
| 35 |
} |
| 36 |
} |