Download wp-calypso/client/devdocs/docs-example/util.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/devdocs/docs-example/util.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/devdocs/docs-example/util.js
-
curl -L -o util.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/devdocs/docs-example/util.js
1.16 kB
| import debug from 'debug'; | |
| /** | |
| * Module variables | |
| */ | |
| const log = debug( 'calypso:docs-example:util' ); | |
| const getComponentName = ( docsExample ) => { | |
| if ( ! docsExample ) { | |
| return ''; | |
| } | |
| if ( docsExample.props.asyncName ) { | |
| return docsExample.props.asyncName; | |
| } | |
| if ( ! docsExample.type || ( ! docsExample.type.displayName && ! docsExample.type.name ) ) { | |
| // eslint-disable-next-line no-console | |
| return console.trace( 'Component must be defined' ); | |
| } | |
| return ( docsExample.type.displayName || docsExample.type.name ).replace( /Example$/, '' ); | |
| }; | |
| const slugToCamelCase = ( name ) => { | |
| if ( ! name ) { | |
| log( 'name is not defined' ); | |
| // eslint-disable-next-line no-console | |
| return console.trace(); | |
| } | |
| return name | |
| .replace( /-([a-z])/g, ( s ) => s[ 1 ].toUpperCase() ) | |
| .replace( /^\w/, ( s ) => s.toUpperCase() ); | |
| }; | |
| const camelCaseToSlug = ( name ) => { | |
| if ( ! name ) { | |
| log( 'name is not defined' ); | |
| // eslint-disable-next-line no-console | |
| return console.trace(); | |
| } | |
| return name.replace( /\.?([A-Z])/g, ( x, y ) => '-' + y.toLowerCase() ).replace( /^-/, '' ); | |
| }; | |
| export { getComponentName, slugToCamelCase, camelCaseToSlug }; | |