type-enforcer
Version:
Type enforcement library for javascript
19 lines (14 loc) • 467 B
JavaScript
import { hasOtherValidValue, processOutput } from './helper';
export default (options) => function(newValue, isForcedSave) {
const value = options.get.call(this);
if (arguments.length) {
if (!hasOtherValidValue(options.other, newValue)) {
newValue = options.enforce(newValue, value, options);
}
if (options.compare(newValue, value) || isForcedSave) {
options.before.call(this, value);
}
return this;
}
return processOutput(value, options);
};