date-holidays-parser
Advanced tools
Comparing version 1.5.0-0 to 1.5.0-1
@@ -7,8 +7,2 @@ /** | ||
function _createForOfIteratorHelperLoose(o) { var i = 0; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } i = o[Symbol.iterator](); return i.next.bind(i); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
@@ -30,5 +24,6 @@ | ||
var DateFn = require('./DateFn'); | ||
var DateFn = require('./DateFn'); // priority in ascending order (low ... high) | ||
var TYPES = ['public', 'bank', 'school', 'optional', 'observance']; | ||
var TYPES = ['observance', 'optional', 'school', 'bank', 'public']; | ||
/** | ||
@@ -199,3 +194,2 @@ * @class | ||
year = toYear(year); | ||
var arr = []; | ||
var langs = this.getLanguages(); | ||
@@ -207,3 +201,24 @@ | ||
Object.keys(this.holidays).forEach(function (rule) { | ||
var startSorter = function startSorter(a, b) { | ||
return +a.start - +b.start; | ||
}; | ||
var typeIndex = function typeIndex(a) { | ||
return TYPES.indexOf(a.type); | ||
}; | ||
var typeSorter = function typeSorter(a, b) { | ||
return typeIndex(b) - typeIndex(a); | ||
}; | ||
var ruleIndex = function ruleIndex(a) { | ||
return /substitutes|and if /.test(a.rule) ? 1 : -1; | ||
}; | ||
var ruleSorter = function ruleSorter(a, b) { | ||
return ruleIndex(a) - ruleIndex(b); | ||
}; | ||
var filterMap = {}; | ||
var arr = Object.keys(this.holidays).reduce(function (arr, rule) { | ||
if (_this2.holidays[rule].fn) { | ||
@@ -216,24 +231,16 @@ _this2._dateByRule(year, rule).forEach(function (o) { | ||
} | ||
}); // sort by date | ||
arr = arr.sort(function (a, b) { | ||
return +a.start - +b.start; | ||
}).map(function (a, i) { | ||
var b = arr[i + 1]; | ||
return arr; | ||
}, []) // sort by date and type to filter by duplicate | ||
.sort(function (a, b) { | ||
return startSorter(a, b) || typeSorter(a, b) || ruleSorter(a, b); | ||
}).filter(function (item) { | ||
var hash = item.name + +item.start; | ||
if (b && a.name === b.name && +a.start === +b.start) { | ||
for (var _iterator = _createForOfIteratorHelperLoose(TYPES), _step; !(_step = _iterator()).done;) { | ||
var type = _step.value; | ||
if (type === a.type || type === b.type) { | ||
a.filter = true; | ||
b.type = type; | ||
break; | ||
} | ||
} | ||
if (!filterMap[hash]) { | ||
filterMap[hash] = true; | ||
return true; | ||
} | ||
return a; | ||
}).filter(function (a) { | ||
if (!a.filter) return a; | ||
return false; | ||
}); | ||
@@ -240,0 +247,0 @@ return arr; |
@@ -9,4 +9,2 @@ /** | ||
function _createForOfIteratorHelper(o) { if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
@@ -44,5 +42,6 @@ | ||
var DateFn = require('./DateFn'); | ||
var DateFn = require('./DateFn'); // priority in ascending order (low ... high) | ||
var TYPES = ['public', 'bank', 'school', 'optional', 'observance']; | ||
var TYPES = ['observance', 'optional', 'school', 'bank', 'public']; | ||
/** | ||
@@ -214,3 +213,2 @@ * @class | ||
year = toYear(year); | ||
var arr = []; | ||
var langs = this.getLanguages(); | ||
@@ -222,3 +220,24 @@ | ||
Object.keys(this.holidays).forEach(function (rule) { | ||
var startSorter = function startSorter(a, b) { | ||
return +a.start - +b.start; | ||
}; | ||
var typeIndex = function typeIndex(a) { | ||
return TYPES.indexOf(a.type); | ||
}; | ||
var typeSorter = function typeSorter(a, b) { | ||
return typeIndex(b) - typeIndex(a); | ||
}; | ||
var ruleIndex = function ruleIndex(a) { | ||
return /substitutes|and if /.test(a.rule) ? 1 : -1; | ||
}; | ||
var ruleSorter = function ruleSorter(a, b) { | ||
return ruleIndex(a) - ruleIndex(b); | ||
}; | ||
var filterMap = {}; | ||
var arr = Object.keys(this.holidays).reduce(function (arr, rule) { | ||
if (_this2.holidays[rule].fn) { | ||
@@ -231,33 +250,16 @@ _this2._dateByRule(year, rule).forEach(function (o) { | ||
} | ||
}); // sort by date | ||
arr = arr.sort(function (a, b) { | ||
return +a.start - +b.start; | ||
}).map(function (a, i) { | ||
var b = arr[i + 1]; | ||
return arr; | ||
}, []) // sort by date and type to filter by duplicate | ||
.sort(function (a, b) { | ||
return startSorter(a, b) || typeSorter(a, b) || ruleSorter(a, b); | ||
}).filter(function (item) { | ||
var hash = item.name + +item.start; | ||
if (b && a.name === b.name && +a.start === +b.start) { | ||
var _iterator = _createForOfIteratorHelper(TYPES), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var type = _step.value; | ||
if (type === a.type || type === b.type) { | ||
a.filter = true; | ||
b.type = type; | ||
break; | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
if (!filterMap[hash]) { | ||
filterMap[hash] = true; | ||
return true; | ||
} | ||
return a; | ||
}).filter(function (a) { | ||
if (!a.filter) return a; | ||
return false; | ||
}); | ||
@@ -264,0 +266,0 @@ return arr; |
{ | ||
"name": "date-holidays-parser", | ||
"version": "1.5.0-0", | ||
"version": "1.5.0-1", | ||
"description": "parser for worldwide holidays", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -18,3 +18,4 @@ /** | ||
const TYPES = ['public', 'bank', 'school', 'optional', 'observance'] | ||
// priority in ascending order (low ... high) | ||
const TYPES = ['observance', 'optional', 'school', 'bank', 'public'] | ||
@@ -164,3 +165,2 @@ /** | ||
let arr = [] | ||
const langs = this.getLanguages() | ||
@@ -171,31 +171,29 @@ if (language) { | ||
Object.keys(this.holidays).forEach((rule) => { | ||
if (this.holidays[rule].fn) { | ||
this._dateByRule(year, rule).forEach((o) => { | ||
arr.push({ ...this._translate(o, langs), rule }) | ||
}) | ||
} | ||
}) | ||
const startSorter = (a, b) => (+a.start) - (+b.start) | ||
const typeIndex = (a) => TYPES.indexOf(a.type) | ||
const typeSorter = (a, b) => typeIndex(b) - typeIndex(a) | ||
const ruleIndex = (a) => /substitutes|and if /.test(a.rule) ? 1 : -1 | ||
const ruleSorter = (a, b) => ruleIndex(a) - ruleIndex(b) | ||
// sort by date | ||
arr = arr | ||
.sort(function (a, b) { | ||
return (+a.start) - (+b.start) | ||
}) | ||
.map(function (a, i) { | ||
const b = arr[i + 1] | ||
if (b && (a.name === b.name) && (+a.start) === (+b.start)) { | ||
for (const type of TYPES) { | ||
if (type === a.type || type === b.type) { | ||
a.filter = true | ||
b.type = type | ||
break | ||
} | ||
} | ||
const filterMap = {} | ||
const arr = Object.keys(this.holidays) | ||
.reduce((arr, rule) => { | ||
if (this.holidays[rule].fn) { | ||
this._dateByRule(year, rule).forEach((o) => { | ||
arr.push({ ...this._translate(o, langs), rule }) | ||
}) | ||
} | ||
return a | ||
return arr | ||
}, []) | ||
// sort by date and type to filter by duplicate | ||
.sort((a, b) => startSorter(a, b) || typeSorter(a, b) || ruleSorter(a, b)) | ||
.filter(item => { | ||
const hash = item.name + (+item.start) | ||
if (!filterMap[hash]) { | ||
filterMap[hash] = true | ||
return true | ||
} | ||
return false | ||
}) | ||
.filter(function (a) { | ||
if (!a.filter) return a | ||
}) | ||
@@ -372,3 +370,2 @@ return arr | ||
}) | ||
return dates | ||
@@ -375,0 +372,0 @@ }, |
337477
6792