vue-convenia-util
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -287,12 +287,17 @@ 'use strict'; | ||
* @param {String} date | ||
* @param {{ from: String, to: String }} [options] | ||
* @param {{ from: String, to: String, UTC: Boolean }} [options] | ||
* @returns {String} | ||
*/ | ||
var toDate = function (date, options) { | ||
if ( options === void 0 ) options = {}; | ||
var toDate = function (date, ref) { | ||
if ( ref === void 0 ) ref = {}; | ||
var to = ref.to; if ( to === void 0 ) to = 'DD/MM/YYYY'; | ||
var from = ref.from; if ( from === void 0 ) from = getDateFormat(date); | ||
var isUTC = ref.UTC; if ( isUTC === void 0 ) isUTC = false; | ||
var from = options.from || getDateFormat(date); | ||
var to = options.to || 'DD/MM/YYYY'; | ||
var isValid = from && isDate(date, from); | ||
var formatted = !isValid ? null : moment(date, from).format(to); | ||
if (!isValid) { | ||
return null | ||
} | ||
var formatter = isUTC ? moment.utc : moment; | ||
var formatted = formatter(date, from).format(to); | ||
return formatted | ||
@@ -407,3 +412,3 @@ }; | ||
var $format = Object.freeze({ | ||
var format = Object.freeze({ | ||
toCPF: toCPF, | ||
@@ -481,3 +486,3 @@ toRG: toRG, | ||
var mixins = Object.freeze({ | ||
var mixin = Object.freeze({ | ||
Loadable: Loadable, | ||
@@ -540,8 +545,8 @@ ObservableFix: ObservableFix | ||
if (options.formatters) { | ||
Vue.prototype.$format = $format; | ||
Vue.prototype.$format = format; | ||
} | ||
if (options.formatFilters) { | ||
Object.keys($format).forEach(function (name) { | ||
var handler = $format[name]; | ||
Object.keys(format).forEach(function (name) { | ||
var handler = format[name]; | ||
Vue.filter(name, handler); | ||
@@ -580,8 +585,11 @@ }); | ||
install: install, | ||
integrate: integrate | ||
integrate: integrate, | ||
validate: validate, | ||
format: format, | ||
mixin: mixin | ||
}; | ||
exports.format = $format; | ||
exports.format = format; | ||
exports.validate = validate; | ||
exports.mixin = mixins; | ||
exports.mixin = mixin; | ||
exports['default'] = index; |
@@ -281,12 +281,17 @@ import moment from 'moment'; | ||
* @param {String} date | ||
* @param {{ from: String, to: String }} [options] | ||
* @param {{ from: String, to: String, UTC: Boolean }} [options] | ||
* @returns {String} | ||
*/ | ||
var toDate = function (date, options) { | ||
if ( options === void 0 ) options = {}; | ||
var toDate = function (date, ref) { | ||
if ( ref === void 0 ) ref = {}; | ||
var to = ref.to; if ( to === void 0 ) to = 'DD/MM/YYYY'; | ||
var from = ref.from; if ( from === void 0 ) from = getDateFormat(date); | ||
var isUTC = ref.UTC; if ( isUTC === void 0 ) isUTC = false; | ||
var from = options.from || getDateFormat(date); | ||
var to = options.to || 'DD/MM/YYYY'; | ||
var isValid = from && isDate(date, from); | ||
var formatted = !isValid ? null : moment(date, from).format(to); | ||
if (!isValid) { | ||
return null | ||
} | ||
var formatter = isUTC ? moment.utc : moment; | ||
var formatted = formatter(date, from).format(to); | ||
return formatted | ||
@@ -401,3 +406,3 @@ }; | ||
var $format = Object.freeze({ | ||
var format = Object.freeze({ | ||
toCPF: toCPF, | ||
@@ -475,3 +480,3 @@ toRG: toRG, | ||
var mixins = Object.freeze({ | ||
var mixin = Object.freeze({ | ||
Loadable: Loadable, | ||
@@ -534,8 +539,8 @@ ObservableFix: ObservableFix | ||
if (options.formatters) { | ||
Vue.prototype.$format = $format; | ||
Vue.prototype.$format = format; | ||
} | ||
if (options.formatFilters) { | ||
Object.keys($format).forEach(function (name) { | ||
var handler = $format[name]; | ||
Object.keys(format).forEach(function (name) { | ||
var handler = format[name]; | ||
Vue.filter(name, handler); | ||
@@ -574,6 +579,9 @@ }); | ||
install: install, | ||
integrate: integrate | ||
integrate: integrate, | ||
validate: validate, | ||
format: format, | ||
mixin: mixin | ||
}; | ||
export { $format as format, validate, mixins as mixin }; | ||
export { format, validate, mixin }; | ||
export default index; |
@@ -0,0 +0,0 @@ MIT License |
{ | ||
"name": "vue-convenia-util", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "Plugin com validações, formatações e filtros para projetos Vue.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -112,10 +112,12 @@ import moment from 'moment' | ||
* @param {String} date | ||
* @param {{ from: String, to: String }} [options] | ||
* @param {{ from: String, to: String, UTC: Boolean }} [options] | ||
* @returns {String} | ||
*/ | ||
export const toDate = (date, options = {}) => { | ||
const from = options.from || getDateFormat(date) | ||
const to = options.to || 'DD/MM/YYYY' | ||
export const toDate = (date, { to = 'DD/MM/YYYY', from = getDateFormat(date), UTC: isUTC = false } = {}) => { | ||
const isValid = from && isDate(date, from) | ||
const formatted = !isValid ? null : moment(date, from).format(to) | ||
if (!isValid) { | ||
return null | ||
} | ||
const formatter = isUTC ? moment.utc : moment | ||
const formatted = formatter(date, from).format(to) | ||
return formatted | ||
@@ -122,0 +124,0 @@ } |
@@ -1,7 +0,7 @@ | ||
import * as $format from './formatters' | ||
import * as $validate from './validators' | ||
import * as $mixins from './mixins' | ||
import * as format from './formatters' | ||
import * as validate from './validators' | ||
import * as mixin from './mixins' | ||
import integrations from './integrations' | ||
export { $format as format, $validate as validate, $mixins as mixin } | ||
export { format, validate, mixin } | ||
@@ -24,8 +24,8 @@ /** | ||
if (options.formatters) { | ||
Vue.prototype.$format = $format | ||
Vue.prototype.$format = format | ||
} | ||
if (options.formatFilters) { | ||
Object.keys($format).forEach(name => { | ||
const handler = $format[name] | ||
Object.keys(format).forEach(name => { | ||
const handler = format[name] | ||
Vue.filter(name, handler) | ||
@@ -36,3 +36,3 @@ }) | ||
if (options.validators) { | ||
Vue.prototype.$validate = $validate | ||
Vue.prototype.$validate = validate | ||
} | ||
@@ -63,3 +63,6 @@ } | ||
install, | ||
integrate | ||
integrate, | ||
validate, | ||
format, | ||
mixin | ||
} |
Sorry, the diff of this file is not supported yet
295285
1514