1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 'use strict';
- var format = require('./format');
- function cascade(formats) {
- if (!formats.every(isValidFormat)) {
- return;
- }
- return function (info) {
- var obj = info;
- for (var i = 0; i < formats.length; i++) {
- obj = formats[i].transform(obj, formats[i].options);
- if (!obj) {
- return false;
- }
- }
- return obj;
- };
- }
- function isValidFormat(fmt) {
- if (typeof fmt.transform !== 'function') {
- throw new Error(['No transform function found on format. Did you create a format instance?', 'const myFormat = format(formatFn);', 'const instance = myFormat();'].join('\n'));
- }
- return true;
- }
- module.exports = function () {
- for (var _len = arguments.length, formats = new Array(_len), _key = 0; _key < _len; _key++) {
- formats[_key] = arguments[_key];
- }
- var combinedFormat = format(cascade(formats));
- var instance = combinedFormat();
- instance.Format = combinedFormat.Format;
- return instance;
- };
- module.exports.cascade = cascade;
|