@meniga/dates
Advanced tools
Comparing version 4.6.1-alpha.204 to 4.6.1-alpha.217
@@ -1,9 +0,34 @@ | ||
import "core-js/modules/es.regexp.exec"; | ||
import "core-js/modules/es.string.replace"; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
require("core-js/modules/es.regexp.exec"); | ||
require("core-js/modules/es.string.replace"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = dates; | ||
exports.getDatesFromPeriod = getDatesFromPeriod; | ||
exports.formatDate = formatDate; | ||
exports.getDaysLeft = getDaysLeft; | ||
exports.isSameDate = isSameDate; | ||
exports.isAfterDate = isAfterDate; | ||
exports.isBeforeDate = isBeforeDate; | ||
exports.isSameOrAfterDate = isSameOrAfterDate; | ||
exports.isSameOrBeforeDate = isSameOrBeforeDate; | ||
exports.isValidDate = isValidDate; | ||
exports.stripTimeFromDate = stripTimeFromDate; | ||
exports.getWeekDayInCorrectFormat = getWeekDayInCorrectFormat; | ||
exports.dateDuration = exports.maxDate = exports.minDate = void 0; | ||
var _moment = _interopRequireDefault(require("moment")); | ||
var _lodash = require("lodash"); | ||
var _config = require("@meniga/config"); | ||
/** @module utils */ | ||
import moment from 'moment'; | ||
import { isString } from 'lodash'; | ||
import { globalConfig } from '@meniga/config'; | ||
export default function dates() { | ||
function dates() { | ||
var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
@@ -13,3 +38,3 @@ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var _localeConfig = globalConfig('locale', { | ||
var _localeConfig = (0, _config.globalConfig)('locale', { | ||
useUTC: false | ||
@@ -19,10 +44,11 @@ }); | ||
if (_localeConfig.useUTC) { | ||
return date ? moment.utc(date, format, strict) : moment(); | ||
return date ? _moment.default.utc(date, format, strict) : (0, _moment.default)(); | ||
} | ||
return date ? moment(date, format, strict) : moment(); | ||
return date ? (0, _moment.default)(date, format, strict) : (0, _moment.default)(); | ||
} | ||
export function getDatesFromPeriod(period, includeCurrentMonth) { | ||
function getDatesFromPeriod(period, includeCurrentMonth) { | ||
var dateStart, dateEnd; | ||
var apiConfig = globalConfig('locale.apiDateFormat', 'YYYY-MM-DD'); | ||
var apiConfig = (0, _config.globalConfig)('locale.apiDateFormat', 'YYYY-MM-DD'); | ||
@@ -63,3 +89,4 @@ if (!period || period === '') { | ||
export function formatDate() { | ||
function formatDate() { | ||
var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
@@ -80,3 +107,4 @@ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
export function getDaysLeft(endDate) { | ||
function getDaysLeft(endDate) { | ||
var today = dates().startOf('day').toDate(); | ||
@@ -94,7 +122,8 @@ var startOfEndDate = dates(endDate).startOf('day').toDate(); | ||
export function isSameDate() { | ||
function isSameDate() { | ||
var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var compareDate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var dateGrouping = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
return moment(date).isSame(compareDate, dateGrouping); | ||
return (0, _moment.default)(date).isSame(compareDate, dateGrouping); | ||
} | ||
@@ -109,7 +138,8 @@ /** | ||
export function isAfterDate() { | ||
function isAfterDate() { | ||
var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var compareDate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var dateGrouping = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
return moment(date).isAfter(compareDate, dateGrouping); | ||
return (0, _moment.default)(date).isAfter(compareDate, dateGrouping); | ||
} | ||
@@ -124,7 +154,8 @@ /** | ||
export function isBeforeDate() { | ||
function isBeforeDate() { | ||
var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var compareDate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var dateGrouping = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
return moment(date).isBefore(compareDate, dateGrouping); | ||
return (0, _moment.default)(date).isBefore(compareDate, dateGrouping); | ||
} | ||
@@ -139,7 +170,8 @@ /** | ||
export function isSameOrAfterDate() { | ||
function isSameOrAfterDate() { | ||
var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var compareDate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var dateGrouping = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
return moment(date).isSameOrAfter(compareDate, dateGrouping); | ||
return (0, _moment.default)(date).isSameOrAfter(compareDate, dateGrouping); | ||
} | ||
@@ -154,7 +186,8 @@ /** | ||
export function isSameOrBeforeDate() { | ||
function isSameOrBeforeDate() { | ||
var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var compareDate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var dateGrouping = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
return moment(date).isSameOrBefore(compareDate, dateGrouping); | ||
return (0, _moment.default)(date).isSameOrBefore(compareDate, dateGrouping); | ||
} | ||
@@ -167,9 +200,13 @@ /** | ||
export function isValidDate() { | ||
function isValidDate() { | ||
var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
return moment(date).isValid(); | ||
return (0, _moment.default)(date).isValid(); | ||
} | ||
export var minDate = moment.min; | ||
export var maxDate = moment.max; | ||
export var dateDuration = moment.duration; | ||
var minDate = _moment.default.min; | ||
exports.minDate = minDate; | ||
var maxDate = _moment.default.max; | ||
exports.maxDate = maxDate; | ||
var dateDuration = _moment.default.duration; | ||
/** | ||
@@ -179,4 +216,6 @@ * Strips time information from ISO string without formatting, so that javascript doesn't change the date to local time | ||
export function stripTimeFromDate(date) { | ||
if (date && isString(date)) { | ||
exports.dateDuration = dateDuration; | ||
function stripTimeFromDate(date) { | ||
if (date && (0, _lodash.isString)(date)) { | ||
if (date.length > 10 && date[10] === 'T') { | ||
@@ -189,5 +228,6 @@ return date.substr(0, 10); | ||
} | ||
export function getWeekDayInCorrectFormat(format, date) { | ||
function getWeekDayInCorrectFormat(format, date) { | ||
var correctFormat = dates(date).format('[Custom] ' + format); | ||
return correctFormat.replace('Custom ', ''); | ||
} |
@@ -1,2 +0,129 @@ | ||
export { dates, maxDate, minDate, dateDuration, isSameDate, isValidDate, formatDate, isBeforeDate, isAfterDate, isSameOrBeforeDate, isSameOrAfterDate, getWeekDayInCorrectFormat, getDaysLeft, getDatesFromPeriod } from './dates'; | ||
export { setLocale, weekdaysShort, weekdays, months, monthsShort, getLocaleObject } from './locale'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "dates", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.dates; | ||
} | ||
}); | ||
Object.defineProperty(exports, "maxDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.maxDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "minDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.minDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "dateDuration", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.dateDuration; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isSameDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.isSameDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isValidDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.isValidDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "formatDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.formatDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isBeforeDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.isBeforeDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isAfterDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.isAfterDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isSameOrBeforeDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.isSameOrBeforeDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isSameOrAfterDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.isSameOrAfterDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getWeekDayInCorrectFormat", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.getWeekDayInCorrectFormat; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getDaysLeft", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.getDaysLeft; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getDatesFromPeriod", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.getDatesFromPeriod; | ||
} | ||
}); | ||
Object.defineProperty(exports, "setLocale", { | ||
enumerable: true, | ||
get: function get() { | ||
return _locale.setLocale; | ||
} | ||
}); | ||
Object.defineProperty(exports, "weekdaysShort", { | ||
enumerable: true, | ||
get: function get() { | ||
return _locale.weekdaysShort; | ||
} | ||
}); | ||
Object.defineProperty(exports, "weekdays", { | ||
enumerable: true, | ||
get: function get() { | ||
return _locale.weekdays; | ||
} | ||
}); | ||
Object.defineProperty(exports, "months", { | ||
enumerable: true, | ||
get: function get() { | ||
return _locale.months; | ||
} | ||
}); | ||
Object.defineProperty(exports, "monthsShort", { | ||
enumerable: true, | ||
get: function get() { | ||
return _locale.monthsShort; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getLocaleObject", { | ||
enumerable: true, | ||
get: function get() { | ||
return _locale.getLocaleObject; | ||
} | ||
}); | ||
var _dates = require("./dates"); | ||
var _locale = require("./locale"); |
@@ -0,29 +1,50 @@ | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.setLocale = setLocale; | ||
exports.weekdaysShort = weekdaysShort; | ||
exports.weekdays = weekdays; | ||
exports.months = months; | ||
exports.monthsShort = monthsShort; | ||
exports.getLocaleObject = getLocaleObject; | ||
var _moment = _interopRequireDefault(require("moment")); | ||
/** @module utils */ | ||
import moment from 'moment'; | ||
export function setLocale(locale, config) { | ||
function setLocale(locale, config) { | ||
//1. set locale | ||
moment.locale(locale); //2. update locale with config | ||
_moment.default.locale(locale); //2. update locale with config | ||
moment.updateLocale(locale, config); | ||
_moment.default.updateLocale(locale, config); | ||
} | ||
export function weekdaysShort(day) { | ||
return moment.weekdaysShort(day); | ||
function weekdaysShort(day) { | ||
return _moment.default.weekdaysShort(day); | ||
} | ||
export function weekdays(day) { | ||
return moment.weekdays(day); | ||
function weekdays(day) { | ||
return _moment.default.weekdays(day); | ||
} | ||
export function months(month) { | ||
return moment.months(month); | ||
function months(month) { | ||
return _moment.default.months(month); | ||
} | ||
export function monthsShort(month) { | ||
return moment.monthsShort(month); | ||
function monthsShort(month) { | ||
return _moment.default.monthsShort(month); | ||
} | ||
export function getLocaleObject() { | ||
function getLocaleObject() { | ||
return { | ||
'periods': ['AM', 'PM'], | ||
'days': moment.weekdays(), | ||
'shortDays': moment.weekdaysShort(), | ||
'months': moment.months(), | ||
'shortMonths': moment.monthsShort() | ||
'days': _moment.default.weekdays(), | ||
'shortDays': _moment.default.weekdaysShort(), | ||
'months': _moment.default.months(), | ||
'shortMonths': _moment.default.monthsShort() | ||
}; | ||
} |
139
lib/index.js
@@ -1,2 +0,137 @@ | ||
export { default as dates, maxDate, minDate, dateDuration, isSameDate, isValidDate, formatDate, isBeforeDate, isAfterDate, stripTimeFromDate, isSameOrBeforeDate, isSameOrAfterDate, getWeekDayInCorrectFormat, getDaysLeft, getDatesFromPeriod } from './date/dates'; | ||
export { setLocale, weekdaysShort, weekdays, months, monthsShort, getLocaleObject } from './date/locale'; | ||
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "dates", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "maxDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.maxDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "minDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.minDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "dateDuration", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.dateDuration; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isSameDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.isSameDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isValidDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.isValidDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "formatDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.formatDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isBeforeDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.isBeforeDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isAfterDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.isAfterDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "stripTimeFromDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.stripTimeFromDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isSameOrBeforeDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.isSameOrBeforeDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isSameOrAfterDate", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.isSameOrAfterDate; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getWeekDayInCorrectFormat", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.getWeekDayInCorrectFormat; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getDaysLeft", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.getDaysLeft; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getDatesFromPeriod", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dates.getDatesFromPeriod; | ||
} | ||
}); | ||
Object.defineProperty(exports, "setLocale", { | ||
enumerable: true, | ||
get: function get() { | ||
return _locale.setLocale; | ||
} | ||
}); | ||
Object.defineProperty(exports, "weekdaysShort", { | ||
enumerable: true, | ||
get: function get() { | ||
return _locale.weekdaysShort; | ||
} | ||
}); | ||
Object.defineProperty(exports, "weekdays", { | ||
enumerable: true, | ||
get: function get() { | ||
return _locale.weekdays; | ||
} | ||
}); | ||
Object.defineProperty(exports, "months", { | ||
enumerable: true, | ||
get: function get() { | ||
return _locale.months; | ||
} | ||
}); | ||
Object.defineProperty(exports, "monthsShort", { | ||
enumerable: true, | ||
get: function get() { | ||
return _locale.monthsShort; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getLocaleObject", { | ||
enumerable: true, | ||
get: function get() { | ||
return _locale.getLocaleObject; | ||
} | ||
}); | ||
var _dates = _interopRequireWildcard(require("./date/dates")); | ||
var _locale = require("./date/locale"); |
{ | ||
"name": "@meniga/dates", | ||
"version": "4.6.1-alpha.204+f38fb0e", | ||
"version": "4.6.1-alpha.217+c1bac5e", | ||
"publishConfig": { | ||
@@ -26,3 +26,3 @@ "registry": "https://registry.npmjs.org/", | ||
}, | ||
"gitHead": "f38fb0ed3d66dfe012eea0968bb46bca8edfb0d9" | ||
"gitHead": "c1bac5e2efccbd4c0e51ad9dcebf82460c22e846" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
18905
478
2