Download wp-calypso/bin/codemods/src/unglobalize-selectors.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 827 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/bin/codemods/src/unglobalize-selectors.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/bin/codemods/src/unglobalize-selectors.js
-
curl -L -o unglobalize-selectors.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/bin/codemods/src/unglobalize-selectors.js
827 Bytes
| import { kebabCase } from 'lodash'; | |
| import config from './config'; | |
| export default function transformer( file, api ) { | |
| const j = api.jscodeshift; | |
| return j( file.source ) | |
| .find( j.ImportDeclaration ) | |
| .filter( ( p ) => p.node.source.value === 'state/selectors' ) | |
| .forEach( ( path ) => { | |
| path.node.specifiers | |
| .map( ( s ) => [ s.imported.name, s.local.name ] ) | |
| .sort( ( a, b ) => a[ 0 ].localeCompare( b[ 0 ] ) ) | |
| .map( ( [ name, alias ], i ) => ( { | |
| ...j.importDeclaration( | |
| [ j.importDefaultSpecifier( j.identifier( alias ) ) ], | |
| j.stringLiteral( `state/selectors/${ kebabCase( name ) }` ) | |
| ), | |
| ...( i === 0 ? { comments: path.node.comments } : {} ), | |
| } ) ) | |
| .forEach( ( i ) => j( path ).insertBefore( i ) ); | |
| j( path ).remove(); | |
| } ) | |
| .toSource( config.recastOptions ); | |
| } | |