Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
set: function (value) {
var newValue;
// check for momentjs objects
if (moment.isDuration(value)) {
return {
val: moment.duration(value),
type: 'numberDatetimeOrDuration'
};
}
if (moment.isMoment(value)) {
return {
val: value.clone(),
type: 'numberDatetimeOrDuration'
};
}
// try to create momentjs objects
newValue = moment(value, moment.ISO_8601);
if (newValue.isValid()) {
return {
return function (d) {
var value = rawValFn(d);
// parse string if necessary
if (value !== misval && typeof value === 'string' && value[0].toLowerCase() === 'p') {
value = moment.duration(value);
}
// check for valid duration
if (moment.isDuration(value)) {
return value;
}
return misval;
};
} else {
it('duration baseValueFn from property should be a momentjs duration', function () {
var datum = {'a': 'P10D'};
facet = new Facet({accessor: 'a', type: 'duration'});
baseVal = utildx.baseValueFn(facet);
expect(moment.isDuration(baseVal(datum))).toBe(true);
});
}
if (!trigger) {
this._data.trigger = null;
return this;
}
if (trigger instanceof Date) {
this._data.trigger = moment(trigger);
return this;
}
if (moment.isMoment(trigger)) {
this._data.trigger = trigger;
return this;
}
if (moment.isDuration(trigger)) {
this._data.trigger = -1 * trigger.as('seconds');
return this;
}
if (typeof trigger === 'number' && isFinite(trigger)) {
this._data.trigger = -1 * trigger;
return this;
}
throw new Error('`trigger` is not correct, must be a `Number`, `Date` or `moment` or a `moment.duration`!');
}
return function (d) {
if (d === misval) {
return false;
}
var m = moment.duration(d);
return moment.isDuration(m) && m >= min && (m < max || (m <= max && max >= edge));
};
}
constructor( values, locale = DEFAULT_VALID_LOCALE ) {
this[ privateProperties.isValid ] = true;
assertions.assertLocaleIsValid( locale );
if ( typeof values !== 'object' ) {
values = moment.duration( values ).locale( locale );
}
if ( moment.isDuration( values ) ) {
this[ privateProperties.duration ] = values;
this[ privateMethods.populateValuesFromDuration ]( values );
} else {
values = this[ privateMethods.filterValues ]( values );
this[ privateMethods.setValues ]( values );
this[ privateProperties.duration ] = moment.duration(
values
).locale( locale );
}
this[ privateMethods.createGetters ]();
Object.freeze( this );
}
fn: function () {
var max;
if (this.isContinuous) {
max = parseFloat(this.maxvalAsText);
if (isNaN(max)) {
max = 100;
}
} else if (this.isDatetime) {
max = moment(this.maxvalAsText, moment.ISO_8601);
if (!max.isValid()) {
max = moment('2020-01-01 00:00', moment.ISO_8601);
}
} else if (this.isDuration) {
max = moment.duration(this.maxvalAsText);
if (!moment.isDuration(max)) {
max = moment.duration(100, 'seconds');
}
}
return max;
},
cache: false
triggerAfter (trigger) {
if (trigger === undefined) {
return this._data.trigger;
}
if (moment.isDuration(trigger)) {
this._data.trigger = -1 * trigger.as('seconds');
return this;
}
return this.trigger(typeof trigger === 'number' ? -1 * trigger : trigger);
}
fn: function () {
var min;
if (this.isContinuous) {
min = parseFloat(this.minvalAsText);
if (isNaN(min)) {
min = 0;
}
} else if (this.isDatetime) {
min = moment(this.minvalAsText, moment.ISO_8601);
if (!min.isValid()) {
min = moment('2010-01-01 00:00', moment.ISO_8601);
}
} else if (this.isDuration) {
min = moment.duration(this.minvalAsText);
if (!moment.isDuration(min)) {
min = moment.duration(1, 'seconds');
}
}
return min;
},
cache: false