Merged submission module code

This commit is contained in:
Giuseppe
2018-07-26 18:36:36 +02:00
parent b6e4e2562d
commit 6f60cd68e2
179 changed files with 9143 additions and 77 deletions

View File

@@ -0,0 +1,41 @@
import { hasValue } from '../../shared/empty.util';
export interface SectionErrorPath {
sectionId: string;
fieldId?: string;
fieldIndex?: number;
originalPath: string;
}
const regex = /([^\/]+)/g;
// const regex = /\/sections\/(.*)\/(.*)\/(.*)/;
const regexShort = /\/sections\/(.*)/;
/**
* the following method accept an array of section path strings and return a path object
* @param {string | string[]} path
* @returns {SectionErrorPath[]}
*/
const parseSectionErrorPaths = (path: string | string[]): SectionErrorPath[] => {
const paths = typeof path === 'string' ? [path] : path;
return paths.map((item) => {
if (item.match(regex) && item.match(regex).length > 2) {
return {
sectionId: item.match(regex)[1],
fieldId: item.match(regex)[2],
fieldIndex: hasValue(item.match(regex)[3]) ? +item.match(regex)[3] : 0,
originalPath: item,
};
} else {
return {
sectionId: item.match(regexShort)[1],
originalPath: item,
};
}
}
);
};
export default parseSectionErrorPaths;