Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// MODULES //

var logger = require( 'debug' );
var parseHeader = require( 'parse-link-header' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var parseHeader = require( '@stdlib/utils/parse-link-header' );
var request = require( './request.js' );
var flatten = require( './flatten.js' );
var getOptions = require( './options.js' );
Expand Down Expand Up @@ -169,7 +169,7 @@

if ( curr === opts.page ) {
debug( 'First paginated result. Resolving %d remaining page(s).', total-count );
setTimeout( getNext( curr+1, last ), 0 ); // dezalgo'd

Check warning on line 172 in lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "dezalgo'd"
}
done();
}
Expand Down
109 changes: 109 additions & 0 deletions lib/node_modules/@stdlib/utils/parse-link-header/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# parseLinkHeader

> Parse a Link header.

<section class="usage">

## Usage

```javascript
var parseLinkHeader = require( '@stdlib/utils/parse-link-header' );
```

#### parseLinkHeader( header )

Parses a `Link` header string.

```javascript
var out = parseLinkHeader( '<https://api.github.com/user/repos?page=2&per_page=1>; rel="next"' );
// returns { 'next': { 'url': 'https://api.github.com/user/repos?page=2&per_page=1', 'page': '2', 'per_page': '1', 'rel': 'next' } }
```

If unable to parse a header, the function returns `null`.

```javascript
var out = parseLinkHeader( 'beep; boop' );
// returns null
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- The implementation is intended for pragmatic parsing of pagination `Link` headers and is **not** a standards-complete general-purpose parser.

- The function returns `null` if provided a first argument which is not a `string`.

```javascript
var out = parseLinkHeader( null );
// returns null
```

- The function returns `null` for header values longer than `2000` characters.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var parseLinkHeader = require( '@stdlib/utils/parse-link-header' );

var out = parseLinkHeader( '<https://api.github.com/user/repos?page=2&per_page=1>; rel="next", <https://api.github.com/user/repos?page=4&per_page=1>; rel="last"' );
// returns { 'next': {...}, 'last': {...} }

out = parseLinkHeader( '<https://api.github.com/user/repos?page=3>; rel="next prev"; title="next, page"' );
// returns { 'next': {...}, 'prev': {...} }

out = parseLinkHeader( 'beep; boop' );
// returns null
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var fromCodePoint = require( '@stdlib/string/from-code-point' );
var pkg = require( './../package.json' ).name;
var parseLinkHeader = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var header;
var out;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
header = '<https://api.github.com/user/repos?page=' + (2+(i%8)) + '&per_page=1>; rel="next", ';
header += '<https://api.github.com/user/repos?page=' + (10+(i%8)) + '&per_page=1>; rel="last"; title="page ' + fromCodePoint( 97 + (i%26) ) + '"';
out = parseLinkHeader( header );
if ( out === null ) {
b.fail( 'should return a parsed object' );
}
}
b.toc();
if ( out === null ) {
b.fail( 'should return an object' );
}
b.pass( 'benchmark finished' );
b.end();
});
36 changes: 36 additions & 0 deletions lib/node_modules/@stdlib/utils/parse-link-header/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

{{alias}}( header )
Parses a Link header.

The implementation is intended for pragmatic parsing of pagination Link
headers and is not a standards-complete general-purpose parser.

Header values longer than 2000 characters return `null`.

Parameters
----------
header: string
Header string to parse.

Returns
-------
out: Object|null
Parsed links or null.

Examples
--------
> var header = '<https://api.github.com/user/repos?page=2>; rel="next"';
> var out = {{alias}}( header )
{
... 'next': {
... 'url': 'https://api.github.com/user/repos?page=2',
... 'page': '2',
... 'rel': 'next'
... }
... }

> out = {{alias}}( 'beep; boop' )
null

See Also
--------
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// TypeScript Version: 4.1

/**
* Interface describing a parsed link value.
*/
interface LinkValue {
/**
* Link target URL.
*/
url: string;

/**
* Link relation string.
*/
rel: string;

/**
* Additional parsed link parameters and URL query parameters.
*/
[key: string]: string;
}

/**
* Interface describing parsed link relations.
*/
interface Links {
[key: string]: LinkValue;
}

/**
* Parses a Link header.
*
* @param header - header string to parse
* @returns parsed links or null
*
* @example
* var out = parseLinkHeader( '<https://api.github.com/user/repos?page=2>; rel="next"' );
* // returns { 'next': { 'url': 'https://api.github.com/user/repos?page=2', 'page': '2', 'rel': 'next' } }
*/
declare function parseLinkHeader( header: string ): Links | null;


// EXPORTS //

export = parseLinkHeader;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import parseLinkHeader = require( './index' );


// TESTS //

// The function returns either parsed links or null...
{
parseLinkHeader( '<https://api.github.com/user/repos?page=2>; rel="next"' ); // $ExpectType Links | null
parseLinkHeader( '' ); // $ExpectType Links | null
}

// The function does not compile if provided a non-string...
{
parseLinkHeader( true ); // $ExpectError
parseLinkHeader( false ); // $ExpectError
parseLinkHeader( 5 ); // $ExpectError
parseLinkHeader( [] ); // $ExpectError
parseLinkHeader( {} ); // $ExpectError
parseLinkHeader( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
parseLinkHeader(); // $ExpectError
parseLinkHeader( '<https://api.github.com/user/repos?page=2>; rel="next"', 'extra' ); // $ExpectError
}
35 changes: 35 additions & 0 deletions lib/node_modules/@stdlib/utils/parse-link-header/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var parseLinkHeader = require( './../lib' );


// MAIN //

var out = parseLinkHeader( '<https://api.github.com/user/repos?page=2&per_page=1>; rel="next", <https://api.github.com/user/repos?page=5&per_page=1>; rel="last"' );
console.log( out );

out = parseLinkHeader( '<https://api.github.com/user/repos?page=3>; rel="next prev"; title="next, page"' );
console.log( out );

out = parseLinkHeader( 'beep; boop' );
console.log( out );
40 changes: 40 additions & 0 deletions lib/node_modules/@stdlib/utils/parse-link-header/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

/**
* Parse a Link header.
*
* @module @stdlib/utils/parse-link-header
*
* @example
* var parseLinkHeader = require( '@stdlib/utils/parse-link-header' );
*
* var out = parseLinkHeader( '<https://api.github.com/user/repos?page=2>; rel="next"' );
* // returns { 'next': { 'url': 'https://api.github.com/user/repos?page=2', 'page': '2', 'rel': 'next' } }
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading