Skip to content

Commit

Permalink
move var into constant
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed May 23, 2018
1 parent 35823a0 commit 112be1b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 35 deletions.
2 changes: 1 addition & 1 deletion dist/timeago.locales.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion lib/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ var IndexMapZH = exports.IndexMapZH = '秒_分钟_小时_天_周_月_年'.split(

var ATTR_DATA_TID = exports.ATTR_DATA_TID = 'data-tid';

var SEC_ARRAY = exports.SEC_ARRAY = [60, 60, 24, 7, 365 / 7 / 12, 12];
var SEC_ARRAY = exports.SEC_ARRAY = [60, 60, 24, 7, 365 / 7 / 12, 12];

var ATTR_TIMEAGO = exports.ATTR_TIMEAGO = 'data-timeago';
var ATTR_DATETIME = exports.ATTR_DATETIME = 'datetime';
2 changes: 1 addition & 1 deletion lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ var getAttr = exports.getAttr = function getAttr(node, name) {
* @returns {*}
*/
var getDateAttr = exports.getDateAttr = function getDateAttr(node) {
return getAttr(node, 'data-timeago') || getAttr(node, 'datetime');
return getAttr(node, _constant.ATTR_TIMEAGO) || getAttr(node, _constant.ATTR_DATETIME);
};

/**
Expand Down
33 changes: 6 additions & 27 deletions lib/localesEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,11 @@ var _lang2 = _interopRequireDefault(_lang);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _iteratorNormalCompletion = true; /**
* Created by hustcc on 18/5/20.
* Contract: i@hust.cc
*/

var _didIteratorError = false;
var _iteratorError = undefined;

try {

for (var _iterator = Object.keys(_lang2.default)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var locale = _step.value;

for (locale in _lang2.default) {
if (_lang2.default.hasOwnProperty(locale)) {
timeago.register(locale, _lang2.default[locale]);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
} /**
* Created by hustcc on 18/5/20.
* Contract: i@hust.cc
*/
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"size-limit": [{
"limit": "2 KB",
"path": "dist/timeago.min.js"
}, {
"limit": "10 KB",
"path": "dist/timeago.locales.min.js"
}],
"jest": {
"setupFiles": [],
Expand Down
3 changes: 3 additions & 0 deletions src/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ export const IndexMapZH = '秒_分钟_小时_天_周_月_年'.split('_');
export const ATTR_DATA_TID = 'data-tid';

export const SEC_ARRAY = [60, 60, 24, 7, 365/7/12, 12];

export const ATTR_TIMEAGO = 'data-timeago';
export const ATTR_DATETIME = 'datetime';
5 changes: 2 additions & 3 deletions src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
* Contract: i@hust.cc
*/

import { SEC_ARRAY, ATTR_DATA_TID } from './constant';
import { SEC_ARRAY, ATTR_DATA_TID, ATTR_TIMEAGO, ATTR_DATETIME } from './constant';
import { Locales } from './locales';


/**
* change f into int, remove decimal. Just for code compression
* @param f
Expand Down Expand Up @@ -103,7 +102,7 @@ export const getAttr = (node, name) => {
* @param node
* @returns {*}
*/
export const getDateAttr = node => getAttr(node, 'data-timeago') || getAttr(node, 'datetime');
export const getDateAttr = node => getAttr(node, ATTR_TIMEAGO) || getAttr(node, ATTR_DATETIME);

/**
* set the node attribute, native DOM and jquery supported.
Expand Down
6 changes: 4 additions & 2 deletions src/localesEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import Languages from './lang';

for (const locale of Object.keys(Languages)) {
timeago.register(locale, Languages[locale]);
for (locale in Languages) {
if (Languages.hasOwnProperty(locale)) {
timeago.register(locale, Languages[locale]);
}
}

0 comments on commit 112be1b

Please sign in to comment.