UNPKG

rule-filter-validator

Version:

A object and scope validator based on structured rules

42 lines 1.04 kB
export const functions = { year, month, week, day, hour, minute, second, count, }; /** * Extract the year from a given ISO-8601 date */ function year(value) { return (new Date(value)).getUTCFullYear(); } function month(value) { // Match DB by using 1-indexed months return (new Date(value)).getUTCMonth() + 1; } function week(value) { const date = new Date(value); const firstDayOfYear = new Date(date.getFullYear(), 0, 1); const pastDaysOfYear = (date.getTime() - firstDayOfYear.getTime()) / 86400000; return Math.ceil((pastDaysOfYear + firstDayOfYear.getDay() + 1) / 7); } function day(value) { return (new Date(value)).getUTCDate(); } function hour(value) { return (new Date(value)).getUTCHours(); } function minute(value) { return (new Date(value)).getUTCMinutes(); } function second(value) { return (new Date(value)).getUTCSeconds(); } function count(value) { return Array.isArray(value) ? value.length : null; } //# sourceMappingURL=functions.js.map