import { EXAMPLE_COMPONENTS } from './example-module' ; /**
 * Example data with information about component name, selector, files used in
 * example, and path to examples.
 */ export class ExampleData { /** Id */ id : string ; /** Description of the example. */ description : string ; /** List of files that are part of this example. */ exampleFiles : string [ ] ; /** Selector name of the example component. */ selectorName : string ; /** Name of the file that contains the example component. */ indexFilename : string ; /** Names of the components being used in this example. */ componentNames : string [ ] ; /** Variants of library for which this example is belonging to. Empty means valid for all variants */ variant : string ; static find ( library , id ) { return Object . keys ( EXAMPLE_COMPONENTS as { [ id ] : { } ; } ) . filter ( ( exampleId ) => EXAMPLE_COMPONENTS [ exampleId ] [ 'module' ] [ 'importSpecifier' ] === `${ library }/${ id }` ) . map ( ( exampleId ) => new ExampleData ( exampleId ) ) ; } static findByVariant ( library , id , variant ) { return ExampleData . find ( library , id ) . filter ( ( value ) => ! value . variant || value . variant === variant ) ; } constructor ( example ) { if ( ! example || ! EXAMPLE_COMPONENTS . hasOwnProperty ( example ) ) { return ; } const { componentName , files , selector , primaryFile , additionalComponents , title , variant } = EXAMPLE_COMPONENTS [ example ] ; const exampleName = example . replace ( /(?:^\w|\b\w)/g , ( letter ) => letter . toUpperCase ( ) ) ; this . id = example ; this . exampleFiles = files ; this . selectorName = selector ; this . indexFilename = primaryFile ; this . description = title || exampleName . replace ( /[\-]+/g , ' ' ) + ' Example' ; this . componentNames = [ componentName , ... additionalComponents ] ; this . variant = variant ; } }