UNPKG

824 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.keyExtractPath = void 0;
4const DeriveJunction_js_1 = require("./DeriveJunction.js");
5const RE_JUNCTION = /\/(\/?)([^/]+)/g;
6/**
7 * @description Extract derivation junctions from the supplied path
8 */
9function keyExtractPath(derivePath) {
10 const parts = derivePath.match(RE_JUNCTION);
11 const path = [];
12 let constructed = '';
13 if (parts) {
14 constructed = parts.join('');
15 for (const p of parts) {
16 path.push(DeriveJunction_js_1.DeriveJunction.from(p.substring(1)));
17 }
18 }
19 if (constructed !== derivePath) {
20 throw new Error(`Re-constructed path "${constructed}" does not match input`);
21 }
22 return {
23 parts,
24 path
25 };
26}
27exports.keyExtractPath = keyExtractPath;