Download wp-calypso/client/devdocs/service.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/devdocs/service.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/devdocs/service.js
-
curl -L -o service.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/devdocs/service.js
1.15 kB
| import { stringify } from 'qs'; | |
| async function fetchDocsEndpoint( endpoint, params, callback ) { | |
| const queryParams = stringify( params ); | |
| const query = queryParams === '' ? '' : `?${ queryParams }`; | |
| const res = await fetch( `/devdocs/service/${ endpoint }${ query }` ); | |
| if ( ! res.ok ) { | |
| callback( `Error invoking /devdocs/${ endpoint }: ${ await res.text() }`, null ); | |
| return; | |
| } | |
| const contentType = res.headers.get( 'content-type' ); | |
| if ( contentType && contentType.includes( 'application/json' ) ) { | |
| callback( null, await res.json() ); | |
| } else { | |
| callback( null, await res.text() ); | |
| } | |
| } | |
| /** | |
| * This service allows you to retrieve a document list (with title, snippets and path) based on | |
| * query term or filename(s), and also to separately retrieve the document body by path. | |
| */ | |
| export default { | |
| search: function ( term, callback ) { | |
| fetchDocsEndpoint( 'search', { q: term }, callback ); | |
| }, | |
| list: function ( filenames, callback ) { | |
| fetchDocsEndpoint( 'list', { files: filenames.join( ',' ) }, callback ); | |
| }, | |
| fetch: function ( path, callback ) { | |
| fetchDocsEndpoint( 'content', { path: path }, callback ); | |
| }, | |
| }; | |