Skip to content

Commit

Permalink
chore: remove duplicate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Nov 24, 2023
1 parent 11b2a63 commit 2623efa
Showing 1 changed file with 0 additions and 74 deletions.
74 changes: 0 additions & 74 deletions packages/@ourworldindata/utils/src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1739,80 +1739,6 @@ export function mergePartialGrapherConfigs<T extends Record<string, any>>(
return merge({}, ...grapherConfigs)
}

export function getOriginAttributionFragments(
origins: OwidOrigin[] | undefined
): string[] {
return origins
? origins.map((origin) => {
const yearPublished = origin.datePublished
? dayjs(origin.datePublished, ["YYYY", "YYYY-MM-DD"]).year()
: undefined
const yearPublishedString = yearPublished
? ` (${yearPublished})`
: ""
return (
origin.attribution ??
`${origin.producer}${yearPublishedString}`
)
})
: []
}

export function getAttributionFromVariable(
variable: OwidVariableWithSource
): string {
return getAttributionFragmentsFromVariable(variable).join("; ")
}

export function getAttributionFragmentsFromVariable(
variable: OwidVariableWithSource
): string[] {
if (
variable.presentation?.attribution &&
variable.presentation?.attribution !== ""
)
return [variable.presentation?.attribution]
const originAttributionFragments = getOriginAttributionFragments(
variable.origins
)
const sourceName = variable.source?.name
return uniq(compact([sourceName, ...originAttributionFragments]))
}

interface ETLPathComponents {
channel: string
producer: string
version: string
dataset: string
table: string
indicator: string
}

export const getETLPathComponents = (path: string): ETLPathComponents => {
const [channel, producer, version, dataset, table, indicator] =
path.split("/")
return { channel, producer, version, dataset, table, indicator }
}

export const formatAuthors = ({
authors,
requireMax,
forBibtex,
}: {
authors: string[]
requireMax?: boolean
forBibtex?: boolean
}): string => {
if (requireMax && !authors.includes("Max Roser"))
authors = [...authors, "Max Roser"]

let authorsText = authors.slice(0, -1).join(forBibtex ? " and " : ", ")
if (authorsText.length === 0) authorsText = authors[0]
else authorsText += ` and ${last(authors)}`

return authorsText
}

/** Works for:
* #dod:text
* #dod:text-hyphenated
Expand Down

0 comments on commit 2623efa

Please sign in to comment.