From ffe806110b0bf093ded65c06d63ad5c527ba18d2 Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Sun, 5 Apr 2026 20:51:36 +0530 Subject: [PATCH 1/3] refactor: replace the parse-link-header dev dependency Remove the external `parse-link-header` dependency from the root development dependency and replace its only in-repo usage with a local parser in `_tools/github/get`. --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../_tools/github/get/lib/linkheader.js | 196 ++++++++++++++++++ .../@stdlib/_tools/github/get/lib/resolve.js | 2 +- .../_tools/github/get/test/test.linkheader.js | 109 ++++++++++ package.json | 1 - 4 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 lib/node_modules/@stdlib/_tools/github/get/lib/linkheader.js create mode 100644 lib/node_modules/@stdlib/_tools/github/get/test/test.linkheader.js diff --git a/lib/node_modules/@stdlib/_tools/github/get/lib/linkheader.js b/lib/node_modules/@stdlib/_tools/github/get/lib/linkheader.js new file mode 100644 index 000000000000..70f73d21e267 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/github/get/lib/linkheader.js @@ -0,0 +1,196 @@ +/** +* @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 parseURL = require( 'url' ).parse; +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var trim = require( '@stdlib/string/base/trim' ); +var objectKeys = require( '@stdlib/utils/keys' ); + + +// VARIABLES // + +var MAX_LENGTH = 2000; + + +// FUNCTIONS // + +/** +* Splits a link header into individual link values. +* +* @private +* @param {string} str - header string +* @returns {StringArray} link values +*/ +function splitValues( str ) { + var values; + var quoted; + var angled; + var start; + var i; + + values = []; + start = 0; + quoted = false; + angled = false; + + for ( i = 0; i < str.length; i++ ) { + if ( str.charCodeAt( i ) === 34 ) { + quoted = !quoted; + } else if ( quoted === false ) { + if ( str.charCodeAt( i ) === 60 ) { + angled = true; + } else if ( str.charCodeAt( i ) === 62 ) { + angled = false; + } else if ( str.charCodeAt( i ) === 44 && angled === false ) { + values.push( str.substring( start, i ) ); + start = i + 1; + } + } + } + values.push( str.substring( start ) ); + return values; +} + +/** +* Removes wrapping double quotes from a string. +* +* @private +* @param {string} str - input string +* @returns {string} unwrapped string +*/ +function unwrap( str ) { + if ( + str.length >= 2 && + str.charCodeAt( 0 ) === 34 && + str.charCodeAt( str.length-1 ) === 34 + ) { + return str.substring( 1, str.length-1 ); + } + return str; +} + +/** +* Parses an individual link header value. +* +* @private +* @param {string} str - link value +* @returns {(Object|null)} parsed link or null +*/ +function parseValue( str ) { + var rels; + var out; + var url; + var idx; + var q; + var v; + var k; + var i; + + str = trim( str ); + if ( str.length === 0 || str.charCodeAt( 0 ) !== 60 ) { + return null; + } + idx = str.indexOf( '>' ); + if ( idx < 0 ) { + return null; + } + url = str.substring( 1, idx ); + out = { + 'url': url + }; + + q = parseURL( url, true ).query; + for ( k in q ) { + if ( hasOwnProp( q, k ) ) { + out[ k ] = q[ k ]; + } + } + str = str.substring( idx+1 ); + str = str.split( ';' ); + + for ( i = 0; i < str.length; i++ ) { + v = trim( str[ i ] ); + if ( v.length === 0 ) { + continue; + } + idx = v.indexOf( '=' ); + if ( idx < 0 ) { + continue; + } + k = trim( v.substring( 0, idx ) ); + v = unwrap( trim( v.substring( idx+1 ) ) ); + out[ k ] = v; + } + if ( typeof out.rel !== 'string' || out.rel.length === 0 ) { + return null; + } + rels = out.rel.split( /\s+/ ); + return { + 'rels': rels, + 'value': out + }; +} + + +// MAIN // + +/** +* Parses a Link header. +* +* @private +* @param {string} header - link header +* @returns {(Object|null)} parsed links or null +*/ +function parseLinkHeader( header ) { + var values; + var out; + var obj; + var i; + var j; + + if ( typeof header !== 'string' || header.length === 0 ) { + return null; + } + if ( header.length > MAX_LENGTH ) { + return null; + } + values = splitValues( header ); + out = {}; + for ( i = 0; i < values.length; i++ ) { + obj = parseValue( values[ i ] ); + if ( obj === null ) { + continue; + } + for ( j = 0; j < obj.rels.length; j++ ) { + out[ obj.rels[ j ] ] = obj.value; + } + } + if ( objectKeys( out ).length === 0 ) { + return null; + } + return out; +} + + +// EXPORTS // + +module.exports = parseLinkHeader; diff --git a/lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js b/lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js index 1f4a99ccfdc2..55e7ddf3609c 100644 --- a/lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js +++ b/lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js @@ -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( './linkheader.js' ); var request = require( './request.js' ); var flatten = require( './flatten.js' ); var getOptions = require( './options.js' ); diff --git a/lib/node_modules/@stdlib/_tools/github/get/test/test.linkheader.js b/lib/node_modules/@stdlib/_tools/github/get/test/test.linkheader.js new file mode 100644 index 000000000000..f04d08eb243e --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/github/get/test/test.linkheader.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var parseLinkHeader = require( './../lib/linkheader.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof parseLinkHeader, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `null` if provided an empty header', function test( t ) { + t.strictEqual( parseLinkHeader( '' ), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `null` if provided a malformed header', function test( t ) { + t.strictEqual( parseLinkHeader( 'beep; boop' ), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `null` if provided a header exceeding the maximum length', function test( t ) { + var header; + var tail; + var i; + + header = '; rel="next", '; + tail = ''; + for ( i = 0; i < 2100; i++ ) { + tail += 'a'; + } + header += tail; + + t.strictEqual( header.length > 2000, true, 'test fixture exceeds maximum length' ); + t.strictEqual( parseLinkHeader( header ), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the function parses paginated GitHub link headers', function test( t ) { + var header; + var out; + + header = '; rel="next", ; rel="last"'; + out = parseLinkHeader( header ); + + t.deepEqual( out, { + 'next': { + 'url': 'https://api.github.com/user/9287/repos?page=2&per_page=1', + 'page': '2', + 'per_page': '1', + 'rel': 'next' + }, + 'last': { + 'url': 'https://api.github.com/user/9287/repos?page=3&per_page=1', + 'page': '3', + 'per_page': '1', + 'rel': 'last' + } + }, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports multiple relation types for a single link value', function test( t ) { + var header; + var out; + + header = '; rel="prev previous"'; + out = parseLinkHeader( header ); + + t.strictEqual( out.prev, out.previous, 'relations reference the same value' ); + t.strictEqual( out.prev.page, '1', 'sets query parameter values' ); + t.strictEqual( out.prev.rel, 'prev previous', 'retains original relation string' ); + t.end(); +}); + +tape( 'the function preserves additional link parameters', function test( t ) { + var header; + var out; + + header = '; rel="next"; type="application/json"; title="next, page"'; + out = parseLinkHeader( header ); + + t.strictEqual( out.next.type, 'application/json', 'sets the media type' ); + t.strictEqual( out.next.title, 'next, page', 'sets the title' ); + t.end(); +}); diff --git a/package.json b/package.json index e168d891abb3..fd456a83c80b 100644 --- a/package.json +++ b/package.json @@ -155,7 +155,6 @@ "mathjax-node-sre": "^3.0.0", "mkdirp": "^0.5.1", "mustache": "^4.0.0", - "parse-link-header": "^1.0.1", "plato": "^1.5.0", "process": "^0.11.10", "proxyquire": "^2.0.0", From 23f2ce9ff9c7ba968ef4698d687759a0bb68fe1e Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Wed, 8 Apr 2026 16:24:18 +0530 Subject: [PATCH 2/3] feat: add utils/parse-link-header --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/_tools/github/get/lib/resolve.js | 2 +- .../@stdlib/utils/parse-link-header/README.md | 109 ++++++++++++++++++ .../parse-link-header/benchmark/benchmark.js | 51 ++++++++ .../utils/parse-link-header/docs/repl.txt | 36 ++++++ .../parse-link-header/docs/types/index.d.ts | 63 ++++++++++ .../parse-link-header/docs/types/test.ts | 44 +++++++ .../utils/parse-link-header/examples/index.js | 35 ++++++ .../utils/parse-link-header/lib/index.js | 40 +++++++ .../parse-link-header/lib/main.js} | 10 +- .../utils/parse-link-header/package.json | 67 +++++++++++ .../parse-link-header/test/test.js} | 22 +++- 11 files changed, 472 insertions(+), 7 deletions(-) create mode 100644 lib/node_modules/@stdlib/utils/parse-link-header/README.md create mode 100644 lib/node_modules/@stdlib/utils/parse-link-header/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/utils/parse-link-header/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/utils/parse-link-header/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/utils/parse-link-header/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/utils/parse-link-header/examples/index.js create mode 100644 lib/node_modules/@stdlib/utils/parse-link-header/lib/index.js rename lib/node_modules/@stdlib/{_tools/github/get/lib/linkheader.js => utils/parse-link-header/lib/main.js} (92%) create mode 100644 lib/node_modules/@stdlib/utils/parse-link-header/package.json rename lib/node_modules/@stdlib/{_tools/github/get/test/test.linkheader.js => utils/parse-link-header/test/test.js} (88%) diff --git a/lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js b/lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js index 55e7ddf3609c..86453761197f 100644 --- a/lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js +++ b/lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js @@ -22,7 +22,7 @@ var logger = require( 'debug' ); var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var parseHeader = require( './linkheader.js' ); +var parseHeader = require( '@stdlib/utils/parse-link-header' ); var request = require( './request.js' ); var flatten = require( './flatten.js' ); var getOptions = require( './options.js' ); diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/README.md b/lib/node_modules/@stdlib/utils/parse-link-header/README.md new file mode 100644 index 000000000000..860328a95077 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-link-header/README.md @@ -0,0 +1,109 @@ + + +# parseLinkHeader + +> Parse a Link header. + +
+ +## Usage + +```javascript +var parseLinkHeader = require( '@stdlib/utils/parse-link-header' ); +``` + +#### parseLinkHeader( header ) + +Parses a `Link` header string. + +```javascript +var out = parseLinkHeader( '; 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 +``` + +
+ + + +
+ +## 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. + +
+ + + +
+ +## Examples + + + +```javascript +var parseLinkHeader = require( '@stdlib/utils/parse-link-header' ); + +var out = parseLinkHeader( '; rel="next", ; rel="last"' ); +// returns { 'next': {...}, 'last': {...} } + +out = parseLinkHeader( '; rel="next prev"; title="next, page"' ); +// returns { 'next': {...}, 'prev': {...} } + +out = parseLinkHeader( 'beep; boop' ); +// returns null +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/parse-link-header/benchmark/benchmark.js new file mode 100644 index 000000000000..b6aaa09b2808 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-link-header/benchmark/benchmark.js @@ -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 = '; rel="next", '; + header += '; 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(); +}); diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/docs/repl.txt b/lib/node_modules/@stdlib/utils/parse-link-header/docs/repl.txt new file mode 100644 index 000000000000..8abca70b8e51 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-link-header/docs/repl.txt @@ -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 = '; 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 + -------- diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/parse-link-header/docs/types/index.d.ts new file mode 100644 index 000000000000..67a7adb78130 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-link-header/docs/types/index.d.ts @@ -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( '; 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; diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/docs/types/test.ts b/lib/node_modules/@stdlib/utils/parse-link-header/docs/types/test.ts new file mode 100644 index 000000000000..023bc4378ffb --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-link-header/docs/types/test.ts @@ -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( '; 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( '; rel="next"', 'extra' ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/examples/index.js b/lib/node_modules/@stdlib/utils/parse-link-header/examples/index.js new file mode 100644 index 000000000000..804d81b649de --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-link-header/examples/index.js @@ -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( '; rel="next", ; rel="last"' ); +console.log( out ); + +out = parseLinkHeader( '; rel="next prev"; title="next, page"' ); +console.log( out ); + +out = parseLinkHeader( 'beep; boop' ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/lib/index.js b/lib/node_modules/@stdlib/utils/parse-link-header/lib/index.js new file mode 100644 index 000000000000..5db1a3043461 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-link-header/lib/index.js @@ -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( '; 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; diff --git a/lib/node_modules/@stdlib/_tools/github/get/lib/linkheader.js b/lib/node_modules/@stdlib/utils/parse-link-header/lib/main.js similarity index 92% rename from lib/node_modules/@stdlib/_tools/github/get/lib/linkheader.js rename to lib/node_modules/@stdlib/utils/parse-link-header/lib/main.js index 70f73d21e267..44d1d2076f70 100644 --- a/lib/node_modules/@stdlib/_tools/github/get/lib/linkheader.js +++ b/lib/node_modules/@stdlib/utils/parse-link-header/lib/main.js @@ -156,9 +156,12 @@ function parseValue( str ) { /** * Parses a Link header. * -* @private * @param {string} header - link header * @returns {(Object|null)} parsed links or null +* +* @example +* var out = parseLinkHeader( '; rel="next"' ); +* // returns { 'next': { 'url': 'https://api.github.com/user/repos?page=2', 'page': '2', 'rel': 'next' } } */ function parseLinkHeader( header ) { var values; @@ -167,10 +170,7 @@ function parseLinkHeader( header ) { var i; var j; - if ( typeof header !== 'string' || header.length === 0 ) { - return null; - } - if ( header.length > MAX_LENGTH ) { + if ( typeof header !== 'string' || header.length === 0 || header.length > MAX_LENGTH ) { return null; } values = splitValues( header ); diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/package.json b/lib/node_modules/@stdlib/utils/parse-link-header/package.json new file mode 100644 index 000000000000..323e38eb5ddc --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-link-header/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/utils/parse-link-header", + "version": "0.0.0", + "description": "Parse a Link header.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "parse", + "link", + "header", + "headers", + "http", + "pagination", + "github" + ] +} diff --git a/lib/node_modules/@stdlib/_tools/github/get/test/test.linkheader.js b/lib/node_modules/@stdlib/utils/parse-link-header/test/test.js similarity index 88% rename from lib/node_modules/@stdlib/_tools/github/get/test/test.linkheader.js rename to lib/node_modules/@stdlib/utils/parse-link-header/test/test.js index f04d08eb243e..ff3c94a0c6eb 100644 --- a/lib/node_modules/@stdlib/_tools/github/get/test/test.linkheader.js +++ b/lib/node_modules/@stdlib/utils/parse-link-header/test/test.js @@ -21,7 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var parseLinkHeader = require( './../lib/linkheader.js' ); +var parseLinkHeader = require( './../lib' ); // TESTS // @@ -32,6 +32,26 @@ tape( 'main export is a function', function test( t ) { t.end(); }); +tape( 'the function returns `null` if not provided a string', function test( t ) { + var values; + var i; + + values = [ + 3.14, + NaN, + true, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( parseLinkHeader( values[ i ] ), null, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +}); + tape( 'the function returns `null` if provided an empty header', function test( t ) { t.strictEqual( parseLinkHeader( '' ), null, 'returns expected value' ); t.end(); From f9cf9fa8e77e06f17e8515401f50f5c38c218fed Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Sat, 11 Apr 2026 01:25:45 +0530 Subject: [PATCH 3/3] refactor: move parse-link-header package to @stdlib/_tools/github/ --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/_tools/github/get/lib/resolve.js | 2 +- .../github}/parse-link-header/README.md | 6 +- .../github/parse-link-header/docs/usage.txt | 5 ++ .../parse-link-header/examples/index.js | 0 .../github}/parse-link-header/lib/index.js | 4 +- .../github}/parse-link-header/lib/main.js | 0 .../github}/parse-link-header/package.json | 18 +++--- .../github}/parse-link-header/test/test.js | 0 .../parse-link-header/benchmark/benchmark.js | 51 --------------- .../utils/parse-link-header/docs/repl.txt | 36 ----------- .../parse-link-header/docs/types/index.d.ts | 63 ------------------- .../parse-link-header/docs/types/test.ts | 44 ------------- 12 files changed, 18 insertions(+), 211 deletions(-) rename lib/node_modules/@stdlib/{utils => _tools/github}/parse-link-header/README.md (93%) create mode 100644 lib/node_modules/@stdlib/_tools/github/parse-link-header/docs/usage.txt rename lib/node_modules/@stdlib/{utils => _tools/github}/parse-link-header/examples/index.js (100%) rename lib/node_modules/@stdlib/{utils => _tools/github}/parse-link-header/lib/index.js (88%) rename lib/node_modules/@stdlib/{utils => _tools/github}/parse-link-header/lib/main.js (100%) rename lib/node_modules/@stdlib/{utils => _tools/github}/parse-link-header/package.json (82%) rename lib/node_modules/@stdlib/{utils => _tools/github}/parse-link-header/test/test.js (100%) delete mode 100644 lib/node_modules/@stdlib/utils/parse-link-header/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/utils/parse-link-header/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/utils/parse-link-header/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/utils/parse-link-header/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js b/lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js index 86453761197f..f0946c59b9bb 100644 --- a/lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js +++ b/lib/node_modules/@stdlib/_tools/github/get/lib/resolve.js @@ -22,7 +22,7 @@ var logger = require( 'debug' ); var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var parseHeader = require( '@stdlib/utils/parse-link-header' ); +var parseHeader = require( '@stdlib/_tools/github/parse-link-header' ); var request = require( './request.js' ); var flatten = require( './flatten.js' ); var getOptions = require( './options.js' ); diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/README.md b/lib/node_modules/@stdlib/_tools/github/parse-link-header/README.md similarity index 93% rename from lib/node_modules/@stdlib/utils/parse-link-header/README.md rename to lib/node_modules/@stdlib/_tools/github/parse-link-header/README.md index 860328a95077..e962470ac9fd 100644 --- a/lib/node_modules/@stdlib/utils/parse-link-header/README.md +++ b/lib/node_modules/@stdlib/_tools/github/parse-link-header/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# parseLinkHeader +# Parse Link Header > Parse a Link header. @@ -27,7 +27,7 @@ limitations under the License. ## Usage ```javascript -var parseLinkHeader = require( '@stdlib/utils/parse-link-header' ); +var parseLinkHeader = require( '@stdlib/_tools/github/parse-link-header' ); ``` #### parseLinkHeader( header ) @@ -76,7 +76,7 @@ var out = parseLinkHeader( 'beep; boop' ); ```javascript -var parseLinkHeader = require( '@stdlib/utils/parse-link-header' ); +var parseLinkHeader = require( '@stdlib/_tools/github/parse-link-header' ); var out = parseLinkHeader( '; rel="next", ; rel="last"' ); // returns { 'next': {...}, 'last': {...} } diff --git a/lib/node_modules/@stdlib/_tools/github/parse-link-header/docs/usage.txt b/lib/node_modules/@stdlib/_tools/github/parse-link-header/docs/usage.txt new file mode 100644 index 000000000000..4f0402695a8f --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/github/parse-link-header/docs/usage.txt @@ -0,0 +1,5 @@ + +Usage: parseLinkHeader( header ) + +Parses a Link header and returns a mapping of link relations to parsed +link values. diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/examples/index.js b/lib/node_modules/@stdlib/_tools/github/parse-link-header/examples/index.js similarity index 100% rename from lib/node_modules/@stdlib/utils/parse-link-header/examples/index.js rename to lib/node_modules/@stdlib/_tools/github/parse-link-header/examples/index.js diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/lib/index.js b/lib/node_modules/@stdlib/_tools/github/parse-link-header/lib/index.js similarity index 88% rename from lib/node_modules/@stdlib/utils/parse-link-header/lib/index.js rename to lib/node_modules/@stdlib/_tools/github/parse-link-header/lib/index.js index 5db1a3043461..6fca9f6392ea 100644 --- a/lib/node_modules/@stdlib/utils/parse-link-header/lib/index.js +++ b/lib/node_modules/@stdlib/_tools/github/parse-link-header/lib/index.js @@ -21,10 +21,10 @@ /** * Parse a Link header. * -* @module @stdlib/utils/parse-link-header +* @module @stdlib/_tools/github/parse-link-header * * @example -* var parseLinkHeader = require( '@stdlib/utils/parse-link-header' ); +* var parseLinkHeader = require( '@stdlib/_tools/github/parse-link-header' ); * * var out = parseLinkHeader( '; rel="next"' ); * // returns { 'next': { 'url': 'https://api.github.com/user/repos?page=2', 'page': '2', 'rel': 'next' } } diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/lib/main.js b/lib/node_modules/@stdlib/_tools/github/parse-link-header/lib/main.js similarity index 100% rename from lib/node_modules/@stdlib/utils/parse-link-header/lib/main.js rename to lib/node_modules/@stdlib/_tools/github/parse-link-header/lib/main.js diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/package.json b/lib/node_modules/@stdlib/_tools/github/parse-link-header/package.json similarity index 82% rename from lib/node_modules/@stdlib/utils/parse-link-header/package.json rename to lib/node_modules/@stdlib/_tools/github/parse-link-header/package.json index 323e38eb5ddc..238b26b7f266 100644 --- a/lib/node_modules/@stdlib/utils/parse-link-header/package.json +++ b/lib/node_modules/@stdlib/_tools/github/parse-link-header/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/utils/parse-link-header", + "name": "@stdlib/_tools/github/parse-link-header", "version": "0.0.0", "description": "Parse a Link header.", "license": "Apache-2.0", @@ -15,13 +15,11 @@ ], "main": "./lib", "directories": { - "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", "lib": "./lib", "test": "./test" }, - "types": "./docs/types", "scripts": {}, "homepage": "https://github.com/stdlib-js/stdlib", "repository": { @@ -50,18 +48,16 @@ ], "keywords": [ "stdlib", - "stdutils", - "stdutil", - "utilities", - "utility", - "utils", - "util", + "tools", + "tool", + "github", + "git", + "gh", "parse", "link", "header", "headers", "http", - "pagination", - "github" + "pagination" ] } diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/test/test.js b/lib/node_modules/@stdlib/_tools/github/parse-link-header/test/test.js similarity index 100% rename from lib/node_modules/@stdlib/utils/parse-link-header/test/test.js rename to lib/node_modules/@stdlib/_tools/github/parse-link-header/test/test.js diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/parse-link-header/benchmark/benchmark.js deleted file mode 100644 index b6aaa09b2808..000000000000 --- a/lib/node_modules/@stdlib/utils/parse-link-header/benchmark/benchmark.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @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 = '; rel="next", '; - header += '; 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(); -}); diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/docs/repl.txt b/lib/node_modules/@stdlib/utils/parse-link-header/docs/repl.txt deleted file mode 100644 index 8abca70b8e51..000000000000 --- a/lib/node_modules/@stdlib/utils/parse-link-header/docs/repl.txt +++ /dev/null @@ -1,36 +0,0 @@ - -{{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 = '; 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 - -------- diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/parse-link-header/docs/types/index.d.ts deleted file mode 100644 index 67a7adb78130..000000000000 --- a/lib/node_modules/@stdlib/utils/parse-link-header/docs/types/index.d.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* -* @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( '; 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; diff --git a/lib/node_modules/@stdlib/utils/parse-link-header/docs/types/test.ts b/lib/node_modules/@stdlib/utils/parse-link-header/docs/types/test.ts deleted file mode 100644 index 023bc4378ffb..000000000000 --- a/lib/node_modules/@stdlib/utils/parse-link-header/docs/types/test.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* -* @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( '; 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( '; rel="next"', 'extra' ); // $ExpectError -}