JAVASCRIPT 5
Token.js Guest on 8th April 2021 05:45:49 AM
  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.     if (typeof token === 'string') {
  11.         token = [token];
  12.     }
  13.     if (isNumber(callback)) {
  14.         func = function (input, array) {
  15.             array[callback] = toInt(input);
  16.         };
  17.     }
  18.     for (i = 0; i < token.length; i++) {
  19.         tokens[token[i]] = func;
  20.     }
  21. }
  22.  
  23. export function addWeekParseToken(token, callback) {
  24.     addParseToken(token, function (input, array, config, token) {
  25.         config._w = config._w || {};
  26.         callback(input, config._w, config, token);
  27.     });
  28. }
  29.  
  30. export function addTimeToArrayFromToken(token, input, config) {
  31.     if (input != null && hasOwnProp(tokens, token)) {
  32.         tokens[token](input, config._a, config, token);
  33.     }
  34. }

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.