Skip to content

Commit

Permalink
path: support child-of-string convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorbin committed Mar 17, 2021
1 parent f2f1e2c commit 9c352ef
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions path.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ exports.firstChild = firstChildPath;

/** Constructs a child path by appending a 1 id to a copy of the given path.
*
* @param {Path} path
* @param {string|Path} path
* @returns {Path} -- a copy of path with an added 1 id
*/
function firstChildPath(path) {
return [...path, 1];
return typeof path === 'string' ? [path, 1] : [...path, 1];
}

exports.zerothChild = zerothChildPath;

/** Constructs a child path by appending a 0 id to a copy of the given path.
*
* @param {Path} path
* @param {string|Path} path
* @returns {Path} -- a copy of path with an added 0 id
*/
function zerothChildPath(path) {
return [...path, 0];
return typeof path === 'string' ? [path, 0] : [...path, 0];
}

0 comments on commit 9c352ef

Please sign in to comment.