| 1 |
import createMask from './factory.js'; |
| 2 |
import IMask from '../core/holder.js'; |
| 3 |
import '../core/utils.js'; |
| 4 |
|
| 5 |
/** Mask pipe source and destination types */ |
| 6 |
const PIPE_TYPE = { |
| 7 |
MASKED: 'value', |
| 8 |
UNMASKED: 'unmaskedValue', |
| 9 |
TYPED: 'typedValue' |
| 10 |
}; |
| 11 |
/** Creates new pipe function depending on mask type, source and destination options */ |
| 12 |
function createPipe(arg, from, to) { |
| 13 |
if (from === void 0) { |
| 14 |
from = PIPE_TYPE.MASKED; |
| 15 |
} |
| 16 |
if (to === void 0) { |
| 17 |
to = PIPE_TYPE.MASKED; |
| 18 |
} |
| 19 |
const masked = createMask(arg); |
| 20 |
return value => masked.runIsolated(m => { |
| 21 |
m[from] = value; |
| 22 |
return m[to]; |
| 23 |
}); |
| 24 |
} |
| 25 |
|
| 26 |
/** Pipes value through mask depending on mask type, source and destination options */ |
| 27 |
function pipe(value, mask, from, to) { |
| 28 |
return createPipe(mask, from, to)(value); |
| 29 |
} |
| 30 |
IMask.PIPE_TYPE = PIPE_TYPE; |
| 31 |
IMask.createPipe = createPipe; |
| 32 |
IMask.pipe = pipe; |
| 33 |
|
| 34 |
export { PIPE_TYPE, createPipe, pipe }; |
| 35 |
|