Skip to content

Commit

Permalink
Merge branch 'ViliusSutkus89-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Jul 4, 2021
2 parents d64be74 + 4db24e1 commit fa5066b
Show file tree
Hide file tree
Showing 12 changed files with 12,608 additions and 17 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
# Enable version updates for npm
- package-ecosystem: 'npm'
# Look for `package.json` and `lock` files in the `root` directory
directory: '/'
# Check the npm registry for updates every day (weekdays)
schedule:
interval: 'daily'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.nyc_output
1 change: 1 addition & 0 deletions .nyc_output/e52ac2a5-3f91-4875-b5c4-9374767e56a9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions .nyc_output/eba98676-c323-4487-a821-e76cd44f38dd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"/Users/julian/dev/juliangruber/parse-apache-directory-index/index.js":{"path":"/Users/julian/dev/juliangruber/parse-apache-directory-index/index.js","statementMap":{"0":{"start":{"line":1,"column":16},"end":{"line":1,"column":34}},"1":{"start":{"line":2,"column":13},"end":{"line":2,"column":39}},"2":{"start":{"line":4,"column":14},"end":{"line":13,"column":1}},"3":{"start":{"line":5,"column":12},"end":{"line":5,"column":49}},"4":{"start":{"line":6,"column":2},"end":{"line":6,"column":22}},"5":{"start":{"line":6,"column":10},"end":{"line":6,"column":22}},"6":{"start":{"line":7,"column":14},"end":{"line":7,"column":26}},"7":{"start":{"line":8,"column":14},"end":{"line":8,"column":18}},"8":{"start":{"line":9,"column":2},"end":{"line":12,"column":10}},"9":{"start":{"line":15,"column":0},"end":{"line":67,"column":2}},"10":{"start":{"line":16,"column":12},"end":{"line":16,"column":29}},"11":{"start":{"line":17,"column":14},"end":{"line":17,"column":64}},"12":{"start":{"line":18,"column":16},"end":{"line":18,"column":18}},"13":{"start":{"line":20,"column":15},"end":{"line":20,"column":46}},"14":{"start":{"line":25,"column":20},"end":{"line":32,"column":9}},"15":{"start":{"line":29,"column":8},"end":{"line":31,"column":10}},"16":{"start":{"line":35,"column":2},"end":{"line":37,"column":3}},"17":{"start":{"line":36,"column":4},"end":{"line":36,"column":89}},"18":{"start":{"line":40,"column":2},"end":{"line":64,"column":7}},"19":{"start":{"line":44,"column":19},"end":{"line":44,"column":35}},"20":{"start":{"line":45,"column":21},"end":{"line":45,"column":95}},"21":{"start":{"line":45,"column":30},"end":{"line":45,"column":95}},"22":{"start":{"line":46,"column":25},"end":{"line":46,"column":78}},"23":{"start":{"line":46,"column":34},"end":{"line":46,"column":78}},"24":{"start":{"line":48,"column":19},"end":{"line":48,"column":63}},"25":{"start":{"line":49,"column":19},"end":{"line":49,"column":37}},"26":{"start":{"line":52,"column":6},"end":{"line":52,"column":55}},"27":{"start":{"line":52,"column":48},"end":{"line":52,"column":55}},"28":{"start":{"line":54,"column":6},"end":{"line":63,"column":9}},"29":{"start":{"line":66,"column":2},"end":{"line":66,"column":24}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":4,"column":14},"end":{"line":4,"column":15}},"loc":{"start":{"line":4,"column":23},"end":{"line":13,"column":1}},"line":4},"1":{"name":"(anonymous_1)","decl":{"start":{"line":15,"column":17},"end":{"line":15,"column":18}},"loc":{"start":{"line":15,"column":24},"end":{"line":67,"column":1}},"line":15},"2":{"name":"(anonymous_2)","decl":{"start":{"line":28,"column":12},"end":{"line":28,"column":13}},"loc":{"start":{"line":29,"column":8},"end":{"line":31,"column":10}},"line":29},"3":{"name":"(anonymous_3)","decl":{"start":{"line":43,"column":13},"end":{"line":43,"column":14}},"loc":{"start":{"line":43,"column":21},"end":{"line":64,"column":5}},"line":43},"4":{"name":"(anonymous_4)","decl":{"start":{"line":45,"column":21},"end":{"line":45,"column":22}},"loc":{"start":{"line":45,"column":30},"end":{"line":45,"column":95}},"line":45},"5":{"name":"(anonymous_5)","decl":{"start":{"line":46,"column":25},"end":{"line":46,"column":26}},"loc":{"start":{"line":46,"column":34},"end":{"line":46,"column":78}},"line":46}},"branchMap":{"0":{"loc":{"start":{"line":6,"column":2},"end":{"line":6,"column":22}},"type":"if","locations":[{"start":{"line":6,"column":2},"end":{"line":6,"column":22}},{"start":{"line":6,"column":2},"end":{"line":6,"column":22}}],"line":6},"1":{"loc":{"start":{"line":9,"column":9},"end":{"line":12,"column":9}},"type":"cond-expr","locations":[{"start":{"line":9,"column":23},"end":{"line":9,"column":33}},{"start":{"line":10,"column":6},"end":{"line":12,"column":9}}],"line":9},"2":{"loc":{"start":{"line":10,"column":6},"end":{"line":12,"column":9}},"type":"cond-expr","locations":[{"start":{"line":10,"column":20},"end":{"line":10,"column":37}},{"start":{"line":11,"column":6},"end":{"line":12,"column":9}}],"line":10},"3":{"loc":{"start":{"line":11,"column":6},"end":{"line":12,"column":9}},"type":"cond-expr","locations":[{"start":{"line":11,"column":20},"end":{"line":11,"column":44}},{"start":{"line":12,"column":6},"end":{"line":12,"column":9}}],"line":11},"4":{"loc":{"start":{"line":35,"column":2},"end":{"line":37,"column":3}},"type":"if","locations":[{"start":{"line":35,"column":2},"end":{"line":37,"column":3}},{"start":{"line":35,"column":2},"end":{"line":37,"column":3}}],"line":35},"5":{"loc":{"start":{"line":45,"column":30},"end":{"line":45,"column":95}},"type":"cond-expr","locations":[{"start":{"line":45,"column":63},"end":{"line":45,"column":67}},{"start":{"line":45,"column":70},"end":{"line":45,"column":95}}],"line":45},"6":{"loc":{"start":{"line":46,"column":34},"end":{"line":46,"column":78}},"type":"binary-expr","locations":[{"start":{"line":46,"column":34},"end":{"line":46,"column":47}},{"start":{"line":46,"column":51},"end":{"line":46,"column":78}}],"line":46},"7":{"loc":{"start":{"line":52,"column":6},"end":{"line":52,"column":55}},"type":"if","locations":[{"start":{"line":52,"column":6},"end":{"line":52,"column":55}},{"start":{"line":52,"column":6},"end":{"line":52,"column":55}}],"line":52},"8":{"loc":{"start":{"line":52,"column":10},"end":{"line":52,"column":46}},"type":"binary-expr","locations":[{"start":{"line":52,"column":10},"end":{"line":52,"column":37}},{"start":{"line":52,"column":41},"end":{"line":52,"column":46}}],"line":52},"9":{"loc":{"start":{"line":55,"column":14},"end":{"line":57,"column":18}},"type":"cond-expr","locations":[{"start":{"line":56,"column":12},"end":{"line":56,"column":23}},{"start":{"line":57,"column":12},"end":{"line":57,"column":18}}],"line":55},"10":{"loc":{"start":{"line":60,"column":22},"end":{"line":60,"column":86}},"type":"binary-expr","locations":[{"start":{"line":60,"column":22},"end":{"line":60,"column":45}},{"start":{"line":60,"column":49},"end":{"line":60,"column":86}}],"line":60},"11":{"loc":{"start":{"line":61,"column":14},"end":{"line":61,"column":57}},"type":"binary-expr","locations":[{"start":{"line":61,"column":14},"end":{"line":61,"column":28}},{"start":{"line":61,"column":32},"end":{"line":61,"column":57}}],"line":61}},"s":{"0":1,"1":1,"2":1,"3":12,"4":12,"5":4,"6":8,"7":8,"8":8,"9":1,"10":3,"11":3,"12":3,"13":3,"14":3,"15":13,"16":3,"17":0,"18":3,"19":19,"20":19,"21":149,"22":19,"23":55,"24":19,"25":19,"26":19,"27":7,"28":12,"29":3},"f":{"0":12,"1":3,"2":13,"3":19,"4":149,"5":55},"b":{"0":[4,8],"1":[6,2],"2":[2,0],"3":[0,0],"4":[0,3],"5":[4,145],"6":[55,51],"7":[7,12],"8":[19,16],"9":[6,6],"10":[12,12],"11":[12,12]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"c0946c06f534cb6ada70fa26f761254f4c665035","contentHash":"68f8a86d507ae8d53d54214bd6114f6612a10b84bba348d42d54c937bfda0a9c"}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parent":null,"pid":61780,"argv":["/Users/julian/.nvm/versions/node/v15.9.0/bin/node","/Users/julian/dev/juliangruber/parse-apache-directory-index/node_modules/.bin/tap","--no-check-coverage","test/index.js"],"execArgv":[],"cwd":"/Users/julian/dev/juliangruber/parse-apache-directory-index","time":1625389670641,"ppid":61779,"coverageFilename":"/Users/julian/dev/juliangruber/parse-apache-directory-index/.nyc_output/e52ac2a5-3f91-4875-b5c4-9374767e56a9.json","externalId":"","uuid":"e52ac2a5-3f91-4875-b5c4-9374767e56a9","files":[]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parent":"e52ac2a5-3f91-4875-b5c4-9374767e56a9","pid":61781,"argv":["/Users/julian/.nvm/versions/node/v15.9.0/bin/node","/Users/julian/dev/juliangruber/parse-apache-directory-index/test/index.js"],"execArgv":[],"cwd":"/Users/julian/dev/juliangruber/parse-apache-directory-index","time":1625389671284,"ppid":61780,"coverageFilename":"/Users/julian/dev/juliangruber/parse-apache-directory-index/.nyc_output/eba98676-c323-4487-a821-e76cd44f38dd.json","externalId":"test/index.js","uuid":"eba98676-c323-4487-a821-e76cd44f38dd","files":["/Users/julian/dev/juliangruber/parse-apache-directory-index/index.js"]}
1 change: 1 addition & 0 deletions .nyc_output/processinfo/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"processes":{"e52ac2a5-3f91-4875-b5c4-9374767e56a9":{"parent":null,"children":["eba98676-c323-4487-a821-e76cd44f38dd"]},"eba98676-c323-4487-a821-e76cd44f38dd":{"parent":"e52ac2a5-3f91-4875-b5c4-9374767e56a9","externalId":"test/index.js","children":[]}},"files":{"/Users/julian/dev/juliangruber/parse-apache-directory-index/index.js":["eba98676-c323-4487-a821-e76cd44f38dd"]},"externalIds":{"test/index.js":{"root":"eba98676-c323-4487-a821-e76cd44f38dd","children":[]}}}
24 changes: 13 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ const bytes = (str) => {
if (!m) return null;
const num = Number(m[1]);
const suf = m[2];
return suf === 'K' ? num * 1024
: suf === 'M' ? num * 1024 * 1024
: suf === 'G' ? num * 1024 * 1024 * 1024
: num;
return suf === 'K'
? num * 1024
: suf === 'M'
? num * 1024 * 1024
: suf === 'G'
? num * 1024 * 1024 * 1024
: num;
};

module.exports = src => {
const $ = cheerio.load(src);
const dir = '/' + $('h1').text().split('/').slice(1).join('/');
const files = [];

const rows = $('table').children('tr').toArray();
const rows = $('table').find('tr').toArray();

// Figure out the order of the columns,
// by looking at the header row.
Expand All @@ -26,13 +29,13 @@ module.exports = src => {
.children('th')
.toArray()
.reduce((fieldCols, th, i) =>
Object.assign(fieldCols, {
[$(th).text().trim()]: i
}),
{});
Object.assign(fieldCols, {
[$(th).text().trim()]: i
}),
{});

// Make sure we at least found a "Name" column
if (fieldCols['Name'] === undefined) {
if (fieldCols.Name === undefined) {
throw new Error('Unable to parse apache index html: cannot identify "Name" column.');
}

Expand Down Expand Up @@ -65,4 +68,3 @@ module.exports = src => {

return { dir, files };
};

Loading

0 comments on commit fa5066b

Please sign in to comment.