Skip to content

Commit

Permalink
Merge 0068ad3 into 706873b
Browse files Browse the repository at this point in the history
  • Loading branch information
mrodrig committed Jun 13, 2021
2 parents 706873b + 0068ad3 commit 616fe03
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/path.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,20 @@ function _sp(obj, kp, v) {
* @returns {{dotIndex: Number, key: String, remaining: String}}
*/
function state(kp) {
let match = (/(?<!\\)\./).exec(kp),
dotIndex = match ? match.index : -1;
let dotIndex = findFirstNonEscapedDotIndex(kp);

return {
dotIndex,
key: kp.slice(0, dotIndex >= 0 ? dotIndex : undefined).replace(/\\./g, '.'),
remaining: kp.slice(dotIndex + 1)
};
}

function findFirstNonEscapedDotIndex(kp) {
for (let i = 0; i < kp.length; i++) {
const previousChar = i > 0 ? kp[i - 1] : '',
currentChar = kp[i];
if (currentChar === '.' && previousChar !== '\\') return i;
}
return -1;
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "mrodrig",
"name": "doc-path",
"description": "A document path library for Node",
"version": "3.0.0",
"version": "3.0.1",
"homepage": "https://mrodrig.github.io/doc-path",
"repository": {
"type": "git",
Expand Down

0 comments on commit 616fe03

Please sign in to comment.