34 lines
900 B
JavaScript
34 lines
900 B
JavaScript
import createMask from './factory.js';
|
|
import IMask from '../core/holder.js';
|
|
import '../core/utils.js';
|
|
|
|
/** Mask pipe source and destination types */
|
|
const PIPE_TYPE = {
|
|
MASKED: 'value',
|
|
UNMASKED: 'unmaskedValue',
|
|
TYPED: 'typedValue'
|
|
};
|
|
/** Creates new pipe function depending on mask type, source and destination options */
|
|
function createPipe(arg, from, to) {
|
|
if (from === void 0) {
|
|
from = PIPE_TYPE.MASKED;
|
|
}
|
|
if (to === void 0) {
|
|
to = PIPE_TYPE.MASKED;
|
|
}
|
|
const masked = createMask(arg);
|
|
return value => masked.runIsolated(m => {
|
|
m[from] = value;
|
|
return m[to];
|
|
});
|
|
}
|
|
|
|
/** Pipes value through mask depending on mask type, source and destination options */
|
|
function pipe(value, mask, from, to) {
|
|
return createPipe(mask, from, to)(value);
|
|
}
|
|
IMask.PIPE_TYPE = PIPE_TYPE;
|
|
IMask.createPipe = createPipe;
|
|
IMask.pipe = pipe;
|
|
|
|
export { PIPE_TYPE, createPipe, pipe };
|