Skip to content

Commit fcf64c1

Browse files
Replaced all format strings with ES6 template literals
1 parent 2fdbda4 commit fcf64c1

8 files changed

Lines changed: 28 additions & 28 deletions

File tree

lib/dereference.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const $Ref = require("./ref");
44
const Pointer = require("./pointer");
5-
const ono = require("ono");
5+
const { ono } = require("ono");
66
const url = require("./util/url");
77

88
module.exports = dereference;
@@ -143,7 +143,7 @@ function dereference$Ref ($ref, path, pathFromRoot, parents, $refs, options) {
143143
function foundCircularReference (keyPath, $refs, options) {
144144
$refs.circular = true;
145145
if (!options.dereference.circular) {
146-
throw ono.reference("Circular $ref pointer found at %s", keyPath);
146+
throw ono.reference(`Circular $ref pointer found at ${keyPath}`);
147147
}
148148
return true;
149149
}

lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const bundle = require("./bundle");
99
const dereference = require("./dereference");
1010
const url = require("./util/url");
1111
const maybe = require("call-me-maybe");
12-
const ono = require("ono");
12+
const { ono } = require("ono");
1313

1414
module.exports = $RefParser;
1515
module.exports.YAML = require("./util/yaml");
@@ -71,7 +71,7 @@ $RefParser.prototype.parse = function (path, schema, options, callback) {
7171
let promise;
7272

7373
if (!args.path && !args.schema) {
74-
let err = ono("Expected a file path, URL, or object. Got %s", args.path || args.schema);
74+
let err = ono(`Expected a file path, URL, or object. Got ${args.path || args.schema}`);
7575
return maybe(args.callback, Promise.reject(err));
7676
}
7777

@@ -111,7 +111,7 @@ $RefParser.prototype.parse = function (path, schema, options, callback) {
111111
return promise
112112
.then((result) => {
113113
if (!result || typeof result !== "object" || Buffer.isBuffer(result)) {
114-
throw ono.syntax('"%s" is not a valid JSON Schema', me.$refs._root$Ref.path || result);
114+
throw ono.syntax(`"${me.$refs._root$Ref.path || result}" is not a valid JSON Schema`);
115115
}
116116
else {
117117
me.schema = result;

lib/parse.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const ono = require("ono");
3+
const { ono } = require("ono");
44
const url = require("./util/url");
55
const plugins = require("./util/plugins");
66

@@ -79,7 +79,7 @@ function readFile (file, options) {
7979
reject(err);
8080
}
8181
else {
82-
reject(ono.syntax('Unable to resolve $ref pointer "%s"', file.url));
82+
reject(ono.syntax(`Unable to resolve $ref pointer "${file.url}"`));
8383
}
8484
}
8585
}));
@@ -115,7 +115,7 @@ function parseFile (file, options) {
115115

116116
function onParsed (parser) {
117117
if (!parser.plugin.allowEmpty && isEmpty(parser.result)) {
118-
reject(ono.syntax('Error parsing "%s" as %s. \nParsed value is empty', file.url, parser.plugin.name));
118+
reject(ono.syntax(`Error parsing "${file.url}" as ${parser.plugin.name}. \nParsed value is empty`));
119119
}
120120
else {
121121
resolve(parser);
@@ -125,10 +125,10 @@ function parseFile (file, options) {
125125
function onError (err) {
126126
if (err) {
127127
err = err instanceof Error ? err : new Error(err);
128-
reject(ono.syntax(err, "Error parsing %s", file.url));
128+
reject(ono.syntax(err, `Error parsing ${file.url}`));
129129
}
130130
else {
131-
reject(ono.syntax("Unable to parse %s", file.url));
131+
reject(ono.syntax(`Unable to parse ${file.url}`));
132132
}
133133
}
134134
}));

lib/pointer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = Pointer;
44

55
const $Ref = require("./ref");
66
const url = require("./util/url");
7-
const ono = require("ono");
7+
const { ono } = require("ono");
88
const slashes = /\//g;
99
const tildes = /~/g;
1010
const escapedSlash = /~1/g;
@@ -84,7 +84,7 @@ Pointer.prototype.resolve = function (obj, options) {
8484

8585
let token = tokens[i];
8686
if (this.value[token] === undefined) {
87-
throw ono.syntax('Error resolving $ref pointer "%s". \nToken "%s" does not exist.', this.originalPath, token);
87+
throw ono.syntax(`Error resolving $ref pointer "${this.originalPath}". \nToken "${token}" does not exist.`);
8888
}
8989
else {
9090
this.value = this.value[token];
@@ -171,7 +171,7 @@ Pointer.parse = function (path) {
171171
}
172172

173173
if (pointer[0] !== "") {
174-
throw ono.syntax('Invalid $ref pointer "%s". Pointers must begin with "#/"', pointer);
174+
throw ono.syntax(`Invalid $ref pointer "${pointer}". Pointers must begin with "#/"`);
175175
}
176176

177177
return pointer.slice(1);
@@ -264,7 +264,7 @@ function setValue (pointer, token, value) {
264264
}
265265
}
266266
else {
267-
throw ono.syntax('Error assigning $ref pointer "%s". \nCannot set "%s" of a non-object.', pointer.path, token);
267+
throw ono.syntax(`Error assigning $ref pointer "${pointer.path}". \nCannot set "${token}" of a non-object.`);
268268
}
269269
return value;
270270
}

lib/refs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const ono = require("ono");
3+
const { ono } = require("ono");
44
const $Ref = require("./ref");
55
const url = require("./util/url");
66

@@ -111,7 +111,7 @@ $Refs.prototype.set = function (path, value) {
111111
let $ref = this._$refs[withoutHash];
112112

113113
if (!$ref) {
114-
throw ono('Error resolving $ref pointer "%s". \n"%s" not found.', path, withoutHash);
114+
throw ono(`Error resolving $ref pointer "${path}". \n"${withoutHash}" not found.`);
115115
}
116116

117117
$ref.set(absPath, value);
@@ -149,7 +149,7 @@ $Refs.prototype._resolve = function (path, options) {
149149
let $ref = this._$refs[withoutHash];
150150

151151
if (!$ref) {
152-
throw ono('Error resolving $ref pointer "%s". \n"%s" not found.', path, withoutHash);
152+
throw ono(`Error resolving $ref pointer "${path}". \n"${withoutHash}" not found.`);
153153
}
154154

155155
return $ref.resolve(absPath, options, path);

lib/resolvers/file.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
const fs = require("fs");
3-
const ono = require("ono");
3+
const { ono } = require("ono");
44
const url = require("../util/url");
55

66
module.exports = {
@@ -40,23 +40,23 @@ module.exports = {
4040
path = url.toFileSystemPath(file.url);
4141
}
4242
catch (err) {
43-
reject(ono.uri(err, "Malformed URI: %s", file.url));
43+
reject(ono.uri(err, `Malformed URI: ${file.url}`));
4444
}
4545

4646
// console.log('Opening file: %s', path);
4747

4848
try {
4949
fs.readFile(path, (err, data) => {
5050
if (err) {
51-
reject(ono(err, 'Error opening file "%s"', path));
51+
reject(ono(err, `Error opening file "${path}"`));
5252
}
5353
else {
5454
resolve(data);
5555
}
5656
});
5757
}
5858
catch (err) {
59-
reject(ono(err, 'Error opening file "%s"', path));
59+
reject(ono(err, `Error opening file "${path}"`));
6060
}
6161
}));
6262
}

lib/resolvers/http.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const http = require("http");
44
const https = require("https");
5-
const ono = require("ono");
5+
const { ono } = require("ono");
66
const url = require("../util/url");
77

88
module.exports = {
@@ -102,15 +102,15 @@ function download (u, httpOptions, redirects) {
102102
get(u, httpOptions)
103103
.then((res) => {
104104
if (res.statusCode >= 400) {
105-
throw ono({ status: res.statusCode }, "HTTP ERROR %d", res.statusCode);
105+
throw ono({ status: res.statusCode }, `HTTP ERROR ${res.statusCode}`);
106106
}
107107
else if (res.statusCode >= 300) {
108108
if (redirects.length > httpOptions.redirects) {
109-
reject(ono({ status: res.statusCode }, "Error downloading %s. \nToo many redirects: \n %s",
110-
redirects[0], redirects.join(" \n ")));
109+
reject(ono({ status: res.statusCode },
110+
`Error downloading ${redirects[0]}. \nToo many redirects: \n ${redirects.join(" \n ")}`));
111111
}
112112
else if (!res.headers.location) {
113-
throw ono({ status: res.statusCode }, "HTTP %d redirect with no location header", res.statusCode);
113+
throw ono({ status: res.statusCode }, `HTTP ${res.statusCode} redirect with no location header`);
114114
}
115115
else {
116116
// console.log('HTTP %d redirect %s -> %s', res.statusCode, u.href, res.headers.location);
@@ -123,7 +123,7 @@ function download (u, httpOptions, redirects) {
123123
}
124124
})
125125
.catch((err) => {
126-
reject(ono(err, "Error downloading", u.href));
126+
reject(ono(err, `Error downloading ${u.href}`));
127127
});
128128
}));
129129
}

lib/util/yaml.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"use strict";
33

44
const yaml = require("js-yaml");
5-
const ono = require("ono");
5+
const { ono } = require("ono");
66

77
/**
88
* Simple YAML parsing functions, similar to {@link JSON.parse} and {@link JSON.stringify}

0 commit comments

Comments
 (0)