41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
import createMask from './factory.js';
|
|
import IMask from '../core/holder.js';
|
|
import '../core/utils.js';
|
|
import '../_rollupPluginBabelHelpers-b054ecd2.js';
|
|
import '../core/change-details.js';
|
|
|
|
/** Mask pipe source and destination types */
|
|
|
|
var PIPE_TYPE = {
|
|
MASKED: 'value',
|
|
UNMASKED: 'unmaskedValue',
|
|
TYPED: 'typedValue'
|
|
};
|
|
/** Creates new pipe function depending on mask type, source and destination options */
|
|
|
|
function createPipe(mask) {
|
|
var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : PIPE_TYPE.MASKED;
|
|
var to = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : PIPE_TYPE.MASKED;
|
|
var masked = createMask(mask);
|
|
return function (value) {
|
|
return masked.runIsolated(function (m) {
|
|
m[from] = value;
|
|
return m[to];
|
|
});
|
|
};
|
|
}
|
|
/** Pipes value through mask depending on mask type, source and destination options */
|
|
|
|
function pipe(value) {
|
|
for (var _len = arguments.length, pipeArgs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
pipeArgs[_key - 1] = arguments[_key];
|
|
}
|
|
|
|
return createPipe.apply(void 0, pipeArgs)(value);
|
|
}
|
|
IMask.PIPE_TYPE = PIPE_TYPE;
|
|
IMask.createPipe = createPipe;
|
|
IMask.pipe = pipe;
|
|
|
|
export { PIPE_TYPE, createPipe, pipe };
|