From bc2fdaafdb7e377f634529743f786b13814a4825 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 19 Dec 2019 11:41:33 -0800 Subject: [PATCH] Add support for disabling the fallback (#5) --- index.js | 8 +++++--- package.json | 2 +- readme.md | 6 ++++++ test.js | 26 ++++++++++++++++++++++++++ test.js.md | 14 +++++++++++++- test.js.snap | Bin 180 -> 237 bytes 6 files changed, 51 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 03f8397..e9124f2 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ import terminalLink from 'terminal-link'; const Link = props => { return ( - terminalLink(children, props.url)}> + terminalLink(children, props.url, {fallback: props.fallback})}> {props.children} ); @@ -16,11 +16,13 @@ Link.propTypes = { PropTypes.arrayOf(PropTypes.node), PropTypes.node ]).isRequired, - url: PropTypes.string + url: PropTypes.string, + fallback: PropTypes.bool }; Link.defaultProps = { - url: '' + url: '', + fallback: true }; module.exports = Link; diff --git a/package.json b/package.json index 8256007..2fccaa1 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ ], "dependencies": { "prop-types": "^15.7.2", - "terminal-link": "^1.2.0" + "terminal-link": "^2.1.1" }, "devDependencies": { "@babel/cli": "^7.2.3", diff --git a/readme.md b/readme.md index fd4c8ec..b3c20bb 100644 --- a/readme.md +++ b/readme.md @@ -43,6 +43,12 @@ Type: `string` The URL to link to. +#### fallback + +Type: `boolean`\ +Default: `true` + +Determines whether the URL should be printed in parens after the text for unsupported terminals: `My website (https://sindresorhus.com)`. ## Related diff --git a/test.js b/test.js index 0c0a418..5873b45 100644 --- a/test.js +++ b/test.js @@ -37,3 +37,29 @@ test('render fallback', t => { console.log(lastFrame()); t.snapshot(lastFrame()); }); + +test('exclude fallback if disabled', t => { + process.env.FORCE_HYPERLINK = 0; + const Link = require('.'); + + const {lastFrame} = render( + + My Website + + ); + console.log(lastFrame()); + t.snapshot(lastFrame()); +}); + +test('include fallback if explicitly enabled', t => { + process.env.FORCE_HYPERLINK = 0; + const Link = require('.'); + + const {lastFrame} = render( + + My Website + + ); + console.log(lastFrame()); + t.snapshot(lastFrame()); +}); diff --git a/test.js.md b/test.js.md index b04778a..91d2879 100644 --- a/test.js.md +++ b/test.js.md @@ -4,6 +4,12 @@ The actual snapshot is saved in `test.js.snap`. Generated by [AVA](https://ava.li). +## exclude fallback if disabled + +> Snapshot 1 + + 'My Website' + ## render > Snapshot 1 @@ -14,4 +20,10 @@ Generated by [AVA](https://ava.li). > Snapshot 1 - 'My Website (https://sindresorhus.com)' + 'My Website (​https://sindresorhus.com​)' + +## include fallback if explicitly enabled + +> Snapshot 1 + + 'My Website (​https://sindresorhus.com​)' diff --git a/test.js.snap b/test.js.snap index 35dd4361f681a91b8e7da0123682f583448bc159..7dc4752d70b5c8f23bab4bf90aae9eabde9f204e 100644 GIT binary patch delta 204 zcmV;-05kuz0qp@YK~_N^Q*L2!b7*gLAa*he0sw;}SoQ8FMK`z{6BC-ihddvP2mk;8 z00003%VS_*U}2FmD}N8fe6u3W?o9mV{ov@jE3V7FhcSXhrvtHfz*k>|(4?a8cct#V z51!M)2o}8n#LNurV3QeH83Y+Eq+>0ttusnW3W}}t^@}s}Qi@WG^NTV{i}jN8bJ=|> z6{Mq$jdH_NlZrD-Qh{vCT(Ayy6jQW;>Yz##G#)i{<1!B@r4fmukqe=bYy$z&esR7& G0RR9ZVONF# delta 146 zcmV;D0B!&60ki=!K~_N^Q*L2!b7*gLAa*he0sz}E?(20I5a_P0($U67x#6iv#hE3kK(=KrSO+_bDXKtqP$dc)xD3+-03DQBShD~C00>_^ AoB#j-