mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-21 04:57:05 +02:00
refactor: re-implement idx (safe getter) & add test
This commit is contained in:
parent
4bc010bfcc
commit
391a8b5500
2 changed files with 48 additions and 2 deletions
|
@ -29,8 +29,13 @@ function getPath(pathStr, cleanUrl = false) {
|
|||
: removeExtension(pathStr);
|
||||
}
|
||||
|
||||
function idx(target, path) {
|
||||
return path.reduce((obj, key) => obj && obj[key], target);
|
||||
function idx(target, keyPaths) {
|
||||
return (
|
||||
target &&
|
||||
(Array.isArray(keyPaths)
|
||||
? keyPaths.reduce((obj, key) => obj && obj[key], target)
|
||||
: target[keyPaths])
|
||||
);
|
||||
}
|
||||
|
||||
function getGitLastUpdated(filepath) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue