sanity-plugin-taxonomy-manager
Version:
Create and manage SKOS compliant taxonomies, thesauri, and classification schemes in Sanity Studio.
21 lines (17 loc) • 614 B
text/typescript
import {customAlphabet} from 'nanoid'
import type {Options} from '../types'
const defaultAlphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
const defaultLength = 6
const defaultPrefix = ''
/**
* #### Create Unique Identifier
* Used for creating the unique identification segment
* of URIs.
*/
export function createId(ident?: Options['ident']): string {
const alphabet = ident?.pattern || defaultAlphabet
const length = ident?.length || defaultLength
const prefix = ident?.prefix || defaultPrefix
const nanoid = customAlphabet(alphabet, length)
return prefix + nanoid()
}