forked from medblocks/medblocks-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
22 lines (21 loc) · 746 Bytes
/
utils.ts
File metadata and controls
22 lines (21 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
import transform from "./src/extension/transform";
import { Data } from "./src/medblocks/form/utils";
import type {Tree,ProcessedTree,TransformFunction} from "./src/extension/transform"
const count = (composition:Data, path:string,initialCount=1):number => {
if (!composition) return initialCount;
let pattern = new RegExp(`${path}:(\\d)+`, "g");
let arrayOfPaths = Object.keys(composition).filter((key) => key.match(pattern));
if(arrayOfPaths.length>0){
let fieldCount = pattern.exec(arrayOfPaths[arrayOfPaths.length - 1]) as RegExpExecArray;
return parseInt(fieldCount[1])+1;
}else{
return initialCount
}
};
export {
count ,
transform,
Tree,
ProcessedTree,
TransformFunction
}