@mountainpass/waychaser 5.0.15 → 5.0.17

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.
@@ -134,210 +134,241 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
134
134
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
135
135
  };
136
136
 
137
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
137
+ function getDefaultExportFromCjs (x) {
138
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
139
+ }
138
140
 
139
141
  var uriTemplateLite = {};
140
142
 
141
- /**
142
- * @version 20.5.0
143
- * @author Lauri Rooden <lauri@rooden.ee>
144
- * @license MIT License
145
- */
143
+ var hasRequiredUriTemplateLite;
146
144
 
145
+ function requireUriTemplateLite () {
146
+ if (hasRequiredUriTemplateLite) return uriTemplateLite;
147
+ hasRequiredUriTemplateLite = 1;
148
+ /**
149
+ * @version 20.5.0
150
+ * @author Lauri Rooden <lauri@rooden.ee>
151
+ * @license MIT License
152
+ */
147
153
 
148
154
 
149
- !function(URI) {
150
155
 
151
- /**
152
- * URI Template
153
- * @see http://tools.ietf.org/html/rfc6570
154
- */
156
+ !function(URI) {
155
157
 
156
- var RESERVED = /[!'()]/g
157
- // /[[\]:\/!#$&()*+,;='?@]/g
158
- , SEPARATORS = {"": ",", "+": ",", "#": ",", "?": "&"}
159
- , escapeRe = /[$-\/?[-^{|}]/g
160
- , expandRe = /\{([#&+.\/;?]?)((?:[-\w%.]+(\*|:\d+)?,?)+)\}/g
161
- , parseRe = RegExp(expandRe.source + "|.[^{]*?", "g");
158
+ /**
159
+ * URI Template
160
+ * @see http://tools.ietf.org/html/rfc6570
161
+ */
162
162
 
163
- /*** EXPAND ***/
164
- function encodeNormal(val) {
165
- return encodeURIComponent(val).replace(RESERVED, escape)
166
- }
163
+ var RESERVED = /[!'()]/g
164
+ // /[[\]:\/!#$&()*+,;='?@]/g
165
+ , SEPARATORS = {"": ",", "+": ",", "#": ",", "?": "&"}
166
+ , escapeRe = /[$-\/?[-^{|}]/g
167
+ , expandRe = /\{([#&+.\/;?]?)((?:[-\w%.]+(\*|:\d+)?,?)+)\}/g
168
+ , parseRe = RegExp(expandRe.source + "|.[^{]*?", "g");
167
169
 
168
- function notNull(s) {
169
- return s != null
170
- }
170
+ /*** EXPAND ***/
171
+ function encodeNormal(val) {
172
+ return encodeURIComponent(val).replace(RESERVED, escape)
173
+ }
171
174
 
172
- function mapCleanJoin(arr, mapFn, joinStr) {
173
- arr = arr.map(mapFn).filter(notNull);
174
- return arr.length && arr.join(joinStr)
175
- }
175
+ function notNull(s) {
176
+ return s != null
177
+ }
176
178
 
177
- function expand(template, data) {
178
- return template.replace(expandRe, function(_, op, vals) {
179
- var sep = SEPARATORS[op] || op
180
- , named = sep == ";" || sep == "&"
181
- , enc = op && sep == "," ? encodeURI : encodeNormal
182
- , out = mapCleanJoin(vals.split(","), function(_name) {
183
- var mod = _name.split(/[*:]/)
184
- , name = mod[0]
185
- , val = data[name];
186
-
187
- if (val == null) return
188
-
189
- if (typeof val == "object") {
190
- mod = name != _name;
191
- if (Array.isArray(val)) {
192
- val = mapCleanJoin(val, enc, mod ? named ? sep + name + "=" : sep : "," );
179
+ function mapCleanJoin(arr, mapFn, joinStr) {
180
+ arr = arr.map(mapFn).filter(notNull);
181
+ return arr.length && arr.join(joinStr)
182
+ }
183
+
184
+ function expand(template, data) {
185
+ return template.replace(expandRe, function(_, op, vals) {
186
+ var sep = SEPARATORS[op] || op
187
+ , named = sep == ";" || sep == "&"
188
+ , enc = op && sep == "," ? encodeURI : encodeNormal
189
+ , out = mapCleanJoin(vals.split(","), function(_name) {
190
+ var mod = _name.split(/[*:]/)
191
+ , name = mod[0]
192
+ , val = data[name];
193
+
194
+ if (val == null) return
195
+
196
+ if (typeof val == "object") {
197
+ mod = name != _name;
198
+ if (Array.isArray(val)) {
199
+ val = mapCleanJoin(val, enc, mod ? named ? sep + name + "=" : sep : "," );
200
+ } else {
201
+ val = mapCleanJoin(Object.keys(val), function(key) {
202
+ return enc(key) + (mod ? "=" : ",") + enc(val[key])
203
+ }, mod && (named || sep == "/") ? sep : ",");
204
+ if (mod) named = 0;
205
+ }
206
+ if (!val) return
193
207
  } else {
194
- val = mapCleanJoin(Object.keys(val), function(key) {
195
- return enc(key) + (mod ? "=" : ",") + enc(val[key])
196
- }, mod && (named || sep == "/") ? sep : ",");
197
- if (mod) named = 0;
208
+ val = enc(mod[1] ? val.slice(0, mod[1]) : val);
198
209
  }
199
- if (!val) return
200
- } else {
201
- val = enc(mod[1] ? val.slice(0, mod[1]) : val);
202
- }
203
-
204
- return (
205
- named ?
206
- name + (val || sep == "&" ? "=" + val : val) :
207
- val
208
- )
209
- }, sep);
210
-
211
- return out || out === "" ? (op != "+" ? op + out : out) : ""
212
- }
213
- )}
214
-
215
- URI.expand = expand;
216
- /**/
217
-
218
- URI.Template = function Template(template) {
219
- var self = this
220
- //if (!(self instanceof Template)) return new Template(template)
221
- /*** PARSE ***/
222
- , pos = 0
223
- , lengths = {}
224
- , fnStr = ""
225
- , reStr = "^" + template.replace(parseRe, function(_, op, vals) {
226
- if (!vals) return escapeRegExp(_)
227
-
228
- var sep = SEPARATORS[op] || op
229
- , named = sep == ";" || sep == "&"
230
- , reGroup = vals.split(",").map(function(_name) {
231
- var mod = _name.split(/[*:]/)
232
- , name = mod[0]
233
- , re = (lengths[name] || "(") + ".*?)";
234
-
235
- pos++;
236
- //console.log("KEY", arguments)
237
- if (mod[1]) {
238
- re = "((?:%..|.){1," + mod[1] + "})";
239
- lengths[name] = "(\\" + pos;
240
- }
241
- //TODO: decodeURIComponent throws an Error on invalid input, add try-catch
242
- fnStr += "t=($[" + pos + "]||'').split('" + sep + "').map(decodeURIComponent);";
243
- fnStr += "o[\"" + name + "\"]=t.length>1?t:t[0];";
244
- return (
245
- named ?
246
- escapeRegExp(name) + "(?:=" + re + ")?" :
247
- sep == "&" ?
248
- escapeRegExp(name + "=") + re :
249
- re
250
- )
251
- }).join(escapeRegExp(sep));
252
- return (op != "+" ? escapeRegExp(op) + reGroup : reGroup)
253
-
254
- }) + "$"
255
- , re = RegExp(reStr)
256
- , fn = Function("$", "var t,o={};" + fnStr + "return o");
257
- self.template = template;
258
- self.match = function(uri) {
259
- var match = re.exec(uri);
260
- return match && fn(match)
261
- };
262
210
 
263
- function escapeRegExp(string) {
264
- return string.replace(escapeRe, "\\$&")
265
- }
266
- /**/
267
- /*** EXPAND ***/
268
- self.expand = expand.bind(self, template);
211
+ return (
212
+ named ?
213
+ name + (val || sep == "&" ? "=" + val : val) :
214
+ val
215
+ )
216
+ }, sep);
217
+
218
+ return out || out === "" ? (op != "+" ? op + out : out) : ""
219
+ }
220
+ )}
221
+
222
+ URI.expand = expand;
269
223
  /**/
270
- };
271
224
 
272
- // `this` is `exports` in NodeJS and `window` in browser.
273
- }(commonjsGlobal.URI || (commonjsGlobal.URI = {}));
225
+ URI.Template = function Template(template) {
226
+ var self = this
227
+ //if (!(self instanceof Template)) return new Template(template)
228
+ /*** PARSE ***/
229
+ , pos = 0
230
+ , lengths = {}
231
+ , fnStr = ""
232
+ , reStr = "^" + template.replace(parseRe, function(_, op, vals) {
233
+ if (!vals) return escapeRegExp(_)
234
+
235
+ var sep = SEPARATORS[op] || op
236
+ , named = sep == ";" || sep == "&"
237
+ , reGroup = vals.split(",").map(function(_name) {
238
+ var mod = _name.split(/[*:]/)
239
+ , name = mod[0]
240
+ , re = (lengths[name] || "(") + ".*?)";
241
+
242
+ pos++;
243
+ //console.log("KEY", arguments)
244
+ if (mod[1]) {
245
+ re = "((?:%..|.){1," + mod[1] + "})";
246
+ lengths[name] = "(\\" + pos;
247
+ }
248
+ //TODO: decodeURIComponent throws an Error on invalid input, add try-catch
249
+ fnStr += "t=($[" + pos + "]||'').split('" + sep + "').map(decodeURIComponent);";
250
+ fnStr += "o[\"" + name + "\"]=t.length>1?t:t[0];";
251
+ return (
252
+ named ?
253
+ escapeRegExp(name) + "(?:=" + re + ")?" :
254
+ sep == "&" ?
255
+ escapeRegExp(name + "=") + re :
256
+ re
257
+ )
258
+ }).join(escapeRegExp(sep));
259
+ return (op != "+" ? escapeRegExp(op) + reGroup : reGroup)
260
+
261
+ }) + "$"
262
+ , re = RegExp(reStr)
263
+ , fn = Function("$", "var t,o={};" + fnStr + "return o");
264
+ self.template = template;
265
+ self.match = function(uri) {
266
+ var match = re.exec(uri);
267
+ return match && fn(match)
268
+ };
269
+
270
+ function escapeRegExp(string) {
271
+ return string.replace(escapeRe, "\\$&")
272
+ }
273
+ /**/
274
+ /*** EXPAND ***/
275
+ self.expand = expand.bind(self, template);
276
+ /**/
277
+ };
274
278
 
275
- /* eslint-disable unicorn/prefer-ternary */
279
+ // `this` is `exports` in NodeJS and `window` in browser.
280
+ }(uriTemplateLite.URI || (uriTemplateLite.URI = {}));
281
+ return uriTemplateLite;
282
+ }
276
283
 
284
+ var uriTemplateLiteExports = requireUriTemplateLite();
277
285
 
286
+ /* eslint-disable unicorn/prefer-ternary */
278
287
  /**
279
288
  *
280
289
  */
281
290
  function getUri() {
282
- /* istanbul ignore next: it's complicated */
283
- if (typeof window === 'undefined') {
284
- // eslint-disable-next-line unicorn/prefer-module
285
- return uriTemplateLite.URI || global.URI
286
- } else {
287
- return window.URI || uriTemplateLite.URI
288
- }
291
+ /* istanbul ignore next: it's complicated */
292
+ if (typeof window === 'undefined') {
293
+ // eslint-disable-next-line unicorn/prefer-module
294
+ return uriTemplateLiteExports.URI || global.URI;
295
+ }
296
+ else {
297
+ return window.URI || uriTemplateLiteExports.URI;
298
+ }
289
299
  }
290
-
291
300
  /**
292
301
  *
293
302
  */
294
303
  function getExtendedUri() {
295
- const base = getUri();
296
- base.parameters = function (url) {
297
- const template = new URI.Template(url);
298
- return template.match(url)
299
- };
300
- return base
304
+ var base = getUri();
305
+ base.parameters = function (url) {
306
+ var template = new URI.Template(url);
307
+ return template.match(url);
308
+ };
309
+ return base;
301
310
  }
311
+ var URI = getExtendedUri();
302
312
 
313
+ var qsStringify$1;
314
+ var hasRequiredQsStringify;
303
315
 
304
- const URI = getExtendedUri();
316
+ function requireQsStringify () {
317
+ if (hasRequiredQsStringify) return qsStringify$1;
318
+ hasRequiredQsStringify = 1;
319
+ var has = Object.prototype.hasOwnProperty;
305
320
 
306
- var has = Object.prototype.hasOwnProperty;
321
+ /**
322
+ * Stringify an object for use in a query string.
323
+ *
324
+ * @param {Object} obj - The object.
325
+ * @param {string} prefix - When nesting, the parent key.
326
+ * keys in `obj` will be stringified as `prefix[key]`.
327
+ * @returns {string}
328
+ */
307
329
 
308
- /**
309
- * Stringify an object for use in a query string.
310
- *
311
- * @param {Object} obj - The object.
312
- * @param {string} prefix - When nesting, the parent key.
313
- * keys in `obj` will be stringified as `prefix[key]`.
314
- * @returns {string}
315
- */
330
+ qsStringify$1 = function queryStringify (obj, prefix) {
331
+ var pairs = [];
332
+ for (var key in obj) {
333
+ if (!has.call(obj, key)) {
334
+ continue
335
+ }
336
+
337
+ var value = obj[key];
338
+ var enkey = encodeURIComponent(key);
339
+ var pair;
340
+ if (typeof value === 'object') {
341
+ pair = queryStringify(value, prefix ? prefix + '[' + enkey + ']' : enkey);
342
+ } else {
343
+ pair = (prefix ? prefix + '[' + enkey + ']' : enkey) + '=' + encodeURIComponent(value);
344
+ }
345
+ pairs.push(pair);
346
+ }
347
+ return pairs.join('&')
348
+ };
349
+ return qsStringify$1;
350
+ }
316
351
 
317
- var qsStringify = function queryStringify (obj, prefix) {
318
- var pairs = [];
319
- for (var key in obj) {
320
- if (!has.call(obj, key)) {
321
- continue
322
- }
352
+ var qsStringifyExports = requireQsStringify();
353
+ var qsStringify = /*@__PURE__*/getDefaultExportFromCjs(qsStringifyExports);
323
354
 
324
- var value = obj[key];
325
- var enkey = encodeURIComponent(key);
326
- var pair;
327
- if (typeof value === 'object') {
328
- pair = queryStringify(value, prefix ? prefix + '[' + enkey + ']' : enkey);
329
- } else {
330
- pair = (prefix ? prefix + '[' + enkey + ']' : enkey) + '=' + encodeURIComponent(value);
331
- }
332
- pairs.push(pair);
333
- }
334
- return pairs.join('&')
335
- };
355
+ var browser;
356
+ var hasRequiredBrowser;
357
+
358
+ function requireBrowser () {
359
+ if (hasRequiredBrowser) return browser;
360
+ hasRequiredBrowser = 1;
361
+
362
+ /* eslint-env browser */
363
+ browser = typeof self === 'object' ? self.FormData : window.FormData;
364
+ return browser;
365
+ }
336
366
 
337
- /* eslint-env browser */
338
- var browser = typeof self === 'object' ? self.FormData : window.FormData;
367
+ var browserExports = requireBrowser();
368
+ var FormData = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
339
369
 
340
370
  // negotiated (https://www.npmjs.com/package/negotiated) doesn't working in IE 11 due to missing regex polyfill stuff
371
+ // @hapi/accept https://www.npmjs.com/package/@hapi/accept is too big (with all it's dependencies)
341
372
  /**
342
373
  * @param {string} accept
343
374
  */
@@ -411,346 +442,372 @@ function parseAccept(accept) {
411
442
  * @param supportedContentTypes
412
443
  * @param defaultType
413
444
  */
414
- function preferredContentType (
415
- accept,
416
- supportedContentTypes,
417
- defaultType
418
- ) {
419
- if (accept) {
420
- const acceptable = parseAccept(accept);
421
-
422
- const acceptableMediaTypes = acceptable.find(row => {
423
- return supportedContentTypes.includes(row.type)
424
- });
425
-
426
- return acceptableMediaTypes.type
427
- } else {
428
- return defaultType
429
- }
430
- }
431
-
432
- var flat = flatten;
433
- flatten.flatten = flatten;
434
- flatten.unflatten = unflatten;
435
-
436
- function isBuffer (obj) {
437
- return obj &&
438
- obj.constructor &&
439
- (typeof obj.constructor.isBuffer === 'function') &&
440
- obj.constructor.isBuffer(obj)
441
- }
442
-
443
- function keyIdentity (key) {
444
- return key
445
- }
446
-
447
- function flatten (target, opts) {
448
- opts = opts || {};
449
-
450
- const delimiter = opts.delimiter || '.';
451
- const maxDepth = opts.maxDepth;
452
- const transformKey = opts.transformKey || keyIdentity;
453
- const output = {};
454
-
455
- function step (object, prev, currentDepth) {
456
- currentDepth = currentDepth || 1;
457
- Object.keys(object).forEach(function (key) {
458
- const value = object[key];
459
- const isarray = opts.safe && Array.isArray(value);
460
- const type = Object.prototype.toString.call(value);
461
- const isbuffer = isBuffer(value);
462
- const isobject = (
463
- type === '[object Object]' ||
464
- type === '[object Array]'
465
- );
466
-
467
- const newKey = prev
468
- ? prev + delimiter + transformKey(key)
469
- : transformKey(key);
470
-
471
- if (!isarray && !isbuffer && isobject && Object.keys(value).length &&
472
- (!opts.maxDepth || currentDepth < maxDepth)) {
473
- return step(value, newKey, currentDepth + 1)
474
- }
475
-
476
- output[newKey] = value;
477
- });
478
- }
479
-
480
- step(target);
481
-
482
- return output
483
- }
484
-
485
- function unflatten (target, opts) {
486
- opts = opts || {};
487
-
488
- const delimiter = opts.delimiter || '.';
489
- const overwrite = opts.overwrite || false;
490
- const transformKey = opts.transformKey || keyIdentity;
491
- const result = {};
492
-
493
- const isbuffer = isBuffer(target);
494
- if (isbuffer || Object.prototype.toString.call(target) !== '[object Object]') {
495
- return target
496
- }
497
-
498
- // safely ensure that the key is
499
- // an integer.
500
- function getkey (key) {
501
- const parsedKey = Number(key);
502
-
503
- return (
504
- isNaN(parsedKey) ||
505
- key.indexOf('.') !== -1 ||
506
- opts.object
507
- ) ? key
508
- : parsedKey
509
- }
510
-
511
- function addKeys (keyPrefix, recipient, target) {
512
- return Object.keys(target).reduce(function (result, key) {
513
- result[keyPrefix + delimiter + key] = target[key];
514
-
515
- return result
516
- }, recipient)
517
- }
518
-
519
- function isEmpty (val) {
520
- const type = Object.prototype.toString.call(val);
521
- const isArray = type === '[object Array]';
522
- const isObject = type === '[object Object]';
523
-
524
- if (!val) {
525
- return true
526
- } else if (isArray) {
527
- return !val.length
528
- } else if (isObject) {
529
- return !Object.keys(val).length
530
- }
531
- }
532
-
533
- target = Object.keys(target).reduce(function (result, key) {
534
- const type = Object.prototype.toString.call(target[key]);
535
- const isObject = (type === '[object Object]' || type === '[object Array]');
536
- if (!isObject || isEmpty(target[key])) {
537
- result[key] = target[key];
538
- return result
539
- } else {
540
- return addKeys(
541
- key,
542
- result,
543
- flatten(target[key], opts)
544
- )
445
+ function preferredContentType(accept, supportedContentTypes, defaultType) {
446
+ if (accept) {
447
+ var acceptable = parseAccept(accept);
448
+ var acceptableMediaTypes = acceptable.find(function (row) {
449
+ return supportedContentTypes.includes(row.type);
450
+ });
451
+ return acceptableMediaTypes.type;
545
452
  }
546
- }, {});
547
-
548
- Object.keys(target).forEach(function (key) {
549
- const split = key.split(delimiter).map(transformKey);
550
- let key1 = getkey(split.shift());
551
- let key2 = getkey(split[0]);
552
- let recipient = result;
553
-
554
- while (key2 !== undefined) {
555
- if (key1 === '__proto__') {
556
- return
557
- }
558
-
559
- const type = Object.prototype.toString.call(recipient[key1]);
560
- const isobject = (
561
- type === '[object Object]' ||
562
- type === '[object Array]'
563
- );
564
-
565
- // do not write over falsey, non-undefined values if overwrite is false
566
- if (!overwrite && !isobject && typeof recipient[key1] !== 'undefined') {
567
- return
568
- }
569
-
570
- if ((overwrite && !isobject) || (!overwrite && recipient[key1] == null)) {
571
- recipient[key1] = (
572
- typeof key2 === 'number' &&
573
- !opts.object ? [] : {}
574
- );
575
- }
576
-
577
- recipient = recipient[key1];
578
- if (split.length > 0) {
579
- key1 = getkey(split.shift());
580
- key2 = getkey(split[0]);
581
- }
453
+ else {
454
+ return defaultType;
582
455
  }
583
-
584
- // unflatten again for 'messy objects'
585
- recipient[key1] = unflatten(target[key], opts);
586
- });
587
-
588
- return result
589
456
  }
590
457
 
591
- var jsonpointer = {};
592
-
593
- var hasExcape = /~/;
594
- var escapeMatcher = /~[01]/g;
595
- function escapeReplacer (m) {
596
- switch (m) {
597
- case '~1': return '/'
598
- case '~0': return '~'
599
- }
600
- throw new Error('Invalid tilde escape: ' + m)
601
- }
458
+ var flat;
459
+ var hasRequiredFlat;
460
+
461
+ function requireFlat () {
462
+ if (hasRequiredFlat) return flat;
463
+ hasRequiredFlat = 1;
464
+ flat = flatten;
465
+ flatten.flatten = flatten;
466
+ flatten.unflatten = unflatten;
467
+
468
+ function isBuffer (obj) {
469
+ return obj &&
470
+ obj.constructor &&
471
+ (typeof obj.constructor.isBuffer === 'function') &&
472
+ obj.constructor.isBuffer(obj)
473
+ }
602
474
 
603
- function untilde (str) {
604
- if (!hasExcape.test(str)) return str
605
- return str.replace(escapeMatcher, escapeReplacer)
606
- }
475
+ function keyIdentity (key) {
476
+ return key
477
+ }
607
478
 
608
- function setter (obj, pointer, value) {
609
- var part;
610
- var hasNextPart;
479
+ function flatten (target, opts) {
480
+ opts = opts || {};
481
+
482
+ const delimiter = opts.delimiter || '.';
483
+ const maxDepth = opts.maxDepth;
484
+ const transformKey = opts.transformKey || keyIdentity;
485
+ const output = {};
486
+
487
+ function step (object, prev, currentDepth) {
488
+ currentDepth = currentDepth || 1;
489
+ Object.keys(object).forEach(function (key) {
490
+ const value = object[key];
491
+ const isarray = opts.safe && Array.isArray(value);
492
+ const type = Object.prototype.toString.call(value);
493
+ const isbuffer = isBuffer(value);
494
+ const isobject = (
495
+ type === '[object Object]' ||
496
+ type === '[object Array]'
497
+ );
498
+
499
+ const newKey = prev
500
+ ? prev + delimiter + transformKey(key)
501
+ : transformKey(key);
502
+
503
+ if (!isarray && !isbuffer && isobject && Object.keys(value).length &&
504
+ (!opts.maxDepth || currentDepth < maxDepth)) {
505
+ return step(value, newKey, currentDepth + 1)
506
+ }
507
+
508
+ output[newKey] = value;
509
+ });
510
+ }
511
+
512
+ step(target);
513
+
514
+ return output
515
+ }
611
516
 
612
- for (var p = 1, len = pointer.length; p < len;) {
613
- if (pointer[p] === 'constructor' || pointer[p] === 'prototype' || pointer[p] === '__proto__') return obj
517
+ function unflatten (target, opts) {
518
+ opts = opts || {};
519
+
520
+ const delimiter = opts.delimiter || '.';
521
+ const overwrite = opts.overwrite || false;
522
+ const transformKey = opts.transformKey || keyIdentity;
523
+ const result = {};
524
+
525
+ const isbuffer = isBuffer(target);
526
+ if (isbuffer || Object.prototype.toString.call(target) !== '[object Object]') {
527
+ return target
528
+ }
529
+
530
+ // safely ensure that the key is
531
+ // an integer.
532
+ function getkey (key) {
533
+ const parsedKey = Number(key);
534
+
535
+ return (
536
+ isNaN(parsedKey) ||
537
+ key.indexOf('.') !== -1 ||
538
+ opts.object
539
+ ) ? key
540
+ : parsedKey
541
+ }
542
+
543
+ function addKeys (keyPrefix, recipient, target) {
544
+ return Object.keys(target).reduce(function (result, key) {
545
+ result[keyPrefix + delimiter + key] = target[key];
546
+
547
+ return result
548
+ }, recipient)
549
+ }
550
+
551
+ function isEmpty (val) {
552
+ const type = Object.prototype.toString.call(val);
553
+ const isArray = type === '[object Array]';
554
+ const isObject = type === '[object Object]';
555
+
556
+ if (!val) {
557
+ return true
558
+ } else if (isArray) {
559
+ return !val.length
560
+ } else if (isObject) {
561
+ return !Object.keys(val).length
562
+ }
563
+ }
564
+
565
+ target = Object.keys(target).reduce(function (result, key) {
566
+ const type = Object.prototype.toString.call(target[key]);
567
+ const isObject = (type === '[object Object]' || type === '[object Array]');
568
+ if (!isObject || isEmpty(target[key])) {
569
+ result[key] = target[key];
570
+ return result
571
+ } else {
572
+ return addKeys(
573
+ key,
574
+ result,
575
+ flatten(target[key], opts)
576
+ )
577
+ }
578
+ }, {});
579
+
580
+ Object.keys(target).forEach(function (key) {
581
+ const split = key.split(delimiter).map(transformKey);
582
+ let key1 = getkey(split.shift());
583
+ let key2 = getkey(split[0]);
584
+ let recipient = result;
585
+
586
+ while (key2 !== undefined) {
587
+ if (key1 === '__proto__') {
588
+ return
589
+ }
590
+
591
+ const type = Object.prototype.toString.call(recipient[key1]);
592
+ const isobject = (
593
+ type === '[object Object]' ||
594
+ type === '[object Array]'
595
+ );
596
+
597
+ // do not write over falsey, non-undefined values if overwrite is false
598
+ if (!overwrite && !isobject && typeof recipient[key1] !== 'undefined') {
599
+ return
600
+ }
601
+
602
+ if ((overwrite && !isobject) || (!overwrite && recipient[key1] == null)) {
603
+ recipient[key1] = (
604
+ typeof key2 === 'number' &&
605
+ !opts.object ? [] : {}
606
+ );
607
+ }
608
+
609
+ recipient = recipient[key1];
610
+ if (split.length > 0) {
611
+ key1 = getkey(split.shift());
612
+ key2 = getkey(split[0]);
613
+ }
614
+ }
615
+
616
+ // unflatten again for 'messy objects'
617
+ recipient[key1] = unflatten(target[key], opts);
618
+ });
619
+
620
+ return result
621
+ }
622
+ return flat;
623
+ }
614
624
 
615
- part = untilde(pointer[p++]);
616
- hasNextPart = len > p;
625
+ var flatExports = requireFlat();
626
+ var flatten = /*@__PURE__*/getDefaultExportFromCjs(flatExports);
617
627
 
618
- if (typeof obj[part] === 'undefined') {
619
- // support setting of /-
620
- if (Array.isArray(obj) && part === '-') {
621
- part = obj.length;
622
- }
628
+ var jsonpointer = {};
623
629
 
624
- // support nested objects/array when setting values
625
- if (hasNextPart) {
626
- if ((pointer[p] !== '' && pointer[p] < Infinity) || pointer[p] === '-') obj[part] = [];
627
- else obj[part] = {};
628
- }
629
- }
630
+ var hasRequiredJsonpointer;
631
+
632
+ function requireJsonpointer () {
633
+ if (hasRequiredJsonpointer) return jsonpointer;
634
+ hasRequiredJsonpointer = 1;
635
+ var hasExcape = /~/;
636
+ var escapeMatcher = /~[01]/g;
637
+ function escapeReplacer (m) {
638
+ switch (m) {
639
+ case '~1': return '/'
640
+ case '~0': return '~'
641
+ }
642
+ throw new Error('Invalid tilde escape: ' + m)
643
+ }
630
644
 
631
- if (!hasNextPart) break
632
- obj = obj[part];
633
- }
645
+ function untilde (str) {
646
+ if (!hasExcape.test(str)) return str
647
+ return str.replace(escapeMatcher, escapeReplacer)
648
+ }
634
649
 
635
- var oldValue = obj[part];
636
- if (value === undefined) delete obj[part];
637
- else obj[part] = value;
638
- return oldValue
639
- }
650
+ function setter (obj, pointer, value) {
651
+ var part;
652
+ var hasNextPart;
653
+
654
+ for (var p = 1, len = pointer.length; p < len;) {
655
+ if (pointer[p] === 'constructor' || pointer[p] === 'prototype' || pointer[p] === '__proto__') return obj
656
+
657
+ part = untilde(pointer[p++]);
658
+ hasNextPart = len > p;
659
+
660
+ if (typeof obj[part] === 'undefined') {
661
+ // support setting of /-
662
+ if (Array.isArray(obj) && part === '-') {
663
+ part = obj.length;
664
+ }
665
+
666
+ // support nested objects/array when setting values
667
+ if (hasNextPart) {
668
+ if ((pointer[p] !== '' && pointer[p] < Infinity) || pointer[p] === '-') obj[part] = [];
669
+ else obj[part] = {};
670
+ }
671
+ }
672
+
673
+ if (!hasNextPart) break
674
+ obj = obj[part];
675
+ }
676
+
677
+ var oldValue = obj[part];
678
+ if (value === undefined) delete obj[part];
679
+ else obj[part] = value;
680
+ return oldValue
681
+ }
640
682
 
641
- function compilePointer (pointer) {
642
- if (typeof pointer === 'string') {
643
- pointer = pointer.split('/');
644
- if (pointer[0] === '') return pointer
645
- throw new Error('Invalid JSON pointer.')
646
- } else if (Array.isArray(pointer)) {
647
- for (const part of pointer) {
648
- if (typeof part !== 'string' && typeof part !== 'number') {
649
- throw new Error('Invalid JSON pointer. Must be of type string or number.')
650
- }
651
- }
652
- return pointer
653
- }
683
+ function compilePointer (pointer) {
684
+ if (typeof pointer === 'string') {
685
+ pointer = pointer.split('/');
686
+ if (pointer[0] === '') return pointer
687
+ throw new Error('Invalid JSON pointer.')
688
+ } else if (Array.isArray(pointer)) {
689
+ for (const part of pointer) {
690
+ if (typeof part !== 'string' && typeof part !== 'number') {
691
+ throw new Error('Invalid JSON pointer. Must be of type string or number.')
692
+ }
693
+ }
694
+ return pointer
695
+ }
696
+
697
+ throw new Error('Invalid JSON pointer.')
698
+ }
654
699
 
655
- throw new Error('Invalid JSON pointer.')
656
- }
700
+ function get (obj, pointer) {
701
+ if (typeof obj !== 'object') throw new Error('Invalid input object.')
702
+ pointer = compilePointer(pointer);
703
+ var len = pointer.length;
704
+ if (len === 1) return obj
705
+
706
+ for (var p = 1; p < len;) {
707
+ obj = obj[untilde(pointer[p++])];
708
+ if (len === p) return obj
709
+ if (typeof obj !== 'object' || obj === null) return undefined
710
+ }
711
+ }
657
712
 
658
- function get (obj, pointer) {
659
- if (typeof obj !== 'object') throw new Error('Invalid input object.')
660
- pointer = compilePointer(pointer);
661
- var len = pointer.length;
662
- if (len === 1) return obj
663
-
664
- for (var p = 1; p < len;) {
665
- obj = obj[untilde(pointer[p++])];
666
- if (len === p) return obj
667
- if (typeof obj !== 'object' || obj === null) return undefined
668
- }
669
- }
713
+ function set (obj, pointer, value) {
714
+ if (typeof obj !== 'object') throw new Error('Invalid input object.')
715
+ pointer = compilePointer(pointer);
716
+ if (pointer.length === 0) throw new Error('Invalid JSON pointer for set.')
717
+ return setter(obj, pointer, value)
718
+ }
670
719
 
671
- function set (obj, pointer, value) {
672
- if (typeof obj !== 'object') throw new Error('Invalid input object.')
673
- pointer = compilePointer(pointer);
674
- if (pointer.length === 0) throw new Error('Invalid JSON pointer for set.')
675
- return setter(obj, pointer, value)
676
- }
720
+ function compile (pointer) {
721
+ var compiled = compilePointer(pointer);
722
+ return {
723
+ get: function (object) {
724
+ return get(object, compiled)
725
+ },
726
+ set: function (object, value) {
727
+ return set(object, compiled, value)
728
+ }
729
+ }
730
+ }
677
731
 
678
- function compile (pointer) {
679
- var compiled = compilePointer(pointer);
680
- return {
681
- get: function (object) {
682
- return get(object, compiled)
683
- },
684
- set: function (object, value) {
685
- return set(object, compiled, value)
686
- }
687
- }
732
+ jsonpointer.get = get;
733
+ jsonpointer.set = set;
734
+ jsonpointer.compile = compile;
735
+ return jsonpointer;
688
736
  }
689
737
 
690
- jsonpointer.get = get;
691
- jsonpointer.set = set;
692
- jsonpointer.compile = compile;
738
+ var jsonpointerExports = requireJsonpointer();
739
+ var pointer = /*@__PURE__*/getDefaultExportFromCjs(jsonpointerExports);
693
740
 
694
741
  /**
695
742
  * @param method
696
743
  */
697
- function methodCanHaveBody (method) {
698
- return !['GET', 'DELETE', 'TRACE', 'OPTIONS', 'HEAD'].includes(method)
744
+ function methodCanHaveBody(method) {
745
+ return !['GET', 'DELETE', 'TRACE', 'OPTIONS', 'HEAD'].includes(method);
699
746
  }
700
747
 
701
748
  var lib = {};
702
749
 
703
- Object.defineProperty(lib, "__esModule", { value: true });
704
- var ProblemDocument_1 = lib.ProblemDocument = void 0;
705
- /**
706
- *
707
- * This class implements RFC7807 "problem detail", a way to carry machine-
708
- * readable details of errors in a HTTP response to avoid the need to
709
- * define new error response formats for HTTP APIs.
710
- *
711
- * Official Documentation @ https://datatracker.ietf.org/doc/html/rfc7807
712
- *
713
- * Consumers MUST use the "type" string as the primary identifier for
714
- * the problem type; the "title" string is advisory and included only
715
- * for users who are not aware of the semantics of the URI and do not
716
- * have the ability to discover them (e.g., offline log analysis).
717
- * Consumers SHOULD NOT automatically dereference the type URI.
718
- *
719
- * The "status" member, if present, is only advisory; it conveys the
720
- * HTTP status code used for the convenience of the consumer.
721
- * Generators MUST use the same status code in the actual HTTP response,
722
- * to assure that generic HTTP software that does not understand this
723
- * format still behaves correctly. See Section 5 for further caveats
724
- * regarding its use.
725
- *
726
- * Consumers can use the status member to determine what the original
727
- * status code used by the generator was, in cases where it has been
728
- * changed (e.g., by an intermediary or cache), and when message bodies
729
- * persist without HTTP information. Generic HTTP software will still
730
- * use the HTTP status code.
731
- *
732
- * The "detail" member, if present, ought to focus on helping the client
733
- * correct the problem, rather than giving debugging information.
734
- *
735
- * Consumers SHOULD NOT parse the "detail" member for information;
736
- * extensions are more suitable and less error-prone ways to obtain such
737
- * information.
738
- *
739
- * Note that both {@link BaseProblemDocumentProperties.type type} and {@link BaseProblemDocumentProperties.instance instance} accept relative URIs; this means
740
- * that they must be resolved relative to the document's base URI, as
741
- * per {@link https://datatracker.ietf.org/doc/html/rfc3986#section-5 [RFC3986], Section 5}.
742
- */
743
- class ProblemDocument {
744
- /**
745
- *
746
- * construct a new ProblemDocument instance
747
- * @param data properties to assign to the new instance
748
- */
749
- constructor(data) {
750
- Object.assign(this, data);
751
- }
750
+ var hasRequiredLib;
751
+
752
+ function requireLib () {
753
+ if (hasRequiredLib) return lib;
754
+ hasRequiredLib = 1;
755
+ Object.defineProperty(lib, "__esModule", { value: true });
756
+ lib.ProblemDocument = void 0;
757
+ /**
758
+ *
759
+ * This class implements RFC7807 "problem detail", a way to carry machine-
760
+ * readable details of errors in a HTTP response to avoid the need to
761
+ * define new error response formats for HTTP APIs.
762
+ *
763
+ * Official Documentation @ https://datatracker.ietf.org/doc/html/rfc7807
764
+ *
765
+ * Consumers MUST use the "type" string as the primary identifier for
766
+ * the problem type; the "title" string is advisory and included only
767
+ * for users who are not aware of the semantics of the URI and do not
768
+ * have the ability to discover them (e.g., offline log analysis).
769
+ * Consumers SHOULD NOT automatically dereference the type URI.
770
+ *
771
+ * The "status" member, if present, is only advisory; it conveys the
772
+ * HTTP status code used for the convenience of the consumer.
773
+ * Generators MUST use the same status code in the actual HTTP response,
774
+ * to assure that generic HTTP software that does not understand this
775
+ * format still behaves correctly. See Section 5 for further caveats
776
+ * regarding its use.
777
+ *
778
+ * Consumers can use the status member to determine what the original
779
+ * status code used by the generator was, in cases where it has been
780
+ * changed (e.g., by an intermediary or cache), and when message bodies
781
+ * persist without HTTP information. Generic HTTP software will still
782
+ * use the HTTP status code.
783
+ *
784
+ * The "detail" member, if present, ought to focus on helping the client
785
+ * correct the problem, rather than giving debugging information.
786
+ *
787
+ * Consumers SHOULD NOT parse the "detail" member for information;
788
+ * extensions are more suitable and less error-prone ways to obtain such
789
+ * information.
790
+ *
791
+ * Note that both {@link BaseProblemDocumentProperties.type type} and {@link BaseProblemDocumentProperties.instance instance} accept relative URIs; this means
792
+ * that they must be resolved relative to the document's base URI, as
793
+ * per {@link https://datatracker.ietf.org/doc/html/rfc3986#section-5 [RFC3986], Section 5}.
794
+ */
795
+ class ProblemDocument {
796
+ /**
797
+ *
798
+ * construct a new ProblemDocument instance
799
+ * @param data properties to assign to the new instance
800
+ */
801
+ constructor(data) {
802
+ Object.assign(this, data);
803
+ }
804
+ }
805
+ lib.ProblemDocument = ProblemDocument;
806
+
807
+ return lib;
752
808
  }
753
- ProblemDocument_1 = lib.ProblemDocument = ProblemDocument;
809
+
810
+ var libExports = requireLib();
754
811
 
755
812
  var Operation = /** @class */ (function () {
756
813
  function Operation(_a) {
@@ -783,7 +840,7 @@ var InvocableOperation = /** @class */ (function (_super) {
783
840
  InvocableOperation.prototype.invokeAsFragment = function (parameters, validator) {
784
841
  if (this.uri.startsWith('#/')) {
785
842
  var anchor = this.expandUrl(parameters).toString();
786
- var fragmentContent = this.response.fullContent && jsonpointer.get(this.response.fullContent, anchor.slice(1));
843
+ var fragmentContent = this.response.fullContent && pointer.get(this.response.fullContent, anchor.slice(1));
787
844
  if (fragmentContent === undefined) {
788
845
  return undefined;
789
846
  }
@@ -831,7 +888,7 @@ var InvocableOperation = /** @class */ (function (_super) {
831
888
  if (keys.length !== 0) {
832
889
  var field = currentUriParameters[keys[0]];
833
890
  var parentUri = currentUri.slice(1, currentUri.indexOf(field) - 1);
834
- var parent_1 = parentUri === '' ? response.content : jsonpointer.get(response.content, parentUri);
891
+ var parent_1 = parentUri === '' ? response.content : pointer.get(response.content, parentUri);
835
892
  if (parent_1) {
836
893
  var indices = Array.isArray(parent_1) ? __spreadArray([], __read(Array.from({ length: parent_1.length }).keys()), false) : Object.keys(parent_1);
837
894
  return indices.flatMap(function (index) {
@@ -843,7 +900,7 @@ var InvocableOperation = /** @class */ (function (_super) {
843
900
  else {
844
901
  throw new WayChaserProblem({
845
902
  response: this.response,
846
- problem: new ProblemDocument_1({
903
+ problem: new libExports.ProblemDocument({
847
904
  type: "https://waychaser.io/fragment-uri-error",
848
905
  title: "The fragment URI does not match the content structure",
849
906
  uri: parentUri, content: response.content,
@@ -918,7 +975,7 @@ var InvocableOperation = /** @class */ (function (_super) {
918
975
  encodedContent = JSON.stringify(body);
919
976
  break;
920
977
  case 'multipart/form-data':
921
- encodedContent = new browser();
978
+ encodedContent = new FormData();
922
979
  for (name_1 in body) {
923
980
  encodedContent.append(name_1, body[name_1]);
924
981
  }
@@ -945,7 +1002,7 @@ var InvocableOperation = /** @class */ (function (_super) {
945
1002
  return invokeUrl;
946
1003
  };
947
1004
  InvocableOperation.prototype.expandUrl = function (parameters) {
948
- return URI.expand(this.uri, flat(parameters || {}));
1005
+ return URI.expand(this.uri, flatten(parameters || {}));
949
1006
  };
950
1007
  return InvocableOperation;
951
1008
  }(Operation));
@@ -1157,38 +1214,38 @@ function parseOperations(_a) {
1157
1214
  return expandedOperations;
1158
1215
  }
1159
1216
 
1160
- const MediaTypes = {
1161
- HAL: 'application/hal+json',
1162
- SIREN: 'application/vnd.siren+json'
1217
+ var MediaTypes = {
1218
+ HAL: 'application/hal+json',
1219
+ SIREN: 'application/vnd.siren+json'
1163
1220
  };
1164
1221
 
1165
1222
  /**
1166
1223
  * @param relationship
1167
1224
  * @param curies
1168
1225
  */
1169
-
1170
1226
  /**
1171
1227
  * @param relationship
1172
1228
  * @param curies
1173
1229
  */
1174
- function deCurie (relationship, curies) {
1175
- // we can either look in the rel for ':' and try to convert if it exists, but then we'll be trying to covert almost
1176
- // everything because none standard rels typically start with 'http:' or 'https:'.
1177
- // otherwise we can iterate over all the curies and try to replace. Seems inefficient.
1178
- // Going with option 1 for now.
1179
- // ⚠️ NOTE TO SELF: never use 'http' or 'https' as a curie name or hilarity will not ensue 😬
1180
- // ⚠️ ALSO NOTE TO SELF: never use ':' in a curie name or hilarity will not ensue 😬
1181
- // I'm going to assume that if there are multiple ':' characters, then we ignore all but the first
1182
- const splitRelationship = relationship.split(/:(.+)/);
1183
- if (splitRelationship.length > 1) {
1184
- const [curieName, curieRemainder] = splitRelationship;
1185
- const rval = curies[curieName]
1186
- ? URI.expand(curies[curieName], { rel: curieRemainder })
1187
- : relationship;
1188
- return rval
1189
- } else {
1190
- return relationship
1191
- }
1230
+ function deCurie(relationship, curies) {
1231
+ // we can either look in the rel for ':' and try to convert if it exists, but then we'll be trying to covert almost
1232
+ // everything because none standard rels typically start with 'http:' or 'https:'.
1233
+ // otherwise we can iterate over all the curies and try to replace. Seems inefficient.
1234
+ // Going with option 1 for now.
1235
+ // ⚠️ NOTE TO SELF: never use 'http' or 'https' as a curie name or hilarity will not ensue 😬
1236
+ // ⚠️ ALSO NOTE TO SELF: never use ':' in a curie name or hilarity will not ensue 😬
1237
+ // I'm going to assume that if there are multiple ':' characters, then we ignore all but the first
1238
+ var splitRelationship = relationship.split(/:(.+)/);
1239
+ if (splitRelationship.length > 1) {
1240
+ var _a = __read(splitRelationship, 2), curieName = _a[0], curieRemainder = _a[1];
1241
+ var rval = curies[curieName]
1242
+ ? URI.expand(curies[curieName], { rel: curieRemainder })
1243
+ : relationship;
1244
+ return rval;
1245
+ }
1246
+ else {
1247
+ return relationship;
1248
+ }
1192
1249
  }
1193
1250
 
1194
1251
  /**
@@ -1197,10 +1254,10 @@ function deCurie (relationship, curies) {
1197
1254
  * @param curies
1198
1255
  */
1199
1256
  function mapHalLinkToOperation(relationship, link, curies) {
1200
- // we don't need to copy `templated` across, because when we invoke an operation, we always
1201
- // assume it's a template and expand it with the passed parameters
1202
- const { href, templated, ...otherProperties } = link;
1203
- return new Operation({ rel: deCurie(relationship, curies), uri: href, ...otherProperties })
1257
+ // we don't need to copy `templated` across, because when we invoke an operation, we always
1258
+ // assume it's a template and expand it with the passed parameters
1259
+ var href = link.href; link.templated; var otherProperties = __rest(link, ["href", "templated"]);
1260
+ return new Operation(__assign({ rel: deCurie(relationship, curies), uri: href }, otherProperties));
1204
1261
  }
1205
1262
 
1206
1263
  /**
@@ -1274,412 +1331,424 @@ function halHandler(response, content) {
1274
1331
  return operations;
1275
1332
  }
1276
1333
 
1277
- var COMPATIBLE_ENCODING_PATTERN = /^utf-?8|ascii|utf-?16-?le|ucs-?2|base-?64|latin-?1$/i;
1278
- var WS_TRIM_PATTERN = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
1279
- var WS_CHAR_PATTERN = /\s|\uFEFF|\xA0/;
1280
- var WS_FOLD_PATTERN = /\r?\n[\x20\x09]+/g;
1281
- var DELIMITER_PATTERN = /[;,"]/;
1282
- var WS_DELIMITER_PATTERN = /[;,"]|\s/;
1283
-
1284
- /**
1285
- * Token character pattern
1286
- * @type {RegExp}
1287
- * @see https://tools.ietf.org/html/rfc7230#section-3.2.6
1288
- */
1289
- var TOKEN_PATTERN = /^[!#$%&'*+\-\.^_`|~\da-zA-Z]+$/;
1290
-
1291
- var STATE = {
1292
- IDLE: 1 << 0,
1293
- URI: 1 << 1,
1294
- ATTR: 1 << 2,
1295
- };
1296
-
1297
- function trim( value ) {
1298
- return value.replace( WS_TRIM_PATTERN, '' )
1299
- }
1300
-
1301
- function hasWhitespace( value ) {
1302
- return WS_CHAR_PATTERN.test( value )
1303
- }
1304
-
1305
- function skipWhitespace( value, offset ) {
1306
- while( hasWhitespace( value[offset] ) ) {
1307
- offset++;
1308
- }
1309
- return offset
1310
- }
1311
-
1312
- function needsQuotes( value ) {
1313
- return WS_DELIMITER_PATTERN.test( value ) ||
1314
- !TOKEN_PATTERN.test( value )
1315
- }
1316
-
1317
- /**
1318
- * Shallow compares two objects to check if their properties match.
1319
- * @param {object} object1 First object to compare.
1320
- * @param {object} object2 Second object to compare.
1321
- * @returns {boolean} Do the objects have matching properties.
1322
- */
1323
- function shallowCompareObjects( object1, object2 ) {
1324
- return (
1325
- Object.keys( object1 ).length === Object.keys( object2 ).length &&
1326
- Object.keys( object1 ).every(
1327
- ( key ) => key in object2 && object1[ key ] === object2[ key ]
1328
- )
1329
- );
1330
- }
1331
-
1332
- class Link {
1333
-
1334
- /**
1335
- * Link
1336
- * @constructor
1337
- * @param {String} [value]
1338
- * @returns {Link}
1339
- */
1340
- constructor( value ) {
1334
+ var link;
1335
+ var hasRequiredLink;
1341
1336
 
1342
- /** @type {Array} URI references */
1343
- this.refs = [];
1337
+ function requireLink () {
1338
+ if (hasRequiredLink) return link;
1339
+ hasRequiredLink = 1;
1344
1340
 
1345
- if( value ) {
1346
- this.parse( value );
1347
- }
1341
+ var COMPATIBLE_ENCODING_PATTERN = /^utf-?8|ascii|utf-?16-?le|ucs-?2|base-?64|latin-?1$/i;
1342
+ var WS_TRIM_PATTERN = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
1343
+ var WS_CHAR_PATTERN = /\s|\uFEFF|\xA0/;
1344
+ var WS_FOLD_PATTERN = /\r?\n[\x20\x09]+/g;
1345
+ var DELIMITER_PATTERN = /[;,"]/;
1346
+ var WS_DELIMITER_PATTERN = /[;,"]|\s/;
1348
1347
 
1349
- }
1348
+ /**
1349
+ * Token character pattern
1350
+ * @type {RegExp}
1351
+ * @see https://tools.ietf.org/html/rfc7230#section-3.2.6
1352
+ */
1353
+ var TOKEN_PATTERN = /^[!#$%&'*+\-\.^_`|~\da-zA-Z]+$/;
1350
1354
 
1351
- /**
1352
- * Get refs with given relation type
1353
- * @param {String} value
1354
- * @returns {Array<Object>}
1355
- */
1356
- rel( value ) {
1355
+ var STATE = {
1356
+ IDLE: 1 << 0,
1357
+ URI: 1 << 1,
1358
+ ATTR: 1 << 2,
1359
+ };
1357
1360
 
1358
- var links = [];
1359
- var type = value.toLowerCase();
1361
+ function trim( value ) {
1362
+ return value.replace( WS_TRIM_PATTERN, '' )
1363
+ }
1360
1364
 
1361
- for( var i = 0; i < this.refs.length; i++ ) {
1362
- if( typeof this.refs[ i ].rel === 'string' && this.refs[ i ].rel.toLowerCase() === type ) {
1363
- links.push( this.refs[ i ] );
1364
- }
1365
- }
1365
+ function hasWhitespace( value ) {
1366
+ return WS_CHAR_PATTERN.test( value )
1367
+ }
1366
1368
 
1367
- return links
1369
+ function skipWhitespace( value, offset ) {
1370
+ while( hasWhitespace( value[offset] ) ) {
1371
+ offset++;
1372
+ }
1373
+ return offset
1374
+ }
1368
1375
 
1369
- }
1376
+ function needsQuotes( value ) {
1377
+ return WS_DELIMITER_PATTERN.test( value ) ||
1378
+ !TOKEN_PATTERN.test( value )
1379
+ }
1370
1380
 
1371
- /**
1372
- * Get refs where given attribute has a given value
1373
- * @param {String} attr
1374
- * @param {String} value
1375
- * @returns {Array<Object>}
1376
- */
1377
- get( attr, value ) {
1381
+ /**
1382
+ * Shallow compares two objects to check if their properties match.
1383
+ * @param {object} object1 First object to compare.
1384
+ * @param {object} object2 Second object to compare.
1385
+ * @returns {boolean} Do the objects have matching properties.
1386
+ */
1387
+ function shallowCompareObjects( object1, object2 ) {
1388
+ return (
1389
+ Object.keys( object1 ).length === Object.keys( object2 ).length &&
1390
+ Object.keys( object1 ).every(
1391
+ ( key ) => key in object2 && object1[ key ] === object2[ key ]
1392
+ )
1393
+ );
1394
+ }
1378
1395
 
1379
- attr = attr.toLowerCase();
1380
- value = value.toLowerCase();
1396
+ class Link {
1381
1397
 
1382
- var links = [];
1398
+ /**
1399
+ * Link
1400
+ * @constructor
1401
+ * @param {String} [value]
1402
+ * @returns {Link}
1403
+ */
1404
+ constructor( value ) {
1383
1405
 
1384
- for( var i = 0; i < this.refs.length; i++ ) {
1385
- if( typeof this.refs[ i ][ attr ] === 'string' && this.refs[ i ][ attr ].toLowerCase() === value ) {
1386
- links.push( this.refs[ i ] );
1387
- }
1388
- }
1406
+ /** @type {Array} URI references */
1407
+ this.refs = [];
1389
1408
 
1390
- return links
1409
+ if( value ) {
1410
+ this.parse( value );
1411
+ }
1391
1412
 
1392
- }
1413
+ }
1393
1414
 
1394
- /** Sets a reference. */
1395
- set( link ) {
1396
- this.refs.push( link );
1397
- return this
1398
- }
1415
+ /**
1416
+ * Get refs with given relation type
1417
+ * @param {String} value
1418
+ * @returns {Array<Object>}
1419
+ */
1420
+ rel( value ) {
1399
1421
 
1400
- /**
1401
- * Sets a reference if a reference with similar properties isn’t already set.
1402
- */
1403
- setUnique( link ) {
1422
+ var links = [];
1423
+ var type = value.toLowerCase();
1424
+
1425
+ for( var i = 0; i < this.refs.length; i++ ) {
1426
+ if( typeof this.refs[ i ].rel === 'string' && this.refs[ i ].rel.toLowerCase() === type ) {
1427
+ links.push( this.refs[ i ] );
1428
+ }
1429
+ }
1430
+
1431
+ return links
1432
+
1433
+ }
1434
+
1435
+ /**
1436
+ * Get refs where given attribute has a given value
1437
+ * @param {String} attr
1438
+ * @param {String} value
1439
+ * @returns {Array<Object>}
1440
+ */
1441
+ get( attr, value ) {
1442
+
1443
+ attr = attr.toLowerCase();
1444
+ value = value.toLowerCase();
1445
+
1446
+ var links = [];
1447
+
1448
+ for( var i = 0; i < this.refs.length; i++ ) {
1449
+ if( typeof this.refs[ i ][ attr ] === 'string' && this.refs[ i ][ attr ].toLowerCase() === value ) {
1450
+ links.push( this.refs[ i ] );
1451
+ }
1452
+ }
1453
+
1454
+ return links
1455
+
1456
+ }
1457
+
1458
+ /** Sets a reference. */
1459
+ set( link ) {
1460
+ this.refs.push( link );
1461
+ return this
1462
+ }
1463
+
1464
+ /**
1465
+ * Sets a reference if a reference with similar properties isn’t already set.
1466
+ */
1467
+ setUnique( link ) {
1468
+
1469
+ if( !this.refs.some(( ref ) => shallowCompareObjects( ref, link )) ) {
1470
+ this.refs.push( link );
1471
+ }
1472
+
1473
+ return this
1474
+
1475
+ }
1476
+
1477
+ has( attr, value ) {
1478
+
1479
+ attr = attr.toLowerCase();
1480
+ value = value.toLowerCase();
1481
+
1482
+ for( var i = 0; i < this.refs.length; i++ ) {
1483
+ if( typeof this.refs[ i ][ attr ] === 'string' && this.refs[ i ][ attr ].toLowerCase() === value ) {
1484
+ return true
1485
+ }
1486
+ }
1487
+
1488
+ return false
1489
+
1490
+ }
1491
+
1492
+ parse( value, offset ) {
1493
+
1494
+ offset = offset || 0;
1495
+ value = offset ? value.slice( offset ) : value;
1496
+
1497
+ // Trim & unfold folded lines
1498
+ value = trim( value ).replace( WS_FOLD_PATTERN, '' );
1499
+
1500
+ var state = STATE.IDLE;
1501
+ var length = value.length;
1502
+ var offset = 0;
1503
+ var ref = null;
1504
+
1505
+ while( offset < length ) {
1506
+ if( state === STATE.IDLE ) {
1507
+ if( hasWhitespace( value[offset] ) ) {
1508
+ offset++;
1509
+ continue
1510
+ } else if( value[offset] === '<' ) {
1511
+ if( ref != null ) {
1512
+ ref.rel != null ?
1513
+ this.refs.push( ...Link.expandRelations( ref ) ) :
1514
+ this.refs.push( ref );
1515
+ }
1516
+ var end = value.indexOf( '>', offset );
1517
+ if( end === -1 ) throw new Error( 'Expected end of URI delimiter at offset ' + offset )
1518
+ ref = { uri: value.slice( offset + 1, end ) };
1519
+ // this.refs.push( ref )
1520
+ offset = end;
1521
+ state = STATE.URI;
1522
+ } else {
1523
+ throw new Error( 'Unexpected character "' + value[offset] + '" at offset ' + offset )
1524
+ }
1525
+ offset++;
1526
+ } else if( state === STATE.URI ) {
1527
+ if( hasWhitespace( value[offset] ) ) {
1528
+ offset++;
1529
+ continue
1530
+ } else if( value[offset] === ';' ) {
1531
+ state = STATE.ATTR;
1532
+ offset++;
1533
+ } else if( value[offset] === ',' ) {
1534
+ state = STATE.IDLE;
1535
+ offset++;
1536
+ } else {
1537
+ throw new Error( 'Unexpected character "' + value[offset] + '" at offset ' + offset )
1538
+ }
1539
+ } else if( state === STATE.ATTR ) {
1540
+ if( value[offset] ===';' || hasWhitespace( value[offset] ) ) {
1541
+ offset++;
1542
+ continue
1543
+ }
1544
+ var end = value.indexOf( '=', offset );
1545
+ if( end === -1 ) end = value.indexOf( ';', offset );
1546
+ if( end === -1 ) end = value.length;
1547
+ var attr = trim( value.slice( offset, end ) ).toLowerCase();
1548
+ var attrValue = '';
1549
+ offset = end + 1;
1550
+ offset = skipWhitespace( value, offset );
1551
+ if( value[offset] === '"' ) {
1552
+ offset++;
1553
+ while( offset < length ) {
1554
+ if( value[offset] === '"' ) {
1555
+ offset++; break
1556
+ }
1557
+ if( value[offset] === '\\' ) {
1558
+ offset++;
1559
+ }
1560
+ attrValue += value[offset];
1561
+ offset++;
1562
+ }
1563
+ } else {
1564
+ var end = offset + 1;
1565
+ while( !DELIMITER_PATTERN.test( value[end] ) && end < length ) {
1566
+ end++;
1567
+ }
1568
+ attrValue = value.slice( offset, end );
1569
+ offset = end;
1570
+ }
1571
+ if( ref[ attr ] && Link.isSingleOccurenceAttr( attr ) ) ; else if( attr[ attr.length - 1 ] === '*' ) {
1572
+ ref[ attr ] = Link.parseExtendedValue( attrValue );
1573
+ } else {
1574
+ attrValue = attr === 'type' ?
1575
+ attrValue.toLowerCase() : attrValue;
1576
+ if( ref[ attr ] != null ) {
1577
+ if( Array.isArray( ref[ attr ] ) ) {
1578
+ ref[ attr ].push( attrValue );
1579
+ } else {
1580
+ ref[ attr ] = [ ref[ attr ], attrValue ];
1581
+ }
1582
+ } else {
1583
+ ref[ attr ] = attrValue;
1584
+ }
1585
+ }
1586
+ switch( value[offset] ) {
1587
+ case ',': state = STATE.IDLE; break
1588
+ case ';': state = STATE.ATTR; break
1589
+ }
1590
+ offset++;
1591
+ } else {
1592
+ throw new Error( 'Unknown parser state "' + state + '"' )
1593
+ }
1594
+ }
1595
+
1596
+ if( ref != null ) {
1597
+ ref.rel != null ?
1598
+ this.refs.push( ...Link.expandRelations( ref ) ) :
1599
+ this.refs.push( ref );
1600
+ }
1601
+
1602
+ ref = null;
1603
+
1604
+ return this
1605
+
1606
+ }
1607
+
1608
+ toString() {
1609
+
1610
+ var refs = [];
1611
+ var link = '';
1612
+ var ref = null;
1613
+
1614
+ for( var i = 0; i < this.refs.length; i++ ) {
1615
+ ref = this.refs[i];
1616
+ link = Object.keys( this.refs[i] ).reduce( function( link, attr ) {
1617
+ if( attr === 'uri' ) return link
1618
+ return link + '; ' + Link.formatAttribute( attr, ref[ attr ] )
1619
+ }, '<' + ref.uri + '>' );
1620
+ refs.push( link );
1621
+ }
1622
+
1623
+ return refs.join( ', ' )
1624
+
1625
+ }
1404
1626
 
1405
- if( !this.refs.some(( ref ) => shallowCompareObjects( ref, link )) ) {
1406
- this.refs.push( link );
1407
- }
1627
+ }
1408
1628
 
1409
- return this
1629
+ /**
1630
+ * Determines whether an encoding can be
1631
+ * natively handled with a `Buffer`
1632
+ * @param {String} value
1633
+ * @returns {Boolean}
1634
+ */
1635
+ Link.isCompatibleEncoding = function( value ) {
1636
+ return COMPATIBLE_ENCODING_PATTERN.test( value )
1637
+ };
1410
1638
 
1411
- }
1639
+ Link.parse = function( value, offset ) {
1640
+ return new Link().parse( value, offset )
1641
+ };
1412
1642
 
1413
- has( attr, value ) {
1643
+ Link.isSingleOccurenceAttr = function( attr ) {
1644
+ return attr === 'rel' || attr === 'type' || attr === 'media' ||
1645
+ attr === 'title' || attr === 'title*'
1646
+ };
1414
1647
 
1415
- attr = attr.toLowerCase();
1416
- value = value.toLowerCase();
1648
+ Link.isTokenAttr = function( attr ) {
1649
+ return attr === 'rel' || attr === 'type' || attr === 'anchor'
1650
+ };
1417
1651
 
1418
- for( var i = 0; i < this.refs.length; i++ ) {
1419
- if( typeof this.refs[ i ][ attr ] === 'string' && this.refs[ i ][ attr ].toLowerCase() === value ) {
1420
- return true
1421
- }
1422
- }
1652
+ Link.escapeQuotes = function( value ) {
1653
+ return value.replace( /"/g, '\\"' )
1654
+ };
1423
1655
 
1424
- return false
1425
-
1426
- }
1427
-
1428
- parse( value, offset ) {
1429
-
1430
- offset = offset || 0;
1431
- value = offset ? value.slice( offset ) : value;
1432
-
1433
- // Trim & unfold folded lines
1434
- value = trim( value ).replace( WS_FOLD_PATTERN, '' );
1435
-
1436
- var state = STATE.IDLE;
1437
- var length = value.length;
1438
- var offset = 0;
1439
- var ref = null;
1440
-
1441
- while( offset < length ) {
1442
- if( state === STATE.IDLE ) {
1443
- if( hasWhitespace( value[offset] ) ) {
1444
- offset++;
1445
- continue
1446
- } else if( value[offset] === '<' ) {
1447
- if( ref != null ) {
1448
- ref.rel != null ?
1449
- this.refs.push( ...Link.expandRelations( ref ) ) :
1450
- this.refs.push( ref );
1451
- }
1452
- var end = value.indexOf( '>', offset );
1453
- if( end === -1 ) throw new Error( 'Expected end of URI delimiter at offset ' + offset )
1454
- ref = { uri: value.slice( offset + 1, end ) };
1455
- // this.refs.push( ref )
1456
- offset = end;
1457
- state = STATE.URI;
1458
- } else {
1459
- throw new Error( 'Unexpected character "' + value[offset] + '" at offset ' + offset )
1460
- }
1461
- offset++;
1462
- } else if( state === STATE.URI ) {
1463
- if( hasWhitespace( value[offset] ) ) {
1464
- offset++;
1465
- continue
1466
- } else if( value[offset] === ';' ) {
1467
- state = STATE.ATTR;
1468
- offset++;
1469
- } else if( value[offset] === ',' ) {
1470
- state = STATE.IDLE;
1471
- offset++;
1472
- } else {
1473
- throw new Error( 'Unexpected character "' + value[offset] + '" at offset ' + offset )
1474
- }
1475
- } else if( state === STATE.ATTR ) {
1476
- if( value[offset] ===';' || hasWhitespace( value[offset] ) ) {
1477
- offset++;
1478
- continue
1479
- }
1480
- var end = value.indexOf( '=', offset );
1481
- if( end === -1 ) end = value.indexOf( ';', offset );
1482
- if( end === -1 ) end = value.length;
1483
- var attr = trim( value.slice( offset, end ) ).toLowerCase();
1484
- var attrValue = '';
1485
- offset = end + 1;
1486
- offset = skipWhitespace( value, offset );
1487
- if( value[offset] === '"' ) {
1488
- offset++;
1489
- while( offset < length ) {
1490
- if( value[offset] === '"' ) {
1491
- offset++; break
1492
- }
1493
- if( value[offset] === '\\' ) {
1494
- offset++;
1495
- }
1496
- attrValue += value[offset];
1497
- offset++;
1498
- }
1499
- } else {
1500
- var end = offset + 1;
1501
- while( !DELIMITER_PATTERN.test( value[end] ) && end < length ) {
1502
- end++;
1503
- }
1504
- attrValue = value.slice( offset, end );
1505
- offset = end;
1506
- }
1507
- if( ref[ attr ] && Link.isSingleOccurenceAttr( attr ) ) ; else if( attr[ attr.length - 1 ] === '*' ) {
1508
- ref[ attr ] = Link.parseExtendedValue( attrValue );
1509
- } else {
1510
- attrValue = attr === 'type' ?
1511
- attrValue.toLowerCase() : attrValue;
1512
- if( ref[ attr ] != null ) {
1513
- if( Array.isArray( ref[ attr ] ) ) {
1514
- ref[ attr ].push( attrValue );
1515
- } else {
1516
- ref[ attr ] = [ ref[ attr ], attrValue ];
1517
- }
1518
- } else {
1519
- ref[ attr ] = attrValue;
1520
- }
1521
- }
1522
- switch( value[offset] ) {
1523
- case ',': state = STATE.IDLE; break
1524
- case ';': state = STATE.ATTR; break
1525
- }
1526
- offset++;
1527
- } else {
1528
- throw new Error( 'Unknown parser state "' + state + '"' )
1529
- }
1530
- }
1656
+ Link.expandRelations = function( ref ) {
1657
+ var rels = ref.rel.split( ' ' );
1658
+ return rels.map( function( rel ) {
1659
+ var value = Object.assign( {}, ref );
1660
+ value.rel = rel;
1661
+ return value
1662
+ })
1663
+ };
1531
1664
 
1532
- if( ref != null ) {
1533
- ref.rel != null ?
1534
- this.refs.push( ...Link.expandRelations( ref ) ) :
1535
- this.refs.push( ref );
1536
- }
1665
+ /**
1666
+ * Parses an extended value and attempts to decode it
1667
+ * @internal
1668
+ * @param {String} value
1669
+ * @return {Object}
1670
+ */
1671
+ Link.parseExtendedValue = function( value ) {
1672
+ var parts = /([^']+)?(?:'([^']*)')?(.+)/.exec( value );
1673
+ return {
1674
+ language: parts[2].toLowerCase(),
1675
+ encoding: Link.isCompatibleEncoding( parts[1] ) ?
1676
+ null : parts[1].toLowerCase(),
1677
+ value: Link.isCompatibleEncoding( parts[1] ) ?
1678
+ decodeURIComponent( parts[3] ) : parts[3]
1679
+ }
1680
+ };
1537
1681
 
1538
- ref = null;
1682
+ /**
1683
+ * Format a given extended attribute and it's value
1684
+ * @param {String} attr
1685
+ * @param {Object} data
1686
+ * @return {String}
1687
+ */
1688
+ Link.formatExtendedAttribute = function( attr, data ) {
1539
1689
 
1540
- return this
1690
+ var encoding = ( data.encoding || 'utf-8' ).toUpperCase();
1691
+ var language = data.language || 'en';
1541
1692
 
1542
- }
1693
+ var encodedValue = '';
1543
1694
 
1544
- toString() {
1695
+ if( Buffer.isBuffer( data.value ) && Link.isCompatibleEncoding( encoding ) ) {
1696
+ encodedValue = data.value.toString( encoding );
1697
+ } else if( Buffer.isBuffer( data.value ) ) {
1698
+ encodedValue = data.value.toString( 'hex' )
1699
+ .replace( /[0-9a-f]{2}/gi, '%$1' );
1700
+ } else {
1701
+ encodedValue = encodeURIComponent( data.value );
1702
+ }
1545
1703
 
1546
- var refs = [];
1547
- var link = '';
1548
- var ref = null;
1704
+ return attr + '=' + encoding + '\'' +
1705
+ language + '\'' + encodedValue
1549
1706
 
1550
- for( var i = 0; i < this.refs.length; i++ ) {
1551
- ref = this.refs[i];
1552
- link = Object.keys( this.refs[i] ).reduce( function( link, attr ) {
1553
- if( attr === 'uri' ) return link
1554
- return link + '; ' + Link.formatAttribute( attr, ref[ attr ] )
1555
- }, '<' + ref.uri + '>' );
1556
- refs.push( link );
1557
- }
1707
+ };
1558
1708
 
1559
- return refs.join( ', ' )
1709
+ /**
1710
+ * Format a given attribute and it's value
1711
+ * @param {String} attr
1712
+ * @param {String|Object} value
1713
+ * @return {String}
1714
+ */
1715
+ Link.formatAttribute = function( attr, value ) {
1716
+
1717
+ if( Array.isArray( value ) ) {
1718
+ return value.map(( item ) => {
1719
+ return Link.formatAttribute( attr, item )
1720
+ }).join( '; ' )
1721
+ }
1722
+
1723
+ if( attr[ attr.length - 1 ] === '*' || typeof value !== 'string' ) {
1724
+ return Link.formatExtendedAttribute( attr, value )
1725
+ }
1726
+
1727
+ if( Link.isTokenAttr( attr ) ) {
1728
+ value = needsQuotes( value ) ?
1729
+ '"' + Link.escapeQuotes( value ) + '"' :
1730
+ Link.escapeQuotes( value );
1731
+ } else if( needsQuotes( value ) ) {
1732
+ value = encodeURIComponent( value );
1733
+ // We don't need to escape <SP> <,> <;> within quotes
1734
+ value = value
1735
+ .replace( /%20/g, ' ' )
1736
+ .replace( /%2C/g, ',' )
1737
+ .replace( /%3B/g, ';' );
1738
+
1739
+ value = '"' + value + '"';
1740
+ }
1741
+
1742
+ return attr + '=' + value
1560
1743
 
1561
- }
1744
+ };
1562
1745
 
1746
+ link = Link;
1747
+ return link;
1563
1748
  }
1564
1749
 
1565
- /**
1566
- * Determines whether an encoding can be
1567
- * natively handled with a `Buffer`
1568
- * @param {String} value
1569
- * @returns {Boolean}
1570
- */
1571
- Link.isCompatibleEncoding = function( value ) {
1572
- return COMPATIBLE_ENCODING_PATTERN.test( value )
1573
- };
1574
-
1575
- Link.parse = function( value, offset ) {
1576
- return new Link().parse( value, offset )
1577
- };
1578
-
1579
- Link.isSingleOccurenceAttr = function( attr ) {
1580
- return attr === 'rel' || attr === 'type' || attr === 'media' ||
1581
- attr === 'title' || attr === 'title*'
1582
- };
1583
-
1584
- Link.isTokenAttr = function( attr ) {
1585
- return attr === 'rel' || attr === 'type' || attr === 'anchor'
1586
- };
1587
-
1588
- Link.escapeQuotes = function( value ) {
1589
- return value.replace( /"/g, '\\"' )
1590
- };
1591
-
1592
- Link.expandRelations = function( ref ) {
1593
- var rels = ref.rel.split( ' ' );
1594
- return rels.map( function( rel ) {
1595
- var value = Object.assign( {}, ref );
1596
- value.rel = rel;
1597
- return value
1598
- })
1599
- };
1600
-
1601
- /**
1602
- * Parses an extended value and attempts to decode it
1603
- * @internal
1604
- * @param {String} value
1605
- * @return {Object}
1606
- */
1607
- Link.parseExtendedValue = function( value ) {
1608
- var parts = /([^']+)?(?:'([^']*)')?(.+)/.exec( value );
1609
- return {
1610
- language: parts[2].toLowerCase(),
1611
- encoding: Link.isCompatibleEncoding( parts[1] ) ?
1612
- null : parts[1].toLowerCase(),
1613
- value: Link.isCompatibleEncoding( parts[1] ) ?
1614
- decodeURIComponent( parts[3] ) : parts[3]
1615
- }
1616
- };
1617
-
1618
- /**
1619
- * Format a given extended attribute and it's value
1620
- * @param {String} attr
1621
- * @param {Object} data
1622
- * @return {String}
1623
- */
1624
- Link.formatExtendedAttribute = function( attr, data ) {
1625
-
1626
- var encoding = ( data.encoding || 'utf-8' ).toUpperCase();
1627
- var language = data.language || 'en';
1628
-
1629
- var encodedValue = '';
1630
-
1631
- if( Buffer.isBuffer( data.value ) && Link.isCompatibleEncoding( encoding ) ) {
1632
- encodedValue = data.value.toString( encoding );
1633
- } else if( Buffer.isBuffer( data.value ) ) {
1634
- encodedValue = data.value.toString( 'hex' )
1635
- .replace( /[0-9a-f]{2}/gi, '%$1' );
1636
- } else {
1637
- encodedValue = encodeURIComponent( data.value );
1638
- }
1639
-
1640
- return attr + '=' + encoding + '\'' +
1641
- language + '\'' + encodedValue
1642
-
1643
- };
1644
-
1645
- /**
1646
- * Format a given attribute and it's value
1647
- * @param {String} attr
1648
- * @param {String|Object} value
1649
- * @return {String}
1650
- */
1651
- Link.formatAttribute = function( attr, value ) {
1652
-
1653
- if( Array.isArray( value ) ) {
1654
- return value.map(( item ) => {
1655
- return Link.formatAttribute( attr, item )
1656
- }).join( '; ' )
1657
- }
1658
-
1659
- if( attr[ attr.length - 1 ] === '*' || typeof value !== 'string' ) {
1660
- return Link.formatExtendedAttribute( attr, value )
1661
- }
1662
-
1663
- if( Link.isTokenAttr( attr ) ) {
1664
- value = needsQuotes( value ) ?
1665
- '"' + Link.escapeQuotes( value ) + '"' :
1666
- Link.escapeQuotes( value );
1667
- } else if( needsQuotes( value ) ) {
1668
- value = encodeURIComponent( value );
1669
- // We don't need to escape <SP> <,> <;> within quotes
1670
- value = value
1671
- .replace( /%20/g, ' ' )
1672
- .replace( /%2C/g, ',' )
1673
- .replace( /%3B/g, ';' );
1674
-
1675
- value = '"' + value + '"';
1676
- }
1677
-
1678
- return attr + '=' + value
1679
-
1680
- };
1681
-
1682
- var link = Link;
1750
+ var linkExports = requireLink();
1751
+ var LinkHeader = /*@__PURE__*/getDefaultExportFromCjs(linkExports);
1683
1752
 
1684
1753
  /**
1685
1754
  * @param response
@@ -1694,7 +1763,7 @@ function linkHeaderHandler(response, content, stopper) {
1694
1763
  */
1695
1764
  function parseHeader(linkHeader) {
1696
1765
  if (linkHeader) {
1697
- var links = link.parse(linkHeader);
1766
+ var links = LinkHeader.parse(linkHeader);
1698
1767
  return links.refs.map(function (reference) {
1699
1768
  var rel = reference.rel, uri = reference.uri, method = reference.method, accept = reference["accept*"], parameters = reference["params*"], otherProperties = __rest(reference, ["rel", "uri", "method", 'accept*', 'params*']);
1700
1769
  var parsedParameters = (parameters === null || parameters === void 0 ? void 0 : parameters.value)
@@ -1882,7 +1951,7 @@ var WayChaserResponse = /** @class */ (function () {
1882
1951
  this.fullContent = fullContent || content;
1883
1952
  this.content = content;
1884
1953
  this.operations = OperationArray.create();
1885
- var thisContext = flat({ this: content });
1954
+ var thisContext = flatten({ this: content });
1886
1955
  if (parentOperations && anchor && defaultOptions) {
1887
1956
  this.allOperations = parentOperations;
1888
1957
  try {
@@ -1957,7 +2026,7 @@ var WayChaserResponse = /** @class */ (function () {
1957
2026
  * @throws {WayChaserProblem}
1958
2027
  */
1959
2028
  WayChaserResponse.create = function (baseResponse, content, defaultOptions, mergedOptions) {
1960
- if (content instanceof ProblemDocument_1) {
2029
+ if (content instanceof libExports.ProblemDocument) {
1961
2030
  throw new WayChaserProblem({
1962
2031
  response: new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions: defaultOptions, baseResponse: baseResponse, content: content, parameters: mergedOptions.parameters }),
1963
2032
  problem: content,
@@ -2253,12 +2322,12 @@ function _waychaser(uriOrRequest, defaultOptions, options) {
2253
2322
  case 4:
2254
2323
  error_1 = _l.sent();
2255
2324
  response = new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions: defaultOptions, baseResponse: baseResponse, content: error_1, parameters: mergedOptions.parameters });
2256
- wayChaserProblem = error_1 instanceof ProblemDocument_1 ? new WayChaserProblem({
2325
+ wayChaserProblem = error_1 instanceof libExports.ProblemDocument ? new WayChaserProblem({
2257
2326
  response: response,
2258
2327
  problem: error_1,
2259
2328
  }) : new WayChaserProblem({
2260
2329
  response: response,
2261
- problem: new ProblemDocument_1({
2330
+ problem: new libExports.ProblemDocument({
2262
2331
  type: "https://waychaser.io/unexected-error",
2263
2332
  title: "An unexpected error occurred",
2264
2333
  error: error_1
@@ -2312,7 +2381,7 @@ function tryParseJson(content, contentType) {
2312
2381
  return JSON.parse(content);
2313
2382
  }
2314
2383
  catch (error) {
2315
- throw new ProblemDocument_1({
2384
+ throw new libExports.ProblemDocument({
2316
2385
  type: "https://waychaser.io/invalid-json",
2317
2386
  title: "JSON response could not be parsed",
2318
2387
  detail: "The response document with content type '".concat(contentType, "' could not be parsed as json"),
@@ -2348,7 +2417,7 @@ var wayChaserDefaults = {
2348
2417
  if (contentType === null || contentType === void 0 ? void 0 : contentType.endsWith('json')) {
2349
2418
  jsonContent = tryParseJson(content, contentType);
2350
2419
  if (contentType === 'application/problem+json') {
2351
- throw Object.assign(new ProblemDocument_1(jsonContent), jsonContent);
2420
+ throw Object.assign(new libExports.ProblemDocument(jsonContent), jsonContent);
2352
2421
  }
2353
2422
  else {
2354
2423
  return [2 /*return*/, jsonContent];