File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import { json } from './fetch.js' ;
2+
3+ /** This will take care of the W3C HAL API */
4+ export
5+ async function * hal ( propertyTarget , link , embed , objFct ) {
6+ while ( true ) {
7+ let apiURL = new URL ( link ) ;
8+ if ( embed === true ) {
9+ apiURL . searchParams . set ( "embed" , "1" ) ; // grab everything
10+ }
11+ let data = await json ( apiURL ) ;
12+ if ( embed ) {
13+ for ( const target of data . _embedded [ propertyTarget ] ) {
14+ if ( objFct ) {
15+ yield objFct ( target ) ;
16+ } else {
17+ yield target ;
18+ }
19+ }
20+ } else {
21+ if ( data . _links [ propertyTarget ] ) {
22+ for ( const target of data . _links [ propertyTarget ] ) {
23+ if ( objFct ) {
24+ yield objFct ( target ) ;
25+ } else {
26+ yield target ;
27+ }
28+ }
29+ }
30+ }
31+ if ( data . pages && data . pages > 1 && data . page < data . pages ) {
32+ link = data . _links . next . href ;
33+ } else {
34+ return ;
35+ }
36+ }
37+ }
38+
39+ export default hal ;
You can’t perform that action at this time.
0 commit comments