@apidevtools/json-schema-ref-parser 9.1.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Returns the given plugins as an array, rather than an object map.
3
+ * All other methods in this module expect an array of plugins rather than an object map.
4
+ *
5
+ * @param {object} plugins - A map of plugin objects
6
+ * @return {object[]}
7
+ */ "use strict";
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ function _export(target, all) {
12
+ for(var name in all)Object.defineProperty(target, name, {
13
+ enumerable: true,
14
+ get: all[name]
15
+ });
16
+ }
17
+ _export(exports, {
18
+ all: function() {
19
+ return all;
20
+ },
21
+ filter: function() {
22
+ return filter;
23
+ },
24
+ sort: function() {
25
+ return sort;
26
+ },
27
+ run: function() {
28
+ return run;
29
+ }
30
+ });
31
+ function _instanceof(left, right) {
32
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
33
+ return !!right[Symbol.hasInstance](left);
34
+ } else {
35
+ return left instanceof right;
36
+ }
37
+ }
38
+ function all(plugins) {
39
+ return Object.keys(plugins).filter(function(key) {
40
+ return typeof plugins[key] === "object";
41
+ }).map(function(key) {
42
+ plugins[key].name = key;
43
+ return plugins[key];
44
+ });
45
+ }
46
+ function filter(plugins, method, file) {
47
+ return plugins.filter(function(plugin) {
48
+ return !!getResult(plugin, method, file);
49
+ });
50
+ }
51
+ function sort(plugins) {
52
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
53
+ try {
54
+ for(var _iterator = plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
55
+ var plugin = _step.value;
56
+ plugin.order = plugin.order || Number.MAX_SAFE_INTEGER;
57
+ }
58
+ } catch (err) {
59
+ _didIteratorError = true;
60
+ _iteratorError = err;
61
+ } finally{
62
+ try {
63
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
64
+ _iterator.return();
65
+ }
66
+ } finally{
67
+ if (_didIteratorError) {
68
+ throw _iteratorError;
69
+ }
70
+ }
71
+ }
72
+ return plugins.sort(function(a, b) {
73
+ return a.order - b.order;
74
+ });
75
+ }
76
+ function run(plugins, method, file, $refs) {
77
+ var plugin, lastError, index = 0;
78
+ return new Promise(function(resolve, reject) {
79
+ var runNextPlugin = function runNextPlugin() {
80
+ plugin = plugins[index++];
81
+ if (!plugin) {
82
+ // There are no more functions, so re-throw the last error
83
+ return reject(lastError);
84
+ }
85
+ try {
86
+ // console.log(' %s', plugin.name);
87
+ var result = getResult(plugin, method, file, callback, $refs);
88
+ if (result && typeof result.then === "function") {
89
+ // A promise was returned
90
+ result.then(onSuccess, onError);
91
+ } else if (result !== undefined) {
92
+ // A synchronous result was returned
93
+ onSuccess(result);
94
+ } else if (index === plugins.length) {
95
+ throw new Error("No promise has been returned or callback has been called.");
96
+ }
97
+ } catch (e) {
98
+ onError(e);
99
+ }
100
+ };
101
+ var callback = function callback(err, result) {
102
+ if (err) {
103
+ onError(err);
104
+ } else {
105
+ onSuccess(result);
106
+ }
107
+ };
108
+ var onSuccess = function onSuccess(result) {
109
+ // console.log(' success');
110
+ resolve({
111
+ plugin: plugin,
112
+ result: result
113
+ });
114
+ };
115
+ var onError = function onError(error) {
116
+ // console.log(' %s', err.message || err);
117
+ lastError = {
118
+ plugin: plugin,
119
+ error: error
120
+ };
121
+ runNextPlugin();
122
+ };
123
+ runNextPlugin();
124
+ });
125
+ }
126
+ /**
127
+ * Returns the value of the given property.
128
+ * If the property is a function, then the result of the function is returned.
129
+ * If the value is a RegExp, then it will be tested against the file URL.
130
+ * If the value is an aray, then it will be compared against the file extension.
131
+ *
132
+ * @param {object} obj - The object whose property/method is called
133
+ * @param {string} prop - The name of the property/method to invoke
134
+ * @param {object} file - A file info object, which will be passed to the method
135
+ * @param {function} [callback] - A callback function, which will be passed to the method
136
+ * @returns {*}
137
+ */ function getResult(obj, prop, file, callback, $refs) {
138
+ var value = obj[prop];
139
+ if (typeof value === "function") {
140
+ return value.apply(obj, [
141
+ file,
142
+ callback,
143
+ $refs
144
+ ]);
145
+ }
146
+ if (!callback) {
147
+ // The synchronous plugin functions (canParse and canRead)
148
+ // allow a "shorthand" syntax, where the user can match
149
+ // files by RegExp or by file extension.
150
+ if (_instanceof(value, RegExp)) {
151
+ return value.test(file.url);
152
+ } else if (typeof value === "string") {
153
+ return value === file.extension;
154
+ } else if (Array.isArray(value)) {
155
+ return value.indexOf(file.extension) !== -1;
156
+ }
157
+ }
158
+ return value;
159
+ }
@@ -0,0 +1,6 @@
1
+ const nodePath = require("path");
2
+
3
+ // Webpack 4 (used by browser tests) can't transpile import.meta.url
4
+ // So export the project directory using __dirname from a .cjs module
5
+ const projectDir = nodePath.resolve(__dirname, "..", "..");
6
+ module.exports = projectDir
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ parse: function() {
13
+ return parse;
14
+ },
15
+ resolve: function() {
16
+ return resolve;
17
+ },
18
+ cwd: function() {
19
+ return cwd;
20
+ },
21
+ getProtocol: function() {
22
+ return getProtocol;
23
+ },
24
+ getExtension: function() {
25
+ return getExtension;
26
+ },
27
+ stripQuery: function() {
28
+ return stripQuery;
29
+ },
30
+ getHash: function() {
31
+ return getHash;
32
+ },
33
+ stripHash: function() {
34
+ return stripHash;
35
+ },
36
+ isHttp: function() {
37
+ return isHttp;
38
+ },
39
+ isFileSystemPath: function() {
40
+ return isFileSystemPath;
41
+ },
42
+ fromFileSystemPath: function() {
43
+ return fromFileSystemPath;
44
+ },
45
+ toFileSystemPath: function() {
46
+ return toFileSystemPath;
47
+ },
48
+ safePointerToPath: function() {
49
+ return safePointerToPath;
50
+ }
51
+ });
52
+ var _projectDirCjs = /*#__PURE__*/ _interopRequireDefault(require("./projectDir.cjs"));
53
+ function _interopRequireDefault(obj) {
54
+ return obj && obj.__esModule ? obj : {
55
+ default: obj
56
+ };
57
+ }
58
+ var isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined), forwardSlashPattern = /\//g, protocolPattern = /^(\w{2,}):\/\//i, jsonPointerSlash = /~1/g, jsonPointerTilde = /~0/g;
59
+ // RegExp patterns to URL-encode special characters in local filesystem paths
60
+ var urlEncodePatterns = [
61
+ /\?/g,
62
+ "%3F",
63
+ /\#/g,
64
+ "%23"
65
+ ];
66
+ // RegExp patterns to URL-decode special characters for local filesystem paths
67
+ var urlDecodePatterns = [
68
+ /\%23/g,
69
+ "#",
70
+ /\%24/g,
71
+ "$",
72
+ /\%26/g,
73
+ "&",
74
+ /\%2C/g,
75
+ ",",
76
+ /\%40/g,
77
+ "@"
78
+ ];
79
+ var parse = function(u) {
80
+ return new URL(u);
81
+ };
82
+ function resolve(from, to) {
83
+ var resolvedUrl = new URL(to, new URL(from, "resolve://"));
84
+ if (resolvedUrl.protocol === "resolve:") {
85
+ // `from` is a relative URL.
86
+ var pathname = resolvedUrl.pathname, search = resolvedUrl.search, hash = resolvedUrl.hash;
87
+ return pathname + search + hash;
88
+ }
89
+ return resolvedUrl.toString();
90
+ }
91
+ function cwd() {
92
+ if (typeof window !== "undefined") {
93
+ return location.href;
94
+ }
95
+ var path = process.cwd();
96
+ var lastChar = path.slice(-1);
97
+ if (lastChar === "/" || lastChar === "\\") {
98
+ return path;
99
+ } else {
100
+ return path + "/";
101
+ }
102
+ }
103
+ function getProtocol(path) {
104
+ var match = protocolPattern.exec(path);
105
+ if (match) {
106
+ return match[1].toLowerCase();
107
+ }
108
+ }
109
+ function getExtension(path) {
110
+ var lastDot = path.lastIndexOf(".");
111
+ if (lastDot >= 0) {
112
+ return stripQuery(path.substr(lastDot).toLowerCase());
113
+ }
114
+ return "";
115
+ }
116
+ function stripQuery(path) {
117
+ var queryIndex = path.indexOf("?");
118
+ if (queryIndex >= 0) {
119
+ path = path.substr(0, queryIndex);
120
+ }
121
+ return path;
122
+ }
123
+ function getHash(path) {
124
+ var hashIndex = path.indexOf("#");
125
+ if (hashIndex >= 0) {
126
+ return path.substr(hashIndex);
127
+ }
128
+ return "#";
129
+ }
130
+ function stripHash(path) {
131
+ var hashIndex = path.indexOf("#");
132
+ if (hashIndex >= 0) {
133
+ path = path.substr(0, hashIndex);
134
+ }
135
+ return path;
136
+ }
137
+ function isHttp(path) {
138
+ var protocol = getProtocol(path);
139
+ if (protocol === "http" || protocol === "https") {
140
+ return true;
141
+ } else if (protocol === undefined) {
142
+ // There is no protocol. If we're running in a browser, then assume it's HTTP.
143
+ return typeof window !== "undefined";
144
+ } else {
145
+ // It's some other protocol, such as "ftp://", "mongodb://", etc.
146
+ return false;
147
+ }
148
+ }
149
+ function isFileSystemPath(path) {
150
+ if (process.browser) {
151
+ // We're running in a browser, so assume that all paths are URLs.
152
+ // This way, even relative paths will be treated as URLs rather than as filesystem paths
153
+ return false;
154
+ }
155
+ var protocol = getProtocol(path);
156
+ return protocol === undefined || protocol === "file";
157
+ }
158
+ function fromFileSystemPath(path) {
159
+ // Step 1: On Windows, replace backslashes with forward slashes,
160
+ // rather than encoding them as "%5C"
161
+ if (isWindows) {
162
+ var hasProjectDir = path.toUpperCase().includes(_projectDirCjs.default.replace(/\\/g, "\\").toUpperCase());
163
+ var hasProjectUri = path.toUpperCase().includes(_projectDirCjs.default.replace(/\\/g, "/").toUpperCase());
164
+ if (hasProjectDir || hasProjectUri) {
165
+ path = path.replace(/\\/g, "/");
166
+ } else {
167
+ path = "".concat(_projectDirCjs.default, "/").concat(path).replace(/\\/g, "/");
168
+ }
169
+ }
170
+ // Step 2: `encodeURI` will take care of MOST characters
171
+ path = encodeURI(path);
172
+ // Step 3: Manually encode characters that are not encoded by `encodeURI`.
173
+ // This includes characters such as "#" and "?", which have special meaning in URLs,
174
+ // but are just normal characters in a filesystem path.
175
+ for(var i = 0; i < urlEncodePatterns.length; i += 2){
176
+ path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]);
177
+ }
178
+ return path;
179
+ }
180
+ function toFileSystemPath(path, keepFileProtocol) {
181
+ // Step 1: `decodeURI` will decode characters such as Cyrillic characters, spaces, etc.
182
+ path = decodeURI(path);
183
+ // Step 2: Manually decode characters that are not decoded by `decodeURI`.
184
+ // This includes characters such as "#" and "?", which have special meaning in URLs,
185
+ // but are just normal characters in a filesystem path.
186
+ for(var i = 0; i < urlDecodePatterns.length; i += 2){
187
+ path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1]);
188
+ }
189
+ // Step 3: If it's a "file://" URL, then format it consistently
190
+ // or convert it to a local filesystem path
191
+ var isFileUrl = path.substr(0, 7).toLowerCase() === "file://";
192
+ if (isFileUrl) {
193
+ // Strip-off the protocol, and the initial "/", if there is one
194
+ path = path[7] === "/" ? path.substr(8) : path.substr(7);
195
+ // insert a colon (":") after the drive letter on Windows
196
+ if (isWindows && path[1] === "/") {
197
+ path = path[0] + ":" + path.substr(1);
198
+ }
199
+ if (keepFileProtocol) {
200
+ // Return the consistently-formatted "file://" URL
201
+ path = "file:///" + path;
202
+ } else {
203
+ // Convert the "file://" URL to a local filesystem path.
204
+ // On Windows, it will start with something like "C:/".
205
+ // On Posix, it will start with "/"
206
+ isFileUrl = false;
207
+ path = isWindows ? path : "/" + path;
208
+ }
209
+ }
210
+ // Step 4: Normalize Windows paths (unless it's a "file://" URL)
211
+ if (isWindows && !isFileUrl) {
212
+ // Replace forward slashes with backslashes
213
+ path = path.replace(forwardSlashPattern, "\\");
214
+ // Capitalize the drive letter
215
+ if (path.substr(1, 2) === ":\\") {
216
+ path = path[0].toUpperCase() + path.substr(1);
217
+ }
218
+ }
219
+ return path;
220
+ }
221
+ function safePointerToPath(pointer) {
222
+ if (pointer.length <= 1 || pointer[0] !== "#" || pointer[1] !== "/") {
223
+ return [];
224
+ }
225
+ return pointer.slice(2).split("/").map(function(value) {
226
+ return decodeURIComponent(value).replace(jsonPointerSlash, "/").replace(jsonPointerTilde, "~");
227
+ });
228
+ }
package/lib/bundle.js CHANGED
@@ -1,10 +1,8 @@
1
- "use strict";
1
+ import $Ref from "./ref.js";
2
+ import Pointer from "./pointer.js";
3
+ import * as url from "./util/url.js";
2
4
 
3
- const $Ref = require("./ref");
4
- const Pointer = require("./pointer");
5
- const url = require("./util/url");
6
-
7
- module.exports = bundle;
5
+ export default bundle;
8
6
 
9
7
  /**
10
8
  * Bundles all external JSON references into the main JSON schema, thus resulting in a schema that
@@ -135,7 +133,7 @@ function inventory$Ref ($refParent, $refKey, path, pathFromRoot, indirections, i
135
133
  });
136
134
 
137
135
  // Recursively crawl the resolved value
138
- if (!existingEntry) {
136
+ if (!existingEntry || external) {
139
137
  crawl(pointer.value, null, pointer.path, pathFromRoot, indirections + 1, inventory, $refs, options);
140
138
  }
141
139
  }
@@ -1,11 +1,9 @@
1
- "use strict";
1
+ import $Ref from "./ref.js";
2
+ import Pointer from "./pointer.js";
3
+ import { ono } from "@jsdevtools/ono";
4
+ import * as url from "./util/url.js";
2
5
 
3
- const $Ref = require("./ref");
4
- const Pointer = require("./pointer");
5
- const { ono } = require("@jsdevtools/ono");
6
- const url = require("./util/url");
7
-
8
- module.exports = dereference;
6
+ export default dereference;
9
7
 
10
8
  /**
11
9
  * Crawls the JSON schema, finds all JSON references, and dereferences them.
@@ -71,6 +69,9 @@ function crawl (obj, path, pathFromRoot, parents, processedObjects, dereferenced
71
69
  // Avoid pointless mutations; breaks frozen objects to no profit
72
70
  if (obj[key] !== dereferenced.value) {
73
71
  obj[key] = dereferenced.value;
72
+ if (options.dereference.onDereference) {
73
+ options.dereference.onDereference(value.$ref, obj[key]);
74
+ }
74
75
  }
75
76
  }
76
77
  else {
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type, JSONSchema7, JSONSchema7Type } from "json-schema";
1
+ import { JSONSchema4, JSONSchema4Object, JSONSchema4Type, JSONSchema6, JSONSchema6Object, JSONSchema6Type, JSONSchema7, JSONSchema7Object, JSONSchema7Type } from "json-schema";
2
2
 
3
3
  export = $RefParser;
4
4
 
@@ -174,6 +174,7 @@ declare class $RefParser {
174
174
  declare namespace $RefParser {
175
175
 
176
176
  export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
177
+ export type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object;
177
178
  export type SchemaCallback = (err: Error | null, schema?: JSONSchema) => any;
178
179
  export type $RefsCallback = (err: Error | null, $refs?: $Refs) => any;
179
180
 
@@ -238,6 +239,14 @@ declare namespace $RefParser {
238
239
  * subpaths contain literal $ref keys that should not be dereferenced.
239
240
  */
240
241
  excludedPathMatcher?(path: string): boolean;
242
+
243
+ /**
244
+ * Callback invoked during dereferencing.
245
+ *
246
+ * @argument {string} path The path being dereferenced (ie. the `$ref` string).
247
+ * @argument {JSONSchemaObject} object The JSON-Schema that the `$ref` resolved to.
248
+ */
249
+ onDereference(path: string, value: JSONSchemaObject): void;
241
250
  };
242
251
  }
243
252
 
package/lib/index.js CHANGED
@@ -1,26 +1,23 @@
1
1
  /* eslint-disable no-unused-vars */
2
- "use strict";
2
+ import $Refs from "./refs.js";
3
+ import _parse from "./parse.js";
4
+ import normalizeArgs from "./normalize-args.js";
5
+ import resolveExternal from "./resolve-external.js";
6
+ import _bundle from "./bundle.js";
7
+ import _dereference from "./dereference.js";
8
+ import * as url from "./util/url.js";
9
+ import { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError, JSONParserErrorGroup } from "./util/errors.js";
10
+ import maybe from "call-me-maybe";
11
+ import { ono } from "@jsdevtools/ono";
3
12
 
4
- const $Refs = require("./refs");
5
- const _parse = require("./parse");
6
- const normalizeArgs = require("./normalize-args");
7
- const resolveExternal = require("./resolve-external");
8
- const _bundle = require("./bundle");
9
- const _dereference = require("./dereference");
10
- const url = require("./util/url");
11
- const { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError, JSONParserErrorGroup } = require("./util/errors");
12
- const maybe = require("call-me-maybe");
13
- const { ono } = require("@jsdevtools/ono");
14
-
15
- module.exports = $RefParser;
16
- module.exports.default = $RefParser;
17
- module.exports.JSONParserError = JSONParserError;
18
- module.exports.InvalidPointerError = InvalidPointerError;
19
- module.exports.MissingPointerError = MissingPointerError;
20
- module.exports.ResolverError = ResolverError;
21
- module.exports.ParserError = ParserError;
22
- module.exports.UnmatchedParserError = UnmatchedParserError;
23
- module.exports.UnmatchedResolverError = UnmatchedResolverError;
13
+ export default $RefParser;
14
+ export { JSONParserError };
15
+ export { InvalidPointerError };
16
+ export { MissingPointerError };
17
+ export { ResolverError };
18
+ export { ParserError };
19
+ export { UnmatchedParserError };
20
+ export { UnmatchedResolverError };
24
21
 
25
22
  /**
26
23
  * This class parses a JSON schema, builds a map of its JSON references and their resolved values,
@@ -281,3 +278,13 @@ function finalize (parser) {
281
278
  throw new JSONParserErrorGroup(parser);
282
279
  }
283
280
  }
281
+
282
+ export const parse = $RefParser.parse.bind($RefParser);
283
+ export const resolve = $RefParser.resolve.bind($RefParser);
284
+ export const bundle = $RefParser.bundle.bind($RefParser);
285
+ export const dereference = $RefParser.dereference.bind($RefParser);
286
+
287
+ // CommonJS default export hack
288
+ if (typeof module === "object" && typeof module.exports === "object") {
289
+ module.exports = Object.assign(module.exports.default, module.exports);
290
+ }
@@ -1,8 +1,6 @@
1
- "use strict";
1
+ import Options from "./options.js";
2
2
 
3
- const Options = require("./options");
4
-
5
- module.exports = normalizeArgs;
3
+ export default normalizeArgs;
6
4
 
7
5
  /**
8
6
  * Normalizes the given arguments, accounting for optional args.
package/lib/options.js CHANGED
@@ -1,14 +1,12 @@
1
1
  /* eslint lines-around-comment: [2, {beforeBlockComment: false}] */
2
- "use strict";
2
+ import jsonParser from "./parsers/json.js";
3
+ import yamlParser from "./parsers/yaml.js";
4
+ import textParser from "./parsers/text.js";
5
+ import binaryParser from "./parsers/binary.js";
6
+ import fileResolver from "./resolvers/file.js";
7
+ import httpResolver from "./resolvers/http.js";
3
8
 
4
- const jsonParser = require("./parsers/json");
5
- const yamlParser = require("./parsers/yaml");
6
- const textParser = require("./parsers/text");
7
- const binaryParser = require("./parsers/binary");
8
- const fileResolver = require("./resolvers/file");
9
- const httpResolver = require("./resolvers/http");
10
-
11
- module.exports = $RefParserOptions;
9
+ export default $RefParserOptions;
12
10
 
13
11
  /**
14
12
  * Options that determine how JSON schemas are parsed, resolved, and dereferenced.
package/lib/parse.js CHANGED
@@ -1,11 +1,9 @@
1
- "use strict";
1
+ import { ono } from "@jsdevtools/ono";
2
+ import * as url from "./util/url.js";
3
+ import * as plugins from "./util/plugins.js";
4
+ import { ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError } from "./util/errors.js";
2
5
 
3
- const { ono } = require("@jsdevtools/ono");
4
- const url = require("./util/url");
5
- const plugins = require("./util/plugins");
6
- const { ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError } = require("./util/errors");
7
-
8
- module.exports = parse;
6
+ export default parse;
9
7
 
10
8
  /**
11
9
  * Reads and parses the specified file path or URL.
@@ -1,8 +1,6 @@
1
- "use strict";
2
-
3
1
  let BINARY_REGEXP = /\.(jpeg|jpg|gif|png|bmp|ico)$/i;
4
2
 
5
- module.exports = {
3
+ export default {
6
4
  /**
7
5
  * The order that this parser will run, in relation to other parsers.
8
6
  *
@@ -1,8 +1,6 @@
1
- "use strict";
1
+ import { ParserError } from "../util/errors.js";
2
2
 
3
- const { ParserError } = require("../util/errors");
4
-
5
- module.exports = {
3
+ export default {
6
4
  /**
7
5
  * The order that this parser will run, in relation to other parsers.
8
6
  *
@@ -1,10 +1,8 @@
1
- "use strict";
2
-
3
- const { ParserError } = require("../util/errors");
1
+ import { ParserError } from "../util/errors.js";
4
2
 
5
3
  let TEXT_REGEXP = /\.(txt|htm|html|md|xml|js|min|map|css|scss|less|svg)$/i;
6
4
 
7
- module.exports = {
5
+ export default {
8
6
  /**
9
7
  * The order that this parser will run, in relation to other parsers.
10
8
  *
@@ -1,10 +1,8 @@
1
- "use strict";
1
+ import { ParserError } from "../util/errors.js";
2
+ import yaml from "js-yaml";
3
+ import { JSON_SCHEMA } from "js-yaml";
2
4
 
3
- const { ParserError } = require("../util/errors");
4
- const yaml = require("js-yaml");
5
- const { JSON_SCHEMA } = require("js-yaml");
6
-
7
- module.exports = {
5
+ export default {
8
6
  /**
9
7
  * The order that this parser will run, in relation to other parsers.
10
8
  *
package/lib/pointer.js CHANGED
@@ -1,10 +1,8 @@
1
- "use strict";
1
+ export default Pointer;
2
2
 
3
- module.exports = Pointer;
4
-
5
- const $Ref = require("./ref");
6
- const url = require("./util/url");
7
- const { JSONParserError, InvalidPointerError, MissingPointerError, isHandledError } = require("./util/errors");
3
+ import $Ref from "./ref.js";
4
+ import * as url from "./util/url.js";
5
+ import { JSONParserError, InvalidPointerError, MissingPointerError, isHandledError } from "./util/errors.js";
8
6
  const slashes = /\//g;
9
7
  const tildes = /~/g;
10
8
  const escapedSlash = /~1/g;
package/lib/ref.js CHANGED
@@ -1,10 +1,8 @@
1
- "use strict";
1
+ export default $Ref;
2
2
 
3
- module.exports = $Ref;
4
-
5
- const Pointer = require("./pointer");
6
- const { InvalidPointerError, isHandledError, normalizeError } = require("./util/errors");
7
- const { safePointerToPath, stripHash, getHash } = require("./util/url");
3
+ import Pointer from "./pointer.js";
4
+ import { InvalidPointerError, isHandledError, normalizeError } from "./util/errors.js";
5
+ import { safePointerToPath, stripHash, getHash } from "./util/url.js";
8
6
 
9
7
  /**
10
8
  * This class represents a single JSON reference and its resolved value.