Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

markdown-link-check

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-link-check - npm Package Compare versions

Comparing version 3.3.1 to 3.4.0

CHANGELOG.md

16

index.js

@@ -28,2 +28,18 @@ 'use strict';

async.mapLimit(linksCollection, 2, function (link, callback) {
// Make sure it is not undefined and that the appropriate headers are always recalculated for a given link.
opts.headers = {};
if (opts.httpHeaders) {
for (let httpHeader of opts.httpHeaders) {
for (let url of httpHeader.urls) {
if (link.startsWith(url)) {
Object.assign(opts.headers, httpHeader.headers);
// The headers of this httpHeader has been applied, the other URLs of this httpHeader don't need to be evaluated any further.
break;
}
}
}
}
linkCheck(link, opts, function (err, result) {

@@ -30,0 +46,0 @@ if (opts.showProgressBar) {

4

package.json
{
"name": "markdown-link-check",
"version": "3.3.1",
"version": "3.4.0",
"description": "checks the all of the hyperlinks in a markdown text to determine if they are alive or dead",

@@ -36,3 +36,3 @@ "bin": {

"commander": "^2.15.1",
"link-check": "^4.3.4",
"link-check": "^4.4.0",
"markdown-link-extractor": "^1.1.1",

@@ -39,0 +39,0 @@ "request": "^2.85.0",

@@ -43,2 +43,3 @@ # markdown-link-check

* `showProgressBar` enable an ASCII progress bar.
* `httpHeaders` to apply URL specific headers, see example below.
* `callback` function which accepts `(err, results)`.

@@ -56,2 +57,4 @@ * `err` an Error object when the operation cannot be completed, otherwise `null`.

**Basic usage:**
```js

@@ -73,2 +76,20 @@ 'use strict';

**With options, for example using URL specific headers:**
```js
'use strict';
var markdownLinkCheck = require('markdown-link-check');
markdownLinkCheck('[example](http://example.com)', { httpHeaders: [{ urls: ['http://example.com'], headers: { 'Authorization': 'Basic Zm9vOmJhcg==' }}] }, function (err, results) {
if (err) {
console.error('Error', err);
return;
}
results.forEach(function (result) {
console.log('%s is %s', result.link, result.status);
});
});
```
### Command Line Tool

@@ -94,3 +115,3 @@

cat *.md | markdown-link-check
#### Usage

@@ -104,7 +125,28 @@

-h, --help output usage information
-p, --progress show progress bar
-h, --help output usage information
-p, --progress show progress bar
-c, --config [config] apply a config file (JSON), holding e.g. URL specific header configuration
```
##### Config file format
`config.json`:
{
"httpHeaders": [
{
"urls": [
"https://example.com"
],
"headers": {
"Authorization": "Basic Zm9vOmJhcg==",
"Foo": "Bar"
}
}
]
}
`httpHeaders`: The headers are only applied to links where the link **starts with** one of the supplied URLs in the `urls` section.
## Testing

@@ -111,0 +153,0 @@

@@ -31,2 +31,11 @@ 'use strict';

app.get('/basic-auth', function (req, res) {
if (req.headers["authorization"] === "Basic Zm9vOmJhcg==") {
res.sendStatus(200);
}
else {
res.sendStatus(401);
}
});
app.get('/loop', function (req, res) {

@@ -55,3 +64,3 @@ res.redirect('/loop');

it('should check the links in sample.md', function (done) {
markdownLinkCheck(fs.readFileSync(path.join(__dirname, 'sample.md')).toString().replace(/%%BASE_URL%%/g, baseUrl), { baseUrl: baseUrl }, function (err, results) {
markdownLinkCheck(fs.readFileSync(path.join(__dirname, 'sample.md')).toString().replace(/%%BASE_URL%%/g, baseUrl), { baseUrl: baseUrl, httpHeaders: [{ urls: [baseUrl + '/basic-auth'], headers: { 'Authorization': 'Basic Zm9vOmJhcg==', 'Foo': 'Bar' }}] }, function (err, results) {
expect(err).to.be(null);

@@ -61,11 +70,33 @@ expect(results).to.be.an('array');

var expected = [
// redirect-loop
{ statusCode: 0, status: 'dead' },
// valid
{ statusCode: 200, status: 'alive' },
// invalid
{ statusCode: 404, status: 'dead' },
// dns-resolution-fail
{ statusCode: 0, status: 'dead' },
// nohead-get-ok
{ statusCode: 200, status: 'alive' },
// redirect
{ statusCode: 200, status: 'alive' },
// basic-auth
{ statusCode: 200, status: 'alive' },
// hello image
{ statusCode: 200, status: 'alive' },
// hello image
{ statusCode: 200, status: 'alive' },
// valid e-mail
{ statusCode: 200, status: 'alive' },
// invalid e-mail
{ statusCode: 400, status: 'dead' },

@@ -72,0 +103,0 @@ ];

@@ -11,2 +11,3 @@ # Sample

* [redirect](%%BASE_URL%%/foo/redirect) (alive)
* [basic-auth](%%BASE_URL%%/basic-auth) (alive)

@@ -19,2 +20,2 @@ ![img](%%BASE_URL%%/hello.jpg) (alive)

* [valid](mailto:linuxgeek@gmail.com)
* [invalid](mailto:foo@bar@baz)
* [invalid](mailto:foo@bar@baz)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc