sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
10 lines (7 loc) • 305 B
text/typescript
import {randomKey} from './randomKey'
function hasKey<T extends {_key?: string}>(item: T): item is T & {_key: string} {
return item._key !== undefined
}
export function ensureKey<T extends {_key?: string}>(item: T): T & {_key: string} {
return hasKey(item) ? item : {...item, _key: randomKey(12)}
}