Files
freeCodeCamp/client/src/utils/to-learn-path.ts
Victor Duarte 7c6524186e refactor(client): docs, ts and test challenges (#42978)
* refactor(client): relocate to learn path tests file

* refactor(client): add docs for to learn path

Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com>

* fix: order imports

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-08-10 15:22:39 +02:00

31 lines
671 B
TypeScript

import { withPrefix } from 'gatsby';
interface ToLearnPathKwargs {
block?: string;
challenge?: string;
superBlock?: string;
}
/**
* Builds a learning url path from folders.
* - /learn/:superBlock/:block/:challenge
* @params {Object} Path kwargs.
* @returns {string} A learning url path.
*/
export default function toLearnPath({
block,
challenge,
superBlock
}: ToLearnPathKwargs): string {
// Match path order /:super-block/:block/:challenge
const folders = [superBlock, block, challenge];
return folders.reduce((path: string, folder) => {
if (folder) {
return `${path}/${folder}`;
}
return path;
}, withPrefix('/learn'));
}