-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathutils.ts
More file actions
24 lines (22 loc) · 746 Bytes
/
utils.ts
File metadata and controls
24 lines (22 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { Data } from './src/medblocks/form/utils';
import type {
Tree,
ProcessedTree,
TransformFunction,
} from './src/extension/transform';
import transform from './src/extension/transform';
const count = (composition: Data, path: string, initialCount = 1): number => {
if (!composition) return initialCount;
const pattern = new RegExp(`${path}:(\\d)+`, 'g');
const arrayOfPaths = Object.keys(composition).filter(key =>
key.match(pattern)
);
if (arrayOfPaths.length > 0) {
const fieldCount = pattern.exec(
arrayOfPaths[arrayOfPaths.length - 1]
) as RegExpExecArray;
return parseInt(fieldCount[1], 10) + 1;
}
return initialCount;
};
export { count, transform, Tree, ProcessedTree, TransformFunction };