-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
extractSectionsFromArticleEdges
to lux (#117)
* defaultProps public * stuff
- Loading branch information
1 parent
2157259
commit 9f3cd28
Showing
3 changed files
with
37 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as uniq from 'lodash.uniq' | ||
|
||
/** | ||
* A function that takes in a string and capitalizes the first letter of each word. | ||
* @author Dustin Newman | ||
* @export | ||
* @param {string} The string. | ||
* @returns {string} A capitalized string. | ||
*/ | ||
function capitalizeSection(section: string): string { | ||
if (section.length === 0) { | ||
return '' | ||
} | ||
|
||
if (section === 'prime') { | ||
return 'prime' | ||
} | ||
|
||
return section | ||
.toLowerCase() | ||
.split(' ') | ||
.map(word => word.charAt(0).toUpperCase() + word.substring(1)) | ||
.join(' ') | ||
} | ||
|
||
export default function extractSectionsFromArticleEdges(edges: any): string[] { | ||
return uniq(edges.map(edge => capitalizeSection(edge.node.section))) | ||
} |