diff --git a/.eslintrc.yml b/.eslintrc.yml index c11ebb19..41066667 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -4,6 +4,8 @@ root: true extends: "@jsdevtools" +parserOptions: + sourceType: module env: node: true browser: true diff --git a/karma.conf.js b/karma.conf.js index 0f9b7050..f224911a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -2,8 +2,6 @@ // https://karma-runner.github.io/0.12/config/configuration-file.html // https://jstools.dev/karma-config/ -"use strict"; - const { karmaConfig } = require("@jsdevtools/karma-config"); const { host } = require("@jsdevtools/host-environment"); diff --git a/lib/bundle.js b/lib/bundle.js index d5578bf1..c4a21444 100644 --- a/lib/bundle.js +++ b/lib/bundle.js @@ -1,10 +1,8 @@ -"use strict"; +import $Ref from "./ref"; +import Pointer from "./pointer"; +import url from "./util/url"; -const $Ref = require("./ref"); -const Pointer = require("./pointer"); -const url = require("./util/url"); - -module.exports = bundle; +export default bundle; /** * Bundles all external JSON references into the main JSON schema, thus resulting in a schema that diff --git a/lib/dereference.js b/lib/dereference.js index f6b2b203..7d11abc9 100644 --- a/lib/dereference.js +++ b/lib/dereference.js @@ -1,11 +1,10 @@ -"use strict"; +import $Ref from "./ref"; +import Pointer from "./pointer"; +import { ono } from "@jsdevtools/ono"; -const $Ref = require("./ref"); -const Pointer = require("./pointer"); -const { ono } = require("@jsdevtools/ono"); -const url = require("./util/url"); +import url from "./util/url"; -module.exports = dereference; +export default dereference; /** * Crawls the JSON schema, finds all JSON references, and dereferences them. diff --git a/lib/index.d.ts b/lib/index.d.ts index 547f27fe..db696195 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type, JSONSchema7, JSONSchema7Type } from "json-schema"; export = $RefParser; diff --git a/lib/index.js b/lib/index.js index fb5d5f32..ddc26194 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,26 +1,34 @@ /* eslint-disable no-unused-vars */ -"use strict"; +import $Refs from "./refs"; +import _parse from "./parse"; +import normalizeArgs from "./normalize-args"; +import resolveExternal from "./resolve-external"; +import _bundle from "./bundle"; +import _dereference from "./dereference"; +import url from "./util/url"; +import { + InvalidPointerError, + isHandledError, + JSONParserError, + JSONParserErrorGroup, + MissingPointerError, + ParserError, + ResolverError, + UnmatchedParserError, + UnmatchedResolverError +} from "./util/errors"; -const $Refs = require("./refs"); -const _parse = require("./parse"); -const normalizeArgs = require("./normalize-args"); -const resolveExternal = require("./resolve-external"); -const _bundle = require("./bundle"); -const _dereference = require("./dereference"); -const url = require("./util/url"); -const { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError, JSONParserErrorGroup } = require("./util/errors"); -const maybe = require("call-me-maybe"); -const { ono } = require("@jsdevtools/ono"); +import maybe from "call-me-maybe"; +import { ono } from "@jsdevtools/ono"; -module.exports = $RefParser; -module.exports.default = $RefParser; -module.exports.JSONParserError = JSONParserError; -module.exports.InvalidPointerError = InvalidPointerError; -module.exports.MissingPointerError = MissingPointerError; -module.exports.ResolverError = ResolverError; -module.exports.ParserError = ParserError; -module.exports.UnmatchedParserError = UnmatchedParserError; -module.exports.UnmatchedResolverError = UnmatchedResolverError; +export default $RefParser; +export { JSONParserError }; +export { InvalidPointerError }; +export { MissingPointerError }; +export { ResolverError }; +export { ParserError }; +export { UnmatchedParserError }; +export { UnmatchedResolverError }; /** * This class parses a JSON schema, builds a map of its JSON references and their resolved values, diff --git a/lib/normalize-args.js b/lib/normalize-args.js index 1d48fe4d..1fafcdbb 100644 --- a/lib/normalize-args.js +++ b/lib/normalize-args.js @@ -1,8 +1,6 @@ -"use strict"; +import Options from "./options"; -const Options = require("./options"); - -module.exports = normalizeArgs; +export default normalizeArgs; /** * Normalizes the given arguments, accounting for optional args. diff --git a/lib/options.js b/lib/options.js index 199362a6..a3c8dada 100644 --- a/lib/options.js +++ b/lib/options.js @@ -1,14 +1,11 @@ -/* eslint lines-around-comment: [2, {beforeBlockComment: false}] */ -"use strict"; +import jsonParser from "./parsers/json"; +import yamlParser from "./parsers/yaml"; +import textParser from "./parsers/text"; +import binaryParser from "./parsers/binary"; +import fileResolver from "./resolvers/file"; +import httpResolver from "./resolvers/http"; -const jsonParser = require("./parsers/json"); -const yamlParser = require("./parsers/yaml"); -const textParser = require("./parsers/text"); -const binaryParser = require("./parsers/binary"); -const fileResolver = require("./resolvers/file"); -const httpResolver = require("./resolvers/http"); - -module.exports = $RefParserOptions; +export default $RefParserOptions; /** * Options that determine how JSON schemas are parsed, resolved, and dereferenced. diff --git a/lib/parse.js b/lib/parse.js index b9160df6..b997b5ef 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1,11 +1,10 @@ -"use strict"; +import { ono } from "@jsdevtools/ono"; -const { ono } = require("@jsdevtools/ono"); -const url = require("./util/url"); -const plugins = require("./util/plugins"); -const { ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError } = require("./util/errors"); +import url from "./util/url"; +import plugins from "./util/plugins"; +import { isHandledError, ParserError, ResolverError, UnmatchedParserError, UnmatchedResolverError } from "./util/errors"; -module.exports = parse; +export default parse; /** * Reads and parses the specified file path or URL. diff --git a/lib/parsers/binary.js b/lib/parsers/binary.js index be15073c..141fc3a8 100644 --- a/lib/parsers/binary.js +++ b/lib/parsers/binary.js @@ -1,8 +1,6 @@ -"use strict"; - let BINARY_REGEXP = /\.(jpeg|jpg|gif|png|bmp|ico)$/i; -module.exports = { +export default { /** * The order that this parser will run, in relation to other parsers. * diff --git a/lib/parsers/json.js b/lib/parsers/json.js index 34dd986f..0ed9b76f 100644 --- a/lib/parsers/json.js +++ b/lib/parsers/json.js @@ -1,8 +1,6 @@ -"use strict"; +import { ParserError } from "../util/errors"; -const { ParserError } = require("../util/errors"); - -module.exports = { +export default { /** * The order that this parser will run, in relation to other parsers. * diff --git a/lib/parsers/text.js b/lib/parsers/text.js index 03bcd96b..f235c97a 100644 --- a/lib/parsers/text.js +++ b/lib/parsers/text.js @@ -1,10 +1,8 @@ -"use strict"; - -const { ParserError } = require("../util/errors"); +import { ParserError } from "../util/errors"; let TEXT_REGEXP = /\.(txt|htm|html|md|xml|js|min|map|css|scss|less|svg)$/i; -module.exports = { +export default { /** * The order that this parser will run, in relation to other parsers. * diff --git a/lib/parsers/yaml.js b/lib/parsers/yaml.js index 94c4eca0..f2307a86 100644 --- a/lib/parsers/yaml.js +++ b/lib/parsers/yaml.js @@ -1,10 +1,8 @@ -"use strict"; +import { ParserError } from "../util/errors"; -const { ParserError } = require("../util/errors"); -const yaml = require("js-yaml"); -const { JSON_SCHEMA } = require("js-yaml"); +import yaml, { JSON_SCHEMA } from "js-yaml"; -module.exports = { +export default { /** * The order that this parser will run, in relation to other parsers. * diff --git a/lib/pointer.js b/lib/pointer.js index 299b2215..b8344ac7 100644 --- a/lib/pointer.js +++ b/lib/pointer.js @@ -1,10 +1,9 @@ -"use strict"; +import $Ref from "./ref"; +import url from "./util/url"; +import { InvalidPointerError, isHandledError, JSONParserError, MissingPointerError } from "./util/errors"; -module.exports = Pointer; +export default Pointer; -const $Ref = require("./ref"); -const url = require("./util/url"); -const { JSONParserError, InvalidPointerError, MissingPointerError, isHandledError } = require("./util/errors"); const slashes = /\//g; const tildes = /~/g; const escapedSlash = /~1/g; diff --git a/lib/ref.js b/lib/ref.js index b6693795..b8d6fec0 100644 --- a/lib/ref.js +++ b/lib/ref.js @@ -1,10 +1,8 @@ -"use strict"; +import Pointer from "./pointer"; +import { InvalidPointerError, isHandledError, normalizeError } from "./util/errors"; +import url from "./util/url"; -module.exports = $Ref; - -const Pointer = require("./pointer"); -const { InvalidPointerError, isHandledError, normalizeError } = require("./util/errors"); -const { safePointerToPath, stripHash, getHash } = require("./util/url"); +export default $Ref; /** * This class represents a single JSON reference and its resolved value. @@ -129,13 +127,13 @@ $Ref.prototype.resolve = function (path, options, friendlyPath, pathFromRoot) { } if (err.path === null) { - err.path = safePointerToPath(getHash(pathFromRoot)); + err.path = url.safePointerToPath(url.getHash(pathFromRoot)); } if (err instanceof InvalidPointerError) { // this is a special case - InvalidPointerError is thrown when dereferencing external file, // but the issue is caused by the source file that referenced the file that undergoes dereferencing - err.source = decodeURI(stripHash(pathFromRoot)); + err.source = decodeURI(url.stripHash(pathFromRoot)); } this.addError(err); diff --git a/lib/refs.js b/lib/refs.js index b487eb78..1b56f62a 100644 --- a/lib/refs.js +++ b/lib/refs.js @@ -1,10 +1,9 @@ -"use strict"; +import { ono } from "@jsdevtools/ono"; -const { ono } = require("@jsdevtools/ono"); -const $Ref = require("./ref"); -const url = require("./util/url"); +import $Ref from "./ref"; +import url from "./util/url"; -module.exports = $Refs; +export default $Refs; /** * This class is a map of JSON references and their resolved values. diff --git a/lib/resolve-external.js b/lib/resolve-external.js index 9af29bb2..af192fda 100644 --- a/lib/resolve-external.js +++ b/lib/resolve-external.js @@ -1,12 +1,10 @@ -"use strict"; +import $Ref from "./ref"; +import Pointer from "./pointer"; +import parse from "./parse"; +import url from "./util/url"; +import { isHandledError } from "./util/errors"; -const $Ref = require("./ref"); -const Pointer = require("./pointer"); -const parse = require("./parse"); -const url = require("./util/url"); -const { isHandledError } = require("./util/errors"); - -module.exports = resolveExternal; +export default resolveExternal; /** * Crawls the JSON schema, finds all external JSON references, and resolves their values. diff --git a/lib/resolvers/file.js b/lib/resolvers/file.js index 45577ad7..8a38eb88 100644 --- a/lib/resolvers/file.js +++ b/lib/resolvers/file.js @@ -1,10 +1,10 @@ -"use strict"; -const fs = require("fs"); -const { ono } = require("@jsdevtools/ono"); -const url = require("../util/url"); -const { ResolverError } = require("../util/errors"); +import fs from "fs"; +import { ono } from "@jsdevtools/ono"; -module.exports = { +import url from "../util/url"; +import { ResolverError } from "../util/errors"; + +export default { /** * The order that this resolver will run, in relation to other resolvers. * diff --git a/lib/resolvers/http.js b/lib/resolvers/http.js index eaadd2de..43ca20df 100644 --- a/lib/resolvers/http.js +++ b/lib/resolvers/http.js @@ -1,12 +1,11 @@ -"use strict"; +import http from "http"; +import https from "https"; +import { ono } from "@jsdevtools/ono"; -const http = require("http"); -const https = require("https"); -const { ono } = require("@jsdevtools/ono"); -const url = require("../util/url"); -const { ResolverError } = require("../util/errors"); +import url from "../util/url"; +import { ResolverError } from "../util/errors"; -module.exports = { +export default { /** * The order that this resolver will run, in relation to other resolvers. * diff --git a/lib/util/errors.js b/lib/util/errors.js index 4cdb1c0a..3201f33a 100644 --- a/lib/util/errors.js +++ b/lib/util/errors.js @@ -1,10 +1,8 @@ -"use strict"; +import { Ono } from "@jsdevtools/ono"; -const { Ono } = require("@jsdevtools/ono"); +import url from "./url"; -const { stripHash, toFileSystemPath } = require("./url"); - -const JSONParserError = exports.JSONParserError = class JSONParserError extends Error { +export class JSONParserError extends Error { constructor (message, source) { super(); @@ -19,16 +17,16 @@ const JSONParserError = exports.JSONParserError = class JSONParserError extends get footprint () { return `${this.path}+${this.source}+${this.code}+${this.message}`; } -}; +} setErrorName(JSONParserError); -const JSONParserErrorGroup = exports.JSONParserErrorGroup = class JSONParserErrorGroup extends Error { +export class JSONParserErrorGroup extends Error { constructor (parser) { super(); this.files = parser; - this.message = `${this.errors.length} error${this.errors.length > 1 ? "s" : ""} occurred while reading '${toFileSystemPath(parser.$refs._root$Ref.path)}'`; + this.message = `${this.errors.length} error${this.errors.length > 1 ? "s" : ""} occurred while reading '${url.toFileSystemPath(parser.$refs._root$Ref.path)}'`; Ono.extend(this); } @@ -48,31 +46,31 @@ const JSONParserErrorGroup = exports.JSONParserErrorGroup = class JSONParserErro get errors () { return JSONParserErrorGroup.getParserErrors(this.files); } -}; +} setErrorName(JSONParserErrorGroup); -const ParserError = exports.ParserError = class ParserError extends JSONParserError { +export class ParserError extends JSONParserError { constructor (message, source) { super(`Error parsing ${source}: ${message}`, source); this.code = "EPARSER"; } -}; +} setErrorName(ParserError); -const UnmatchedParserError = exports.UnmatchedParserError = class UnmatchedParserError extends JSONParserError { +export class UnmatchedParserError extends JSONParserError { constructor (source) { super(`Could not find parser for "${source}"`, source); this.code = "EUNMATCHEDPARSER"; } -}; +} setErrorName(UnmatchedParserError); -const ResolverError = exports.ResolverError = class ResolverError extends JSONParserError { +export class ResolverError extends JSONParserError { constructor (ex, source) { super(ex.message || `Error reading file "${source}"`, source); @@ -82,37 +80,37 @@ const ResolverError = exports.ResolverError = class ResolverError extends JSONPa this.ioErrorCode = String(ex.code); } } -}; +} setErrorName(ResolverError); -const UnmatchedResolverError = exports.UnmatchedResolverError = class UnmatchedResolverError extends JSONParserError { +export class UnmatchedResolverError extends JSONParserError { constructor (source) { super(`Could not find resolver for "${source}"`, source); this.code = "EUNMATCHEDRESOLVER"; } -}; +} setErrorName(UnmatchedResolverError); -const MissingPointerError = exports.MissingPointerError = class MissingPointerError extends JSONParserError { +export class MissingPointerError extends JSONParserError { constructor (token, path) { - super(`Token "${token}" does not exist.`, stripHash(path)); + super(`Token "${token}" does not exist.`, url.stripHash(path)); this.code = "EMISSINGPOINTER"; } -}; +} setErrorName(MissingPointerError); -const InvalidPointerError = exports.InvalidPointerError = class InvalidPointerError extends JSONParserError { +export class InvalidPointerError extends JSONParserError { constructor (pointer, path) { - super(`Invalid $ref pointer "${pointer}". Pointers must begin with "#/"`, stripHash(path)); + super(`Invalid $ref pointer "${pointer}". Pointers must begin with "#/"`, url.stripHash(path)); this.code = "EINVALIDPOINTER"; } -}; +} setErrorName(InvalidPointerError); @@ -123,14 +121,14 @@ function setErrorName (err) { }); } -exports.isHandledError = function (err) { +export function isHandledError (err) { return err instanceof JSONParserError || err instanceof JSONParserErrorGroup; -}; +} -exports.normalizeError = function (err) { +export function normalizeError (err) { if (err.path === null) { err.path = []; } return err; -}; +} diff --git a/lib/util/plugins.js b/lib/util/plugins.js index 24d69349..69352b6f 100644 --- a/lib/util/plugins.js +++ b/lib/util/plugins.js @@ -1,126 +1,3 @@ -"use strict"; - -/** - * Returns the given plugins as an array, rather than an object map. - * All other methods in this module expect an array of plugins rather than an object map. - * - * @param {object} plugins - A map of plugin objects - * @return {object[]} - */ -exports.all = function (plugins) { - return Object.keys(plugins) - .filter((key) => { - return typeof plugins[key] === "object"; - }) - .map((key) => { - plugins[key].name = key; - return plugins[key]; - }); -}; - -/** - * Filters the given plugins, returning only the ones return `true` for the given method. - * - * @param {object[]} plugins - An array of plugin objects - * @param {string} method - The name of the filter method to invoke for each plugin - * @param {object} file - A file info object, which will be passed to each method - * @return {object[]} - */ -exports.filter = function (plugins, method, file) { - return plugins - .filter((plugin) => { - return !!getResult(plugin, method, file); - }); -}; - -/** - * Sorts the given plugins, in place, by their `order` property. - * - * @param {object[]} plugins - An array of plugin objects - * @returns {object[]} - */ -exports.sort = function (plugins) { - for (let plugin of plugins) { - plugin.order = plugin.order || Number.MAX_SAFE_INTEGER; - } - - return plugins.sort((a, b) => { return a.order - b.order; }); -}; - -/** - * Runs the specified method of the given plugins, in order, until one of them returns a successful result. - * Each method can return a synchronous value, a Promise, or call an error-first callback. - * If the promise resolves successfully, or the callback is called without an error, then the result - * is immediately returned and no further plugins are called. - * If the promise rejects, or the callback is called with an error, then the next plugin is called. - * If ALL plugins fail, then the last error is thrown. - * - * @param {object[]} plugins - An array of plugin objects - * @param {string} method - The name of the method to invoke for each plugin - * @param {object} file - A file info object, which will be passed to each method - * @returns {Promise} - */ -exports.run = function (plugins, method, file, $refs) { - let plugin, lastError, index = 0; - - return new Promise(((resolve, reject) => { - runNextPlugin(); - - function runNextPlugin () { - plugin = plugins[index++]; - if (!plugin) { - // There are no more functions, so re-throw the last error - return reject(lastError); - } - - try { - // console.log(' %s', plugin.name); - let result = getResult(plugin, method, file, callback, $refs); - if (result && typeof result.then === "function") { - // A promise was returned - result.then(onSuccess, onError); - } - else if (result !== undefined) { - // A synchronous result was returned - onSuccess(result); - } - else if (index === plugins.length) { - throw new Error("No promise has been returned or callback has been called."); - } - } - catch (e) { - onError(e); - } - } - - function callback (err, result) { - if (err) { - onError(err); - } - else { - onSuccess(result); - } - } - - function onSuccess (result) { - // console.log(' success'); - resolve({ - plugin, - result - }); - } - - function onError (error) { - // console.log(' %s', err.message || err); - lastError = { - plugin, - error, - }; - runNextPlugin(); - } - })); -}; - /** * Returns the value of the given property. * If the property is a function, then the result of the function is returned. @@ -157,3 +34,126 @@ function getResult (obj, prop, file, callback, $refs) { return value; } + +export default { + /** + * Returns the given plugins as an array, rather than an object map. + * All other methods in this module expect an array of plugins rather than an object map. + * + * @param {object} plugins - A map of plugin objects + * @return {object[]} + */ + all (plugins) { + return Object.keys(plugins) + .filter((key) => { + return typeof plugins[key] === "object"; + }) + .map((key) => { + plugins[key].name = key; + return plugins[key]; + }); + }, + + /** + * Filters the given plugins, returning only the ones return `true` for the given method. + * + * @param {object[]} plugins - An array of plugin objects + * @param {string} method - The name of the filter method to invoke for each plugin + * @param {object} file - A file info object, which will be passed to each method + * @return {object[]} + */ + filter (plugins, method, file) { + return plugins + .filter((plugin) => { + return !!getResult(plugin, method, file); + }); + }, + + /** + * Sorts the given plugins, in place, by their `order` property. + * + * @param {object[]} plugins - An array of plugin objects + * @returns {object[]} + */ + sort (plugins) { + for (let plugin of plugins) { + plugin.order = plugin.order || Number.MAX_SAFE_INTEGER; + } + + return plugins.sort((a, b) => { return a.order - b.order; }); + }, + + /** + * Runs the specified method of the given plugins, in order, until one of them returns a successful result. + * Each method can return a synchronous value, a Promise, or call an error-first callback. + * If the promise resolves successfully, or the callback is called without an error, then the result + * is immediately returned and no further plugins are called. + * If the promise rejects, or the callback is called with an error, then the next plugin is called. + * If ALL plugins fail, then the last error is thrown. + * + * @param {object[]} plugins - An array of plugin objects + * @param {string} method - The name of the method to invoke for each plugin + * @param {object} file - A file info object, which will be passed to each method + * @returns {Promise} + */ + run (plugins, method, file, $refs) { + let plugin, lastError, index = 0; + + return new Promise(((resolve, reject) => { + runNextPlugin(); + + function runNextPlugin () { + plugin = plugins[index++]; + if (!plugin) { + // There are no more functions, so re-throw the last error + return reject(lastError); + } + + try { + // console.log(' %s', plugin.name); + let result = getResult(plugin, method, file, callback, $refs); + if (result && typeof result.then === "function") { + // A promise was returned + result.then(onSuccess, onError); + } + else if (result !== undefined) { + // A synchronous result was returned + onSuccess(result); + } + else if (index === plugins.length) { + throw new Error("No promise has been returned or callback has been called."); + } + } + catch (e) { + onError(e); + } + } + + function callback (err, result) { + if (err) { + onError(err); + } + else { + onSuccess(result); + } + } + + function onSuccess (result) { + // console.log(' success'); + resolve({ + plugin, + result + }); + } + + function onError (error) { + // console.log(' %s', err.message || err); + lastError = { + plugin, + error, + }; + runNextPlugin(); + } + })); + }, +}; diff --git a/lib/util/url.js b/lib/util/url.js index 81b3a0d7..20e987f3 100644 --- a/lib/util/url.js +++ b/lib/util/url.js @@ -1,9 +1,8 @@ -"use strict"; +import { parse, resolve } from "url"; let isWindows = /^win/.test(process.platform), forwardSlashPattern = /\//g, protocolPattern = /^(\w{2,}):\/\//i, - url = module.exports, jsonPointerSlash = /~1/g, jsonPointerTilde = /~0/g; @@ -22,250 +21,253 @@ let urlDecodePatterns = [ /\%40/g, "@" ]; -exports.parse = require("url").parse; -exports.resolve = require("url").resolve; +export default { + /** + * Returns the current working directory (in Node) or the current page URL (in browsers). + * + * @returns {string} + */ + cwd () { + if (process.browser) { + return location.href; + } -/** - * Returns the current working directory (in Node) or the current page URL (in browsers). - * - * @returns {string} - */ -exports.cwd = function cwd () { - if (process.browser) { - return location.href; - } + let path = process.cwd(); - let path = process.cwd(); + let lastChar = path.slice(-1); + if (lastChar === "/" || lastChar === "\\") { + return path; + } + else { + return path + "/"; + } + }, - let lastChar = path.slice(-1); - if (lastChar === "/" || lastChar === "\\") { - return path; - } - else { - return path + "/"; - } -}; + /** + * Returns the protocol of the given URL, or `undefined` if it has no protocol. + * + * @param {string} path + * @returns {?string} + */ + getProtocol (path) { + let match = protocolPattern.exec(path); + if (match) { + return match[1].toLowerCase(); + } + }, -/** - * Returns the protocol of the given URL, or `undefined` if it has no protocol. - * - * @param {string} path - * @returns {?string} - */ -exports.getProtocol = function getProtocol (path) { - let match = protocolPattern.exec(path); - if (match) { - return match[1].toLowerCase(); - } -}; + /** + * Returns the lowercased file extension of the given URL, + * or an empty string if it has no extension. + * + * @param {string} path + * @returns {string} + */ + getExtension (path) { + let lastDot = path.lastIndexOf("."); + if (lastDot >= 0) { + return this.stripQuery(path.substr(lastDot).toLowerCase()); + } + return ""; + }, -/** - * Returns the lowercased file extension of the given URL, - * or an empty string if it has no extension. - * - * @param {string} path - * @returns {string} - */ -exports.getExtension = function getExtension (path) { - let lastDot = path.lastIndexOf("."); - if (lastDot >= 0) { - return url.stripQuery(path.substr(lastDot).toLowerCase()); - } - return ""; -}; + /** + * Removes the query, if any, from the given path. + * + * @param {string} path + * @returns {string} + */ + stripQuery (path) { + let queryIndex = path.indexOf("?"); + if (queryIndex >= 0) { + path = path.substr(0, queryIndex); + } + return path; + }, -/** - * Removes the query, if any, from the given path. - * - * @param {string} path - * @returns {string} - */ -exports.stripQuery = function stripQuery (path) { - let queryIndex = path.indexOf("?"); - if (queryIndex >= 0) { - path = path.substr(0, queryIndex); - } - return path; -}; + /** + * Returns the hash (URL fragment), of the given path. + * If there is no hash, then the root hash ("#") is returned. + * + * @param {string} path + * @returns {string} + */ + getHash (path) { + let hashIndex = path.indexOf("#"); + if (hashIndex >= 0) { + return path.substr(hashIndex); + } + return "#"; + }, -/** - * Returns the hash (URL fragment), of the given path. - * If there is no hash, then the root hash ("#") is returned. - * - * @param {string} path - * @returns {string} - */ -exports.getHash = function getHash (path) { - let hashIndex = path.indexOf("#"); - if (hashIndex >= 0) { - return path.substr(hashIndex); - } - return "#"; -}; + /** + * Removes the hash (URL fragment), if any, from the given path. + * + * @param {string} path + * @returns {string} + */ + stripHash (path) { + let hashIndex = path.indexOf("#"); + if (hashIndex >= 0) { + path = path.substr(0, hashIndex); + } + return path; + }, -/** - * Removes the hash (URL fragment), if any, from the given path. - * - * @param {string} path - * @returns {string} - */ -exports.stripHash = function stripHash (path) { - let hashIndex = path.indexOf("#"); - if (hashIndex >= 0) { - path = path.substr(0, hashIndex); - } - return path; -}; + /** + * Determines whether the given path is an HTTP(S) URL. + * + * @param {string} path + * @returns {boolean} + */ + isHttp (path) { + let protocol = this.getProtocol(path); + if (protocol === "http" || protocol === "https") { + return true; + } + else if (protocol === undefined) { + // There is no protocol. If we're running in a browser, then assume it's HTTP. + return process.browser; + } + else { + // It's some other protocol, such as "ftp://", "mongodb://", etc. + return false; + } + }, -/** - * Determines whether the given path is an HTTP(S) URL. - * - * @param {string} path - * @returns {boolean} - */ -exports.isHttp = function isHttp (path) { - let protocol = url.getProtocol(path); - if (protocol === "http" || protocol === "https") { - return true; - } - else if (protocol === undefined) { - // There is no protocol. If we're running in a browser, then assume it's HTTP. - return process.browser; - } - else { - // It's some other protocol, such as "ftp://", "mongodb://", etc. - return false; - } -}; + /** + * Determines whether the given path is a filesystem path. + * This includes "file://" URLs. + * + * @param {string} path + * @returns {boolean} + */ + isFileSystemPath (path) { + if (process.browser) { + // We're running in a browser, so assume that all paths are URLs. + // This way, even relative paths will be treated as URLs rather than as filesystem paths + return false; + } -/** - * Determines whether the given path is a filesystem path. - * This includes "file://" URLs. - * - * @param {string} path - * @returns {boolean} - */ -exports.isFileSystemPath = function isFileSystemPath (path) { - if (process.browser) { - // We're running in a browser, so assume that all paths are URLs. - // This way, even relative paths will be treated as URLs rather than as filesystem paths - return false; - } + let protocol = this.getProtocol(path); + return protocol === undefined || protocol === "file"; + }, - let protocol = url.getProtocol(path); - return protocol === undefined || protocol === "file"; -}; + /** + * Converts a filesystem path to a properly-encoded URL. + * + * This is intended to handle situations where JSON Schema $Ref Parser is called + * with a filesystem path that contains characters which are not allowed in URLs. + * + * @example + * The following filesystem paths would be converted to the following URLs: + * + * <"!@#$%^&*+=?'>.json ==> %3C%22!@%23$%25%5E&*+=%3F\'%3E.json + * C:\\My Documents\\File (1).json ==> C:/My%20Documents/File%20(1).json + * file://Project #42/file.json ==> file://Project%20%2342/file.json + * + * @param {string} path + * @returns {string} + */ + fromFileSystemPath (path) { + // Step 1: On Windows, replace backslashes with forward slashes, + // rather than encoding them as "%5C" + if (isWindows) { + path = path.replace(/\\/g, "/"); + } -/** - * Converts a filesystem path to a properly-encoded URL. - * - * This is intended to handle situations where JSON Schema $Ref Parser is called - * with a filesystem path that contains characters which are not allowed in URLs. - * - * @example - * The following filesystem paths would be converted to the following URLs: - * - * <"!@#$%^&*+=?'>.json ==> %3C%22!@%23$%25%5E&*+=%3F\'%3E.json - * C:\\My Documents\\File (1).json ==> C:/My%20Documents/File%20(1).json - * file://Project #42/file.json ==> file://Project%20%2342/file.json - * - * @param {string} path - * @returns {string} - */ -exports.fromFileSystemPath = function fromFileSystemPath (path) { - // Step 1: On Windows, replace backslashes with forward slashes, - // rather than encoding them as "%5C" - if (isWindows) { - path = path.replace(/\\/g, "/"); - } + // Step 2: `encodeURI` will take care of MOST characters + path = encodeURI(path); - // Step 2: `encodeURI` will take care of MOST characters - path = encodeURI(path); + // Step 3: Manually encode characters that are not encoded by `encodeURI`. + // This includes characters such as "#" and "?", which have special meaning in URLs, + // but are just normal characters in a filesystem path. + for (let i = 0; i < urlEncodePatterns.length; i += 2) { + path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]); + } - // Step 3: Manually encode characters that are not encoded by `encodeURI`. - // This includes characters such as "#" and "?", which have special meaning in URLs, - // but are just normal characters in a filesystem path. - for (let i = 0; i < urlEncodePatterns.length; i += 2) { - path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]); - } + return path; + }, - return path; -}; + /** + * Converts a URL to a local filesystem path. + * + * @param {string} path + * @param {boolean} [keepFileProtocol] - If true, then "file://" will NOT be stripped + * @returns {string} + */ + toFileSystemPath (path, keepFileProtocol) { + // Step 1: `decodeURI` will decode characters such as Cyrillic characters, spaces, etc. + path = decodeURI(path); -/** - * Converts a URL to a local filesystem path. - * - * @param {string} path - * @param {boolean} [keepFileProtocol] - If true, then "file://" will NOT be stripped - * @returns {string} - */ -exports.toFileSystemPath = function toFileSystemPath (path, keepFileProtocol) { - // Step 1: `decodeURI` will decode characters such as Cyrillic characters, spaces, etc. - path = decodeURI(path); + // Step 2: Manually decode characters that are not decoded by `decodeURI`. + // This includes characters such as "#" and "?", which have special meaning in URLs, + // but are just normal characters in a filesystem path. + for (let i = 0; i < urlDecodePatterns.length; i += 2) { + path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1]); + } - // Step 2: Manually decode characters that are not decoded by `decodeURI`. - // This includes characters such as "#" and "?", which have special meaning in URLs, - // but are just normal characters in a filesystem path. - for (let i = 0; i < urlDecodePatterns.length; i += 2) { - path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1]); - } + // Step 3: If it's a "file://" URL, then format it consistently + // or convert it to a local filesystem path + let isFileUrl = path.substr(0, 7).toLowerCase() === "file://"; + if (isFileUrl) { + // Strip-off the protocol, and the initial "/", if there is one + path = path[7] === "/" ? path.substr(8) : path.substr(7); - // Step 3: If it's a "file://" URL, then format it consistently - // or convert it to a local filesystem path - let isFileUrl = path.substr(0, 7).toLowerCase() === "file://"; - if (isFileUrl) { - // Strip-off the protocol, and the initial "/", if there is one - path = path[7] === "/" ? path.substr(8) : path.substr(7); + // insert a colon (":") after the drive letter on Windows + if (isWindows && path[1] === "/") { + path = path[0] + ":" + path.substr(1); + } - // insert a colon (":") after the drive letter on Windows - if (isWindows && path[1] === "/") { - path = path[0] + ":" + path.substr(1); + if (keepFileProtocol) { + // Return the consistently-formatted "file://" URL + path = "file:///" + path; + } + else { + // Convert the "file://" URL to a local filesystem path. + // On Windows, it will start with something like "C:/". + // On Posix, it will start with "/" + isFileUrl = false; + path = isWindows ? path : "/" + path; + } } - if (keepFileProtocol) { - // Return the consistently-formatted "file://" URL - path = "file:///" + path; - } - else { - // Convert the "file://" URL to a local filesystem path. - // On Windows, it will start with something like "C:/". - // On Posix, it will start with "/" - isFileUrl = false; - path = isWindows ? path : "/" + path; + // Step 4: Normalize Windows paths (unless it's a "file://" URL) + if (isWindows && !isFileUrl) { + // Replace forward slashes with backslashes + path = path.replace(forwardSlashPattern, "\\"); + + // Capitalize the drive letter + if (path.substr(1, 2) === ":\\") { + path = path[0].toUpperCase() + path.substr(1); + } } - } - // Step 4: Normalize Windows paths (unless it's a "file://" URL) - if (isWindows && !isFileUrl) { - // Replace forward slashes with backslashes - path = path.replace(forwardSlashPattern, "\\"); + return path; + }, - // Capitalize the drive letter - if (path.substr(1, 2) === ":\\") { - path = path[0].toUpperCase() + path.substr(1); + /** + * Converts a $ref pointer to a valid JSON Path. + * + * @param {string} pointer + * @returns {Array} + */ + safePointerToPath (pointer) { + if (pointer.length <= 1 || pointer[0] !== "#" || pointer[1] !== "/") { + return []; } - } - return path; -}; + return pointer + .slice(2) + .split("/") + .map((value) => { + return decodeURIComponent(value) + .replace(jsonPointerSlash, "/") + .replace(jsonPointerTilde, "~"); + }); + }, -/** - * Converts a $ref pointer to a valid JSON Path. - * - * @param {string} pointer - * @returns {Array} - */ -exports.safePointerToPath = function safePointerToPath (pointer) { - if (pointer.length <= 1 || pointer[0] !== "#" || pointer[1] !== "/") { - return []; - } + parse, - return pointer - .slice(2) - .split("/") - .map((value) => { - return decodeURIComponent(value) - .replace(jsonPointerSlash, "/") - .replace(jsonPointerTilde, "~"); - }); + resolve, }; diff --git a/package.json b/package.json index 4cea85a6..129b469a 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "files": [ "lib" ], + "type": "module", "scripts": { "build": "cp LICENSE *.md dist", "clean": "shx rm -rf .nyc_output coverage", diff --git a/test/fixtures/mocha.js b/test/fixtures/mocha.js index 2d9625c6..5e758542 100644 --- a/test/fixtures/mocha.js +++ b/test/fixtures/mocha.js @@ -1,5 +1,3 @@ -"use strict"; - const { host } = require("@jsdevtools/host-environment"); // Mocha configuration diff --git a/test/fixtures/polyfill.js b/test/fixtures/polyfill.js index 7add5abd..1ce493d8 100644 --- a/test/fixtures/polyfill.js +++ b/test/fixtures/polyfill.js @@ -1,5 +1,3 @@ -"use strict"; - const { host } = require("@jsdevtools/host-environment"); // Load the Babel Polyfills for old browsers. diff --git a/test/specs/__({[ % & $ # @ ` ~ ,)}]__/dereferenced.js b/test/specs/__({[ % & $ # @ ` ~ ,)}]__/dereferenced.js index c011e237..01011242 100644 --- a/test/specs/__({[ % & $ # @ ` ~ ,)}]__/dereferenced.js +++ b/test/specs/__({[ % & $ # @ ` ~ ,)}]__/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { definitions: { diff --git a/test/specs/__({[ % & $ # @ ` ~ ,)}]__/parsed.js b/test/specs/__({[ % & $ # @ ` ~ ,)}]__/parsed.js index 61153c01..eedaede1 100644 --- a/test/specs/__({[ % & $ # @ ` ~ ,)}]__/parsed.js +++ b/test/specs/__({[ % & $ # @ ` ~ ,)}]__/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/__({[ % & $ # @ ` ~ ,)}]__/special-characters.spec.js b/test/specs/__({[ % & $ # @ ` ~ ,)}]__/special-characters.spec.js index cf5f83c6..643d807b 100644 --- a/test/specs/__({[ % & $ # @ ` ~ ,)}]__/special-characters.spec.js +++ b/test/specs/__({[ % & $ # @ ` ~ ,)}]__/special-characters.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const $RefParser = require("../../.."); const helper = require("../../utils/helper"); const path = require("../../utils/path"); diff --git a/test/specs/absolute-root/absolute-root.spec.js b/test/specs/absolute-root/absolute-root.spec.js index 45541690..9589ac5b 100644 --- a/test/specs/absolute-root/absolute-root.spec.js +++ b/test/specs/absolute-root/absolute-root.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const { resolve } = require("path"); const $RefParser = require("../../.."); diff --git a/test/specs/absolute-root/bundled.js b/test/specs/absolute-root/bundled.js index db7919ec..635d392a 100644 --- a/test/specs/absolute-root/bundled.js +++ b/test/specs/absolute-root/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Person", diff --git a/test/specs/absolute-root/dereferenced.js b/test/specs/absolute-root/dereferenced.js index d82f1ca5..3d0e2c30 100644 --- a/test/specs/absolute-root/dereferenced.js +++ b/test/specs/absolute-root/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Person", diff --git a/test/specs/absolute-root/parsed.js b/test/specs/absolute-root/parsed.js index d6c1349f..f3aaf050 100644 --- a/test/specs/absolute-root/parsed.js +++ b/test/specs/absolute-root/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/blank/blank.spec.js b/test/specs/blank/blank.spec.js index a8f59a14..1ef6bc92 100644 --- a/test/specs/blank/blank.spec.js +++ b/test/specs/blank/blank.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { host } = require("@jsdevtools/host-environment"); const { expect } = require("chai"); const $RefParser = require("../../.."); diff --git a/test/specs/blank/dereferenced.js b/test/specs/blank/dereferenced.js index 6dc06e5c..10986093 100644 --- a/test/specs/blank/dereferenced.js +++ b/test/specs/blank/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { json: undefined, yaml: undefined, diff --git a/test/specs/blank/parsed.js b/test/specs/blank/parsed.js index d55e6748..523c5638 100644 --- a/test/specs/blank/parsed.js +++ b/test/specs/blank/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/callbacks.spec.js b/test/specs/callbacks.spec.js index ecd43ebb..3b9a24f2 100644 --- a/test/specs/callbacks.spec.js +++ b/test/specs/callbacks.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../lib"); const helper = require("../utils/helper"); diff --git a/test/specs/circular-extended/bundled.js b/test/specs/circular-extended/bundled.js index 77352209..e3988e85 100644 --- a/test/specs/circular-extended/bundled.js +++ b/test/specs/circular-extended/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - const bundledSchema = module.exports = { self: { diff --git a/test/specs/circular-extended/circular-extended.spec.js b/test/specs/circular-extended/circular-extended.spec.js index 14d8fd12..8827b31e 100644 --- a/test/specs/circular-extended/circular-extended.spec.js +++ b/test/specs/circular-extended/circular-extended.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/circular-extended/dereferenced.js b/test/specs/circular-extended/dereferenced.js index 527b1a75..97c7f767 100644 --- a/test/specs/circular-extended/dereferenced.js +++ b/test/specs/circular-extended/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - const dereferencedSchema = module.exports = { self: { diff --git a/test/specs/circular-extended/parsed.js b/test/specs/circular-extended/parsed.js index e9054c2c..a44602d9 100644 --- a/test/specs/circular-extended/parsed.js +++ b/test/specs/circular-extended/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { self: { diff --git a/test/specs/circular-external-direct/circular-external-direct.spec.js b/test/specs/circular-external-direct/circular-external-direct.spec.js index 408ec73f..bdbb1490 100644 --- a/test/specs/circular-external-direct/circular-external-direct.spec.js +++ b/test/specs/circular-external-direct/circular-external-direct.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const chai = require("chai"); const chaiSubset = require("chai-subset"); chai.use(chaiSubset); diff --git a/test/specs/circular-external-direct/dereferenced.js b/test/specs/circular-external-direct/dereferenced.js index 30ac5ddc..3565623b 100644 --- a/test/specs/circular-external-direct/dereferenced.js +++ b/test/specs/circular-external-direct/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { $ref: "./circular-external-direct-root.yaml#/foo", diff --git a/test/specs/circular-external-direct/parsed.js b/test/specs/circular-external-direct/parsed.js index 8ffbbd6e..67be0e20 100644 --- a/test/specs/circular-external-direct/parsed.js +++ b/test/specs/circular-external-direct/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/circular-external/bundled.js b/test/specs/circular-external/bundled.js index 39ec2ca9..e7b31b03 100644 --- a/test/specs/circular-external/bundled.js +++ b/test/specs/circular-external/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { definitions: { diff --git a/test/specs/circular-external/circular-external.spec.js b/test/specs/circular-external/circular-external.spec.js index bf60c30f..3b29b1fd 100644 --- a/test/specs/circular-external/circular-external.spec.js +++ b/test/specs/circular-external/circular-external.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/circular-external/dereferenced.js b/test/specs/circular-external/dereferenced.js index 5d952c5d..6d3f9e9b 100644 --- a/test/specs/circular-external/dereferenced.js +++ b/test/specs/circular-external/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - const dereferencedSchema = module.exports = { definitions: { diff --git a/test/specs/circular-external/parsed.js b/test/specs/circular-external/parsed.js index b9367703..65c75080 100644 --- a/test/specs/circular-external/parsed.js +++ b/test/specs/circular-external/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/circular-multi/bundled.js b/test/specs/circular-multi/bundled.js index 780ce18d..e6dcd535 100644 --- a/test/specs/circular-multi/bundled.js +++ b/test/specs/circular-multi/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { $schema: "http://json-schema.org/draft-07/schema#", properties: { diff --git a/test/specs/circular-multi/circular-multi.spec.js b/test/specs/circular-multi/circular-multi.spec.js index f7889693..222b56ae 100644 --- a/test/specs/circular-multi/circular-multi.spec.js +++ b/test/specs/circular-multi/circular-multi.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const path = require("../../utils/path"); diff --git a/test/specs/circular/circular.spec.js b/test/specs/circular/circular.spec.js index 2ba5b886..54001ca9 100644 --- a/test/specs/circular/circular.spec.js +++ b/test/specs/circular/circular.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/circular/dereferenced.js b/test/specs/circular/dereferenced.js index 519893dc..3cff0449 100644 --- a/test/specs/circular/dereferenced.js +++ b/test/specs/circular/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - const dereferencedSchema = module.exports = { self: { diff --git a/test/specs/circular/parsed.js b/test/specs/circular/parsed.js index fff22719..e118905c 100644 --- a/test/specs/circular/parsed.js +++ b/test/specs/circular/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { self: { diff --git a/test/specs/date-strings/date-strings.spec.js b/test/specs/date-strings/date-strings.spec.js index 7de4acce..4f0a4754 100644 --- a/test/specs/date-strings/date-strings.spec.js +++ b/test/specs/date-strings/date-strings.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/date-strings/parsed.js b/test/specs/date-strings/parsed.js index c9228a93..4963049e 100644 --- a/test/specs/date-strings/parsed.js +++ b/test/specs/date-strings/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { title: "Date Strings", diff --git a/test/specs/deep-circular/bundled.js b/test/specs/deep-circular/bundled.js index d1ba471d..f9fc6b66 100644 --- a/test/specs/deep-circular/bundled.js +++ b/test/specs/deep-circular/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Deep Schema", diff --git a/test/specs/deep-circular/deep-circular.spec.js b/test/specs/deep-circular/deep-circular.spec.js index 00ae32bb..87e6e0da 100644 --- a/test/specs/deep-circular/deep-circular.spec.js +++ b/test/specs/deep-circular/deep-circular.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/deep-circular/dereferenced.js b/test/specs/deep-circular/dereferenced.js index 1da07d24..8d8a200e 100644 --- a/test/specs/deep-circular/dereferenced.js +++ b/test/specs/deep-circular/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - let name = { required: [ "first", diff --git a/test/specs/deep-circular/parsed.js b/test/specs/deep-circular/parsed.js index 7c4d7186..c8063db5 100644 --- a/test/specs/deep-circular/parsed.js +++ b/test/specs/deep-circular/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/deep/bundled.js b/test/specs/deep/bundled.js index b47d6922..330f1076 100644 --- a/test/specs/deep/bundled.js +++ b/test/specs/deep/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { type: "object", diff --git a/test/specs/deep/deep.spec.js b/test/specs/deep/deep.spec.js index 30d9ac60..f2a0ab2e 100644 --- a/test/specs/deep/deep.spec.js +++ b/test/specs/deep/deep.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/deep/dereferenced.js b/test/specs/deep/dereferenced.js index 59035087..0b3f02e2 100644 --- a/test/specs/deep/dereferenced.js +++ b/test/specs/deep/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - let name = { required: [ "first", diff --git a/test/specs/deep/parsed.js b/test/specs/deep/parsed.js index 24218bb2..06d43d02 100644 --- a/test/specs/deep/parsed.js +++ b/test/specs/deep/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/empty/empty.spec.js b/test/specs/empty/empty.spec.js index f3815726..999a870e 100644 --- a/test/specs/empty/empty.spec.js +++ b/test/specs/empty/empty.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../../lib"); const helper = require("../../utils/helper"); diff --git a/test/specs/error-source/error-source.spec.js b/test/specs/error-source/error-source.spec.js index 4315c8bf..30c05497 100644 --- a/test/specs/error-source/error-source.spec.js +++ b/test/specs/error-source/error-source.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const chai = require("chai"); const chaiSubset = require("chai-subset"); chai.use(chaiSubset); diff --git a/test/specs/exports.spec.js b/test/specs/exports.spec.js index 1c87693d..0a3c096d 100644 --- a/test/specs/exports.spec.js +++ b/test/specs/exports.spec.js @@ -1,6 +1,4 @@ /* eslint-disable require-await */ -"use strict"; - const { expect } = require("chai"); const commonJSExport = require("../../"); const { default: defaultExport } = require("../../"); diff --git a/test/specs/external-from-internal/bundled.js b/test/specs/external-from-internal/bundled.js index 9b8caa3e..a3bce65a 100644 --- a/test/specs/external-from-internal/bundled.js +++ b/test/specs/external-from-internal/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { internal1: { $ref: "#/external1" diff --git a/test/specs/external-from-internal/dereferenced.js b/test/specs/external-from-internal/dereferenced.js index edf7d382..adddf134 100644 --- a/test/specs/external-from-internal/dereferenced.js +++ b/test/specs/external-from-internal/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { internal1: { diff --git a/test/specs/external-from-internal/external-from-internal.spec.js b/test/specs/external-from-internal/external-from-internal.spec.js index 75a36d22..b3d830ee 100644 --- a/test/specs/external-from-internal/external-from-internal.spec.js +++ b/test/specs/external-from-internal/external-from-internal.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/external-from-internal/parsed.js b/test/specs/external-from-internal/parsed.js index f4553079..657a66ad 100644 --- a/test/specs/external-from-internal/parsed.js +++ b/test/specs/external-from-internal/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/external-multiple/bundled.js b/test/specs/external-multiple/bundled.js index 782dd3dd..bc84683d 100644 --- a/test/specs/external-multiple/bundled.js +++ b/test/specs/external-multiple/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { type: "object", required: ["user", "token"], diff --git a/test/specs/external-multiple/dereferenced.js b/test/specs/external-multiple/dereferenced.js index d2bcf464..eb4e9052 100644 --- a/test/specs/external-multiple/dereferenced.js +++ b/test/specs/external-multiple/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { type: "object", required: ["user", "token"], diff --git a/test/specs/external-multiple/external-multiple.spec.js b/test/specs/external-multiple/external-multiple.spec.js index bbefe176..9cefc0cd 100644 --- a/test/specs/external-multiple/external-multiple.spec.js +++ b/test/specs/external-multiple/external-multiple.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/external-multiple/parsed.js b/test/specs/external-multiple/parsed.js index 29bafd16..38350713 100644 --- a/test/specs/external-multiple/parsed.js +++ b/test/specs/external-multiple/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { type: "object", diff --git a/test/specs/external-partial/bundled.js b/test/specs/external-partial/bundled.js index 93e97832..92b4cd21 100644 --- a/test/specs/external-partial/bundled.js +++ b/test/specs/external-partial/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Person", diff --git a/test/specs/external-partial/dereferenced.js b/test/specs/external-partial/dereferenced.js index e56ea468..fd593769 100644 --- a/test/specs/external-partial/dereferenced.js +++ b/test/specs/external-partial/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Person", diff --git a/test/specs/external-partial/external-partial.spec.js b/test/specs/external-partial/external-partial.spec.js index 2ab233b4..d35ab92a 100644 --- a/test/specs/external-partial/external-partial.spec.js +++ b/test/specs/external-partial/external-partial.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/external-partial/parsed.js b/test/specs/external-partial/parsed.js index e3043c06..dd475524 100644 --- a/test/specs/external-partial/parsed.js +++ b/test/specs/external-partial/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/external/bundled.js b/test/specs/external/bundled.js index db7919ec..635d392a 100644 --- a/test/specs/external/bundled.js +++ b/test/specs/external/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Person", diff --git a/test/specs/external/dereferenced.js b/test/specs/external/dereferenced.js index d82f1ca5..3d0e2c30 100644 --- a/test/specs/external/dereferenced.js +++ b/test/specs/external/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Person", diff --git a/test/specs/external/external.spec.js b/test/specs/external/external.spec.js index f1a8ec4b..78e28e3c 100644 --- a/test/specs/external/external.spec.js +++ b/test/specs/external/external.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/external/parsed.js b/test/specs/external/parsed.js index d6c1349f..f3aaf050 100644 --- a/test/specs/external/parsed.js +++ b/test/specs/external/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/http.spec.js b/test/specs/http.spec.js index 9cd2add4..ac296556 100644 --- a/test/specs/http.spec.js +++ b/test/specs/http.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { host } = require("@jsdevtools/host-environment"); const { expect } = require("chai"); const $RefParser = require("../../lib"); diff --git a/test/specs/internal/bundled.js b/test/specs/internal/bundled.js index dc923eec..af9f0b24 100644 --- a/test/specs/internal/bundled.js +++ b/test/specs/internal/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { definitions: { diff --git a/test/specs/internal/dereferenced.js b/test/specs/internal/dereferenced.js index 1e971e0d..f3524ffe 100644 --- a/test/specs/internal/dereferenced.js +++ b/test/specs/internal/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { definitions: { diff --git a/test/specs/internal/internal.spec.js b/test/specs/internal/internal.spec.js index f43875e5..0a07b4b5 100644 --- a/test/specs/internal/internal.spec.js +++ b/test/specs/internal/internal.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/internal/parsed.js b/test/specs/internal/parsed.js index b9bf16a6..ed84fe03 100644 --- a/test/specs/internal/parsed.js +++ b/test/specs/internal/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { definitions: { diff --git a/test/specs/invalid-pointers/invalid-pointers.js b/test/specs/invalid-pointers/invalid-pointers.js index bc62d936..f20224fa 100644 --- a/test/specs/invalid-pointers/invalid-pointers.js +++ b/test/specs/invalid-pointers/invalid-pointers.js @@ -1,5 +1,3 @@ -"use strict"; - const chai = require("chai"); const chaiSubset = require("chai-subset"); chai.use(chaiSubset); diff --git a/test/specs/invalid/invalid.spec.js b/test/specs/invalid/invalid.spec.js index dc6db7f9..603fb42d 100644 --- a/test/specs/invalid/invalid.spec.js +++ b/test/specs/invalid/invalid.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { host } = require("@jsdevtools/host-environment"); const chai = require("chai"); const chaiSubset = require("chai-subset"); diff --git a/test/specs/missing-pointers/missing-pointers.spec.js b/test/specs/missing-pointers/missing-pointers.spec.js index 4270bee9..7418bf75 100644 --- a/test/specs/missing-pointers/missing-pointers.spec.js +++ b/test/specs/missing-pointers/missing-pointers.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const chai = require("chai"); const chaiSubset = require("chai-subset"); chai.use(chaiSubset); diff --git a/test/specs/no-refs/no-refs.spec.js b/test/specs/no-refs/no-refs.spec.js index fe87615e..aa374523 100644 --- a/test/specs/no-refs/no-refs.spec.js +++ b/test/specs/no-refs/no-refs.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/no-refs/parsed.js b/test/specs/no-refs/parsed.js index 2cadce72..bcdc5a6c 100644 --- a/test/specs/no-refs/parsed.js +++ b/test/specs/no-refs/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { required: [ diff --git a/test/specs/object-source-with-path/bundled.js b/test/specs/object-source-with-path/bundled.js index 7a2e5898..dc0addc8 100644 --- a/test/specs/object-source-with-path/bundled.js +++ b/test/specs/object-source-with-path/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Person", diff --git a/test/specs/object-source-with-path/dereferenced.js b/test/specs/object-source-with-path/dereferenced.js index e5a5eb39..ea5a9d81 100644 --- a/test/specs/object-source-with-path/dereferenced.js +++ b/test/specs/object-source-with-path/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Person", diff --git a/test/specs/object-source-with-path/object-source-with-path.spec.js b/test/specs/object-source-with-path/object-source-with-path.spec.js index 5393f8b1..5caa9211 100644 --- a/test/specs/object-source-with-path/object-source-with-path.spec.js +++ b/test/specs/object-source-with-path/object-source-with-path.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/object-source-with-path/parsed.js b/test/specs/object-source-with-path/parsed.js index a12db7e7..152104e8 100644 --- a/test/specs/object-source-with-path/parsed.js +++ b/test/specs/object-source-with-path/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/object-source/bundled.js b/test/specs/object-source/bundled.js index 7a2e5898..dc0addc8 100644 --- a/test/specs/object-source/bundled.js +++ b/test/specs/object-source/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Person", diff --git a/test/specs/object-source/dereferenced.js b/test/specs/object-source/dereferenced.js index e5a5eb39..ea5a9d81 100644 --- a/test/specs/object-source/dereferenced.js +++ b/test/specs/object-source/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Person", diff --git a/test/specs/object-source/object-source.spec.js b/test/specs/object-source/object-source.spec.js index 57c294ce..223b98a6 100644 --- a/test/specs/object-source/object-source.spec.js +++ b/test/specs/object-source/object-source.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/object-source/parsed.js b/test/specs/object-source/parsed.js index fe034a4f..9f6fa301 100644 --- a/test/specs/object-source/parsed.js +++ b/test/specs/object-source/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - const path = require("../../utils/path"); module.exports = diff --git a/test/specs/parsers/dereferenced.js b/test/specs/parsers/dereferenced.js index 0d7e4997..2e8b6695 100644 --- a/test/specs/parsers/dereferenced.js +++ b/test/specs/parsers/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { defaultParsers: { definitions: { diff --git a/test/specs/parsers/parsed.js b/test/specs/parsers/parsed.js index 8dc803ab..e425405c 100644 --- a/test/specs/parsers/parsed.js +++ b/test/specs/parsers/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/parsers/parsers.spec.js b/test/specs/parsers/parsers.spec.js index 506d1cf7..2c4b15e5 100644 --- a/test/specs/parsers/parsers.spec.js +++ b/test/specs/parsers/parsers.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const chai = require("chai"); const chaiSubset = require("chai-subset"); chai.use(chaiSubset); diff --git a/test/specs/ref-in-excluded-path/dereferenced.js b/test/specs/ref-in-excluded-path/dereferenced.js index bd995c99..885e287d 100644 --- a/test/specs/ref-in-excluded-path/dereferenced.js +++ b/test/specs/ref-in-excluded-path/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { components: { examples: { diff --git a/test/specs/ref-in-excluded-path/ref-in-excluded-path.spec.js b/test/specs/ref-in-excluded-path/ref-in-excluded-path.spec.js index a462932e..8499e692 100644 --- a/test/specs/ref-in-excluded-path/ref-in-excluded-path.spec.js +++ b/test/specs/ref-in-excluded-path/ref-in-excluded-path.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const path = require("../../utils/path"); diff --git a/test/specs/refs.spec.js b/test/specs/refs.spec.js index be9bbdc9..55e706df 100644 --- a/test/specs/refs.spec.js +++ b/test/specs/refs.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { host } = require("@jsdevtools/host-environment"); const { expect } = require("chai"); const $RefParser = require("../../lib"); diff --git a/test/specs/resolvers/dereferenced.js b/test/specs/resolvers/dereferenced.js index fae7aace..81474b65 100644 --- a/test/specs/resolvers/dereferenced.js +++ b/test/specs/resolvers/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { definitions: { diff --git a/test/specs/resolvers/parsed.js b/test/specs/resolvers/parsed.js index 25fd633a..07a58f67 100644 --- a/test/specs/resolvers/parsed.js +++ b/test/specs/resolvers/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { definitions: { diff --git a/test/specs/resolvers/resolvers.spec.js b/test/specs/resolvers/resolvers.spec.js index 3dd95144..36dfe4d0 100644 --- a/test/specs/resolvers/resolvers.spec.js +++ b/test/specs/resolvers/resolvers.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const chai = require("chai"); const chaiSubset = require("chai-subset"); chai.use(chaiSubset); diff --git a/test/specs/root/bundled.js b/test/specs/root/bundled.js index c16becab..d87f6766 100644 --- a/test/specs/root/bundled.js +++ b/test/specs/root/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Extending a root $ref", diff --git a/test/specs/root/dereferenced.js b/test/specs/root/dereferenced.js index c16becab..d87f6766 100644 --- a/test/specs/root/dereferenced.js +++ b/test/specs/root/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Extending a root $ref", diff --git a/test/specs/root/parsed.js b/test/specs/root/parsed.js index 3fcce63c..6a369422 100644 --- a/test/specs/root/parsed.js +++ b/test/specs/root/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/root/root.spec.js b/test/specs/root/root.spec.js index e15cb31c..34f45da1 100644 --- a/test/specs/root/root.spec.js +++ b/test/specs/root/root.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/substrings/bundled.js b/test/specs/substrings/bundled.js index 96dc4c0e..2066cf10 100644 --- a/test/specs/substrings/bundled.js +++ b/test/specs/substrings/bundled.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Person", diff --git a/test/specs/substrings/dereferenced.js b/test/specs/substrings/dereferenced.js index e79bfaa8..5bbabf82 100644 --- a/test/specs/substrings/dereferenced.js +++ b/test/specs/substrings/dereferenced.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { title: "Person", diff --git a/test/specs/substrings/parsed.js b/test/specs/substrings/parsed.js index bdfb3419..41cd00f2 100644 --- a/test/specs/substrings/parsed.js +++ b/test/specs/substrings/parsed.js @@ -1,5 +1,3 @@ -"use strict"; - module.exports = { schema: { diff --git a/test/specs/substrings/substrings.spec.js b/test/specs/substrings/substrings.spec.js index ea7b3437..dae5ab52 100644 --- a/test/specs/substrings/substrings.spec.js +++ b/test/specs/substrings/substrings.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const { expect } = require("chai"); const $RefParser = require("../../.."); const helper = require("../../utils/helper"); diff --git a/test/specs/util/url.spec.js b/test/specs/util/url.spec.js index b0b464c9..7bfd4660 100644 --- a/test/specs/util/url.spec.js +++ b/test/specs/util/url.spec.js @@ -1,5 +1,3 @@ -"use strict"; - const chai = require("chai"); const chaiSubset = require("chai-subset"); chai.use(chaiSubset); diff --git a/test/utils/helper.js b/test/utils/helper.js index e201bf64..03127f3d 100644 --- a/test/utils/helper.js +++ b/test/utils/helper.js @@ -1,5 +1,3 @@ -"use strict"; - const $RefParser = require("../../lib"); const { host } = require("@jsdevtools/host-environment"); const { expect } = require("chai"); diff --git a/test/utils/path.js b/test/utils/path.js index 8f468a84..6b513280 100644 --- a/test/utils/path.js +++ b/test/utils/path.js @@ -1,5 +1,3 @@ -"use strict"; - const { host } = require("@jsdevtools/host-environment"); if (host.node) {