import startCase from 'lodash/startCase' ; /**
 * Remove punctuation and illegal characters from a story ID.
 *
 * See https://gist.github.com/davidjrice/9d2af51100e41c6c4b4a
 */ export const sanitize = ( string ) => { return ( string . toLowerCase ( ) . replace ( /[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi , '-' ) . replace ( /-+/g , '-' ) . replace ( /^-+/ , '' ) . replace ( /-+$/ , '' ) ) ; } ; const sanitizeSafe = ( string , part ) => { const sanitized = sanitize ( string ) ; if ( sanitized === '' ) { throw new Error ( `Invalid ${ part } '${ string }', must include alphanumeric characters` ) ; } return sanitized ; } ; /**
 * Generate a storybook ID from a component/kind and story name.
 */ export const toId = ( kind , name ? ) => `${ sanitizeSafe ( kind , 'kind' ) }${ name ? `--${ sanitizeSafe ( name , 'name' ) }` : '' }` ; /**
 * Transform a CSF named export into a readable story name
 */ export const storyNameFromExport = ( key ) => startCase ( key ) ; type StoryDescriptor = string [ ] | RegExp ; export interface IncludeExcludeOptions { includeStories ? : StoryDescriptor ; excludeStories ? : StoryDescriptor ; } function matches ( storyKey , arrayOrRegex ) { if ( Array . isArray ( arrayOrRegex ) ) { return arrayOrRegex . includes ( storyKey ) ; } return storyKey . match ( arrayOrRegex ) ; } /**
 * Does a named export match CSF inclusion/exclusion options?
 */ export function isExportStory ( key , { includeStories , excludeStories } ) { return ( key !== '__esModule' && ( ! includeStories || matches ( key , includeStories ) ) && ( ! excludeStories || ! matches ( key , excludeStories ) ) ) ; } export interface SeparatorOptions { rootSeparator : string | RegExp ; groupSeparator : string | RegExp ; } /**
 * Parse out the component/kind name from a path, using the given separator config.
 */ export const parseKind = ( kind , { rootSeparator , groupSeparator } ) => { const [ root , remainder ] = kind . split ( rootSeparator , 2 ) ; const groups = ( remainder || kind ) . split ( groupSeparator ) . filter ( i => ! ! i ) ; return { root : remainder ? root : null , groups , } ; } ; export * from './story' ;