forked from tywalch/electrodb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial commit * Adding type `any` and laying the groundwork for types `map`, `set`, and `list`. * Updating readme to include info on new type `"any"`. * Fixing failed tests
- Loading branch information
Showing
8 changed files
with
464 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function getPartDetail(part = "") { | ||
let detail = { | ||
expression: "", | ||
name: "", | ||
value: "", | ||
}; | ||
if (part.includes("[")) { | ||
if (!part.match(/\[\d\]/gi)) { | ||
throw new Error(`Invalid path part "${part}" has bracket containing non-numeric characters.`); | ||
} | ||
let [name] = part.match(/.*(?=\[)/gi); | ||
detail.name = `#${name}`; | ||
detail.value = name; | ||
} else { | ||
detail.name = `#${part}`; | ||
detail.value = part; | ||
} | ||
detail.expression = `#${part}`; | ||
return detail; | ||
} | ||
|
||
function parse(path = "") { | ||
if (typeof path !== "string" || !path.length) { | ||
throw new Error("Path must be a string with a non-zero length"); | ||
} | ||
let parts = path.split(/\./gi); | ||
let attr = getPartDetail(parts[0]).value; | ||
let target = getPartDetail(parts[parts.length-1]); | ||
if (target.expression.includes("[")) { | ||
|
||
} | ||
let names = {}; | ||
let expressions = [] | ||
for (let part of parts) { | ||
let detail = getPartDetail(part); | ||
names[detail.name] = detail.value; | ||
expressions.push(detail.expression); | ||
} | ||
return {attr, path, names, target: target.value, expression: expressions.join(".")}; | ||
} | ||
|
||
module.exports = { | ||
parse, | ||
getPartDetail | ||
}; |
Oops, something went wrong.