mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
This refactors the front-end collateral to all live within `site` - so no `package.json` at the root. The reason we had this initially is that the jest test run and NextJS actually require having _two_ different `tsconfig`s - Next needs `jsx:"preserve"`, while jest needs `jsx:"react"` - we were using `tsconfig`s at different levels at the hierarchy to manage this. I changed this behavior to still use two different `tsconfig.json`s, which is mandatory - but just side-by-side in `site`. Once that's fixed, it was easy to move everything into `site` Follow up from: https://github.com/coder/coder/pull/118#discussion_r796244577
18 lines
504 B
TypeScript
18 lines
504 B
TypeScript
/**
|
|
* Helper function that, given an array or a single item:
|
|
* - If an array with no elements, returns null
|
|
* - If an array with 1 or more elements, returns the first element
|
|
* - If a single item, returns that item
|
|
*/
|
|
export const firstOrItem = <T>(itemOrItems: undefined | T | T[], defaults: T): T => {
|
|
if (Array.isArray(itemOrItems)) {
|
|
return itemOrItems.length > 0 ? itemOrItems[0] : defaults
|
|
}
|
|
|
|
if (typeof itemOrItems === "undefined") {
|
|
return defaults
|
|
}
|
|
|
|
return itemOrItems
|
|
}
|