From 0c22223596343d09dba8a651d9343e1b86df6b80 Mon Sep 17 00:00:00 2001 From: Dale Hui Date: Sun, 2 Dec 2018 04:20:01 -0800 Subject: [PATCH 1/5] Cleanup get() (single return type) and improve has() happy-case performance - https://github.com/jhermsmeier/node-http-link-header/issues/14#issuecomment-443470506 --- lib/link.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/link.js b/lib/link.js index f46fc2b..bb5ef86 100644 --- a/lib/link.js +++ b/lib/link.js @@ -74,7 +74,7 @@ class Link { * Get refs where given attribute has a given value * @param {String} attr * @param {String} value - * @returns {Array|null} + * @returns {Array} */ get( attr, value ) { @@ -88,7 +88,7 @@ class Link { } } - return links.length ? links : null + return links } @@ -98,7 +98,17 @@ class Link { } has( attr, value ) { - return this.get( attr, value ) != null + + attr = attr.toLowerCase() + + for( var i = 0; i < this.refs.length; i++ ) { + if( this.refs[ i ][ attr ] === value ) { + return true + } + } + + return false + } parse( value, offset ) { From 68f507bc11e00eb752eecf63bfdfd50260fd8f9b Mon Sep 17 00:00:00 2001 From: Dale Hui Date: Sun, 2 Dec 2018 04:22:11 -0800 Subject: [PATCH 2/5] Fix has() test and add a test for the negative case --- test/api.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/api.js b/test/api.js index 651ed7c..318e02f 100644 --- a/test/api.js +++ b/test/api.js @@ -25,7 +25,13 @@ suite( 'API', function() { test( 'has("rel", "next")', function() { var link = Link.parse( ';rel="next", ;rel="terms-of-service"' ) // console.log( inspect( link.has( 'rel', 'next' ) ) ) - assert.deepEqual( link.has( 'next' ), true ) + assert.deepEqual( link.has( 'rel', 'next' ), true ) + }) + + test( 'has("rel", "prev")', function() { + var link = Link.parse( ';rel="next", ;rel="terms-of-service"' ) + // console.log( inspect( link.has( 'rel', 'prev' ) ) ) + assert.deepEqual( link.has( 'rel', 'prev' ), false ) }) test( 'toString()', function() { From 22edf2073f3ece5bb0cf2136cc11084d1de93170 Mon Sep 17 00:00:00 2001 From: Jonas Hermsmeier Date: Wed, 5 Dec 2018 21:57:46 +0100 Subject: [PATCH 3/5] doc: Update authors file --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 145279e..634deb2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,4 @@ Jonas Hermsmeier +Dale Hui Matteo Brancaleoni Yamagishi Kazutoshi From fee31bab7d2f1b78f3fd9bb8d035feb1c7022940 Mon Sep 17 00:00:00 2001 From: Jonas Hermsmeier Date: Wed, 5 Dec 2018 21:58:00 +0100 Subject: [PATCH 4/5] doc: Update changelog --- CHANGELOG.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9238a5..93cd208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## v1.0.2 + +- Make `.get()` have a consistent return type ([@dhui]) +- Improve `.has()` best-case performance ([@dhui]) +- Fix `.has()` test and add a test for the negative case ([@dhui]) + +## v1.0.1 + +- Fix `link.has()` always returning `true` + ## v1.0.0 **Breaking Changes:** @@ -14,4 +24,7 @@ - Fixed handling of backslash-escaped characters - Fixed missing cardinality handling for `type`, `media` and `title` attributes - Fixed handling of leading / trailing whitespace around delimiters -- Replace `querystring.*()` with `xxcodeURIComponent()` ([@ykzts](https://github.com/ykzts)) +- Replace `querystring.*()` with `xxcodeURIComponent()` ([@ykzts]) + +[@ykzts]: https://github.com/ykzts +[@dhui]: https://github.com/dhui From 57fa8427048d60471242ba95060e5bd0ef1e8af2 Mon Sep 17 00:00:00 2001 From: Jonas Hermsmeier Date: Wed, 5 Dec 2018 21:58:11 +0100 Subject: [PATCH 5/5] chore(package): Version 1.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dc1cae5..aa6dc22 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "http-link-header", - "version": "1.0.1", + "version": "1.0.2", "description": "Parse & format HTTP link headers according to RFC 8288", "author": "Jonas Hermsmeier (https://jhermsmeier.de)", "license": "MIT",