pruneEnd
pruneEnd
(pruneArg: Character | Character[]) => (aString: string) => string
Prune characters off the end of a string
const pruneTrailingDashes = pruneEnd('-') pruneTrailingDashes('--abc--') // is '--abc'
const pruneTrailingDashes = pruneEnd('-') pruneTrailingDashes('--abc--') // is '--abc'
const pruneTrailingDashes = pruneEnd('-') pruneTrailingDashes('--abc--') // is '--abc'
const pruneTrailingDashes = pruneEnd('-') pruneTrailingDashes('--abc--') // is '--abc'
Sometimes we want to remove characters from the end of strings. Below, we are coding print software for PDFs. We've parsed the external links, but the arrows remain. Let's clean them up for printing.
const pdfLinks = [ 'More Info On Added Sugars ➚', 'Nutrition Facts Label Resources ➚', 'Explore The Percent Daily Value ➚', ] const pruneLinkSymbol = pruneEnd([' ', '➚']) const cleanLinks = mapValues(pruneLinkSymbol) const links = cleanLinks(pdfLinks) console.log(links) // is // [ // More Info On Added Sugars // Nutrition Facts Label Resources // Explore The Percent Daily Value // ]
const pdfLinks = [ 'More Info On Added Sugars ➚', 'Nutrition Facts Label Resources ➚', 'Explore The Percent Daily Value ➚', ] const pruneLinkSymbol = pruneEnd([' ', '➚']) const cleanLinks = mapValues(pruneLinkSymbol)<string[]> const links = cleanLinks(pdfLinks) console.log(links) // is // [ // More Info On Added Sugars // Nutrition Facts Label Resources // Explore The Percent Daily Value // ]
const pdfLinks = [ 'More Info On Added Sugars ➚', 'Nutrition Facts Label Resources ➚', 'Explore The Percent Daily Value ➚', ] const pruneLinkSymbol = pruneEnd([' ', '➚']) const cleanLinks = mapValues(pruneLinkSymbol) const links = cleanLinks(pdfLinks) console.log(links) // is // [ // More Info On Added Sugars // Nutrition Facts Label Resources // Explore The Percent Daily Value // ]
const pdfLinks = [ 'More Info On Added Sugars ➚', 'Nutrition Facts Label Resources ➚', 'Explore The Percent Daily Value ➚', ] const pruneLinkSymbol = pruneEnd([' ', '➚']) const cleanLinks = mapValues(pruneLinkSymbol)< string[] > const links = cleanLinks(pdfLinks) console.log(links) // is // [ // More Info On Added Sugars // Nutrition Facts Label Resources // Explore The Percent Daily Value // ]