1 | import { DeriveJunction } from './DeriveJunction.js';
|
2 | const RE_JUNCTION = /\/(\/?)([^/]+)/g;
|
3 |
|
4 |
|
5 |
|
6 | export function keyExtractPath(derivePath) {
|
7 | const parts = derivePath.match(RE_JUNCTION);
|
8 | const path = [];
|
9 | let constructed = '';
|
10 | if (parts) {
|
11 | constructed = parts.join('');
|
12 | for (const p of parts) {
|
13 | path.push(DeriveJunction.from(p.substring(1)));
|
14 | }
|
15 | }
|
16 | if (constructed !== derivePath) {
|
17 | throw new Error(`Re-constructed path "${constructed}" does not match input`);
|
18 | }
|
19 | return {
|
20 | parts,
|
21 | path
|
22 | };
|
23 | }
|