aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.js')
-rw-r--r--src/utils.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/utils.js b/src/utils.js
new file mode 100644
index 0000000..0ab00eb
--- /dev/null
+++ b/src/utils.js
@@ -0,0 +1,23 @@
1const path = require('path');
2
3const repeat = (value, times) =>
4 times <= 0 ? [] : [value, ...repeat(value, times - 1)];
5const diffPursModuleNames = (from, target, parts) => {
6 if (!from.length) return parts.concat(target);
7 if (!target.length) return parts.concat(repeat('..', from.length));
8 const [head_from, ...tail_from] = from;
9 const [head_target, ...tail_target] = target;
10 return head_from === head_target
11 ? diffPursModuleNames(tail_from, tail_target, parts)
12 : parts.concat(repeat('..', from.length), target);
13};
14exports.resolvePursModule = ({ baseModulePath, baseModuleName, targetModuleName }) => {
15 const parts = diffPursModuleNames(
16 baseModuleName.split('.'),
17 targetModuleName.split('.'),
18 []);
19 return parts.length
20 ? path.resolve(baseModulePath,
21 `${path.join(...parts)}.purs`)
22 : baseModulePath;
23};