Skip to content

Commit

Permalink
Simplify string detection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tidoust committed Jan 21, 2020
1 parent b0e105c commit 6f77ab1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"use strict";

const isString = obj =>
Object.prototype.toString.call(obj) === "[object String]";

const specs = require("./specs.json")
.map(spec => isString(spec) ? { url: spec } : spec);
.map(spec => (typeof spec === "string") ? { url: spec } : spec);

module.exports = { specs };
5 changes: 1 addition & 4 deletions lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

const fs = require("fs").promises;

const isString = obj =>
Object.prototype.toString.call(obj) === "[object String]";

// Lint by normalizing specs.json and comparing it to the original,
// fixing it in place if |fix| is true.
async function lint(fix = false) {
const specsBuffer = await fs.readFile("./specs.json");
const specs = JSON.parse(specsBuffer);

const sorted = specs
.map(spec => isString(spec) ? { url: spec } : spec)
.map(spec => (typeof spec === "string") ? { url: spec } : spec)
.map(spec => Object.assign({}, spec, { url: new URL(spec.url).toString() }));
sorted.sort((a, b) => a.url.localeCompare(b.url));

Expand Down

0 comments on commit 6f77ab1

Please sign in to comment.