@mountainpass/waychaser 5.0.14 → 5.0.16

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,347 +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
- *
748
- * @param data properties to assign to the new instance
749
- */
750
- constructor(data) {
751
- Object.assign(this, data);
752
- }
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;
753
808
  }
754
- ProblemDocument_1 = lib.ProblemDocument = ProblemDocument;
809
+
810
+ var libExports = requireLib();
755
811
 
756
812
  var Operation = /** @class */ (function () {
757
813
  function Operation(_a) {
@@ -784,7 +840,7 @@ var InvocableOperation = /** @class */ (function (_super) {
784
840
  InvocableOperation.prototype.invokeAsFragment = function (parameters, validator) {
785
841
  if (this.uri.startsWith('#/')) {
786
842
  var anchor = this.expandUrl(parameters).toString();
787
- 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));
788
844
  if (fragmentContent === undefined) {
789
845
  return undefined;
790
846
  }
@@ -832,7 +888,7 @@ var InvocableOperation = /** @class */ (function (_super) {
832
888
  if (keys.length !== 0) {
833
889
  var field = currentUriParameters[keys[0]];
834
890
  var parentUri = currentUri.slice(1, currentUri.indexOf(field) - 1);
835
- var parent_1 = parentUri === '' ? response.content : jsonpointer.get(response.content, parentUri);
891
+ var parent_1 = parentUri === '' ? response.content : pointer.get(response.content, parentUri);
836
892
  if (parent_1) {
837
893
  var indices = Array.isArray(parent_1) ? __spreadArray([], __read(Array.from({ length: parent_1.length }).keys()), false) : Object.keys(parent_1);
838
894
  return indices.flatMap(function (index) {
@@ -844,7 +900,7 @@ var InvocableOperation = /** @class */ (function (_super) {
844
900
  else {
845
901
  throw new WayChaserProblem({
846
902
  response: this.response,
847
- problem: new ProblemDocument_1({
903
+ problem: new libExports.ProblemDocument({
848
904
  type: "https://waychaser.io/fragment-uri-error",
849
905
  title: "The fragment URI does not match the content structure",
850
906
  uri: parentUri, content: response.content,
@@ -919,7 +975,7 @@ var InvocableOperation = /** @class */ (function (_super) {
919
975
  encodedContent = JSON.stringify(body);
920
976
  break;
921
977
  case 'multipart/form-data':
922
- encodedContent = new browser();
978
+ encodedContent = new FormData();
923
979
  for (name_1 in body) {
924
980
  encodedContent.append(name_1, body[name_1]);
925
981
  }
@@ -946,7 +1002,7 @@ var InvocableOperation = /** @class */ (function (_super) {
946
1002
  return invokeUrl;
947
1003
  };
948
1004
  InvocableOperation.prototype.expandUrl = function (parameters) {
949
- return URI.expand(this.uri, flat(parameters || {}));
1005
+ return URI.expand(this.uri, flatten(parameters || {}));
950
1006
  };
951
1007
  return InvocableOperation;
952
1008
  }(Operation));
@@ -1158,38 +1214,38 @@ function parseOperations(_a) {
1158
1214
  return expandedOperations;
1159
1215
  }
1160
1216
 
1161
- const MediaTypes = {
1162
- HAL: 'application/hal+json',
1163
- SIREN: 'application/vnd.siren+json'
1217
+ var MediaTypes = {
1218
+ HAL: 'application/hal+json',
1219
+ SIREN: 'application/vnd.siren+json'
1164
1220
  };
1165
1221
 
1166
1222
  /**
1167
1223
  * @param relationship
1168
1224
  * @param curies
1169
1225
  */
1170
-
1171
1226
  /**
1172
1227
  * @param relationship
1173
1228
  * @param curies
1174
1229
  */
1175
- function deCurie (relationship, curies) {
1176
- // we can either look in the rel for ':' and try to convert if it exists, but then we'll be trying to covert almost
1177
- // everything because none standard rels typically start with 'http:' or 'https:'.
1178
- // otherwise we can iterate over all the curies and try to replace. Seems inefficient.
1179
- // Going with option 1 for now.
1180
- // ⚠️ NOTE TO SELF: never use 'http' or 'https' as a curie name or hilarity will not ensue 😬
1181
- // ⚠️ ALSO NOTE TO SELF: never use ':' in a curie name or hilarity will not ensue 😬
1182
- // I'm going to assume that if there are multiple ':' characters, then we ignore all but the first
1183
- const splitRelationship = relationship.split(/:(.+)/);
1184
- if (splitRelationship.length > 1) {
1185
- const [curieName, curieRemainder] = splitRelationship;
1186
- const rval = curies[curieName]
1187
- ? URI.expand(curies[curieName], { rel: curieRemainder })
1188
- : relationship;
1189
- return rval
1190
- } else {
1191
- return relationship
1192
- }
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
+ }
1193
1249
  }
1194
1250
 
1195
1251
  /**
@@ -1198,10 +1254,10 @@ function deCurie (relationship, curies) {
1198
1254
  * @param curies
1199
1255
  */
1200
1256
  function mapHalLinkToOperation(relationship, link, curies) {
1201
- // we don't need to copy `templated` across, because when we invoke an operation, we always
1202
- // assume it's a template and expand it with the passed parameters
1203
- const { href, templated, ...otherProperties } = link;
1204
- 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));
1205
1261
  }
1206
1262
 
1207
1263
  /**
@@ -1275,412 +1331,424 @@ function halHandler(response, content) {
1275
1331
  return operations;
1276
1332
  }
1277
1333
 
1278
- var COMPATIBLE_ENCODING_PATTERN = /^utf-?8|ascii|utf-?16-?le|ucs-?2|base-?64|latin-?1$/i;
1279
- var WS_TRIM_PATTERN = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
1280
- var WS_CHAR_PATTERN = /\s|\uFEFF|\xA0/;
1281
- var WS_FOLD_PATTERN = /\r?\n[\x20\x09]+/g;
1282
- var DELIMITER_PATTERN = /[;,"]/;
1283
- var WS_DELIMITER_PATTERN = /[;,"]|\s/;
1284
-
1285
- /**
1286
- * Token character pattern
1287
- * @type {RegExp}
1288
- * @see https://tools.ietf.org/html/rfc7230#section-3.2.6
1289
- */
1290
- var TOKEN_PATTERN = /^[!#$%&'*+\-\.^_`|~\da-zA-Z]+$/;
1291
-
1292
- var STATE = {
1293
- IDLE: 1 << 0,
1294
- URI: 1 << 1,
1295
- ATTR: 1 << 2,
1296
- };
1297
-
1298
- function trim( value ) {
1299
- return value.replace( WS_TRIM_PATTERN, '' )
1300
- }
1301
-
1302
- function hasWhitespace( value ) {
1303
- return WS_CHAR_PATTERN.test( value )
1304
- }
1305
-
1306
- function skipWhitespace( value, offset ) {
1307
- while( hasWhitespace( value[offset] ) ) {
1308
- offset++;
1309
- }
1310
- return offset
1311
- }
1312
-
1313
- function needsQuotes( value ) {
1314
- return WS_DELIMITER_PATTERN.test( value ) ||
1315
- !TOKEN_PATTERN.test( value )
1316
- }
1317
-
1318
- /**
1319
- * Shallow compares two objects to check if their properties match.
1320
- * @param {object} object1 First object to compare.
1321
- * @param {object} object2 Second object to compare.
1322
- * @returns {boolean} Do the objects have matching properties.
1323
- */
1324
- function shallowCompareObjects( object1, object2 ) {
1325
- return (
1326
- Object.keys( object1 ).length === Object.keys( object2 ).length &&
1327
- Object.keys( object1 ).every(
1328
- ( key ) => key in object2 && object1[ key ] === object2[ key ]
1329
- )
1330
- );
1331
- }
1332
-
1333
- class Link {
1334
-
1335
- /**
1336
- * Link
1337
- * @constructor
1338
- * @param {String} [value]
1339
- * @returns {Link}
1340
- */
1341
- constructor( value ) {
1334
+ var link;
1335
+ var hasRequiredLink;
1342
1336
 
1343
- /** @type {Array} URI references */
1344
- this.refs = [];
1337
+ function requireLink () {
1338
+ if (hasRequiredLink) return link;
1339
+ hasRequiredLink = 1;
1345
1340
 
1346
- if( value ) {
1347
- this.parse( value );
1348
- }
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/;
1349
1347
 
1350
- }
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]+$/;
1351
1354
 
1352
- /**
1353
- * Get refs with given relation type
1354
- * @param {String} value
1355
- * @returns {Array<Object>}
1356
- */
1357
- rel( value ) {
1355
+ var STATE = {
1356
+ IDLE: 1 << 0,
1357
+ URI: 1 << 1,
1358
+ ATTR: 1 << 2,
1359
+ };
1358
1360
 
1359
- var links = [];
1360
- var type = value.toLowerCase();
1361
+ function trim( value ) {
1362
+ return value.replace( WS_TRIM_PATTERN, '' )
1363
+ }
1361
1364
 
1362
- for( var i = 0; i < this.refs.length; i++ ) {
1363
- if( typeof this.refs[ i ].rel === 'string' && this.refs[ i ].rel.toLowerCase() === type ) {
1364
- links.push( this.refs[ i ] );
1365
- }
1366
- }
1365
+ function hasWhitespace( value ) {
1366
+ return WS_CHAR_PATTERN.test( value )
1367
+ }
1367
1368
 
1368
- return links
1369
+ function skipWhitespace( value, offset ) {
1370
+ while( hasWhitespace( value[offset] ) ) {
1371
+ offset++;
1372
+ }
1373
+ return offset
1374
+ }
1369
1375
 
1370
- }
1376
+ function needsQuotes( value ) {
1377
+ return WS_DELIMITER_PATTERN.test( value ) ||
1378
+ !TOKEN_PATTERN.test( value )
1379
+ }
1371
1380
 
1372
- /**
1373
- * Get refs where given attribute has a given value
1374
- * @param {String} attr
1375
- * @param {String} value
1376
- * @returns {Array<Object>}
1377
- */
1378
- 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
+ }
1379
1395
 
1380
- attr = attr.toLowerCase();
1381
- value = value.toLowerCase();
1396
+ class Link {
1382
1397
 
1383
- var links = [];
1398
+ /**
1399
+ * Link
1400
+ * @constructor
1401
+ * @param {String} [value]
1402
+ * @returns {Link}
1403
+ */
1404
+ constructor( value ) {
1384
1405
 
1385
- for( var i = 0; i < this.refs.length; i++ ) {
1386
- if( typeof this.refs[ i ][ attr ] === 'string' && this.refs[ i ][ attr ].toLowerCase() === value ) {
1387
- links.push( this.refs[ i ] );
1388
- }
1389
- }
1406
+ /** @type {Array} URI references */
1407
+ this.refs = [];
1390
1408
 
1391
- return links
1409
+ if( value ) {
1410
+ this.parse( value );
1411
+ }
1392
1412
 
1393
- }
1413
+ }
1394
1414
 
1395
- /** Sets a reference. */
1396
- set( link ) {
1397
- this.refs.push( link );
1398
- return this
1399
- }
1415
+ /**
1416
+ * Get refs with given relation type
1417
+ * @param {String} value
1418
+ * @returns {Array<Object>}
1419
+ */
1420
+ rel( value ) {
1400
1421
 
1401
- /**
1402
- * Sets a reference if a reference with similar properties isn’t already set.
1403
- */
1404
- 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
+ }
1405
1626
 
1406
- if( !this.refs.some(( ref ) => shallowCompareObjects( ref, link )) ) {
1407
- this.refs.push( link );
1408
- }
1627
+ }
1409
1628
 
1410
- 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
+ };
1411
1638
 
1412
- }
1639
+ Link.parse = function( value, offset ) {
1640
+ return new Link().parse( value, offset )
1641
+ };
1413
1642
 
1414
- has( attr, value ) {
1643
+ Link.isSingleOccurenceAttr = function( attr ) {
1644
+ return attr === 'rel' || attr === 'type' || attr === 'media' ||
1645
+ attr === 'title' || attr === 'title*'
1646
+ };
1415
1647
 
1416
- attr = attr.toLowerCase();
1417
- value = value.toLowerCase();
1648
+ Link.isTokenAttr = function( attr ) {
1649
+ return attr === 'rel' || attr === 'type' || attr === 'anchor'
1650
+ };
1418
1651
 
1419
- for( var i = 0; i < this.refs.length; i++ ) {
1420
- if( typeof this.refs[ i ][ attr ] === 'string' && this.refs[ i ][ attr ].toLowerCase() === value ) {
1421
- return true
1422
- }
1423
- }
1652
+ Link.escapeQuotes = function( value ) {
1653
+ return value.replace( /"/g, '\\"' )
1654
+ };
1424
1655
 
1425
- return false
1426
-
1427
- }
1428
-
1429
- parse( value, offset ) {
1430
-
1431
- offset = offset || 0;
1432
- value = offset ? value.slice( offset ) : value;
1433
-
1434
- // Trim & unfold folded lines
1435
- value = trim( value ).replace( WS_FOLD_PATTERN, '' );
1436
-
1437
- var state = STATE.IDLE;
1438
- var length = value.length;
1439
- var offset = 0;
1440
- var ref = null;
1441
-
1442
- while( offset < length ) {
1443
- if( state === STATE.IDLE ) {
1444
- if( hasWhitespace( value[offset] ) ) {
1445
- offset++;
1446
- continue
1447
- } else if( value[offset] === '<' ) {
1448
- if( ref != null ) {
1449
- ref.rel != null ?
1450
- this.refs.push( ...Link.expandRelations( ref ) ) :
1451
- this.refs.push( ref );
1452
- }
1453
- var end = value.indexOf( '>', offset );
1454
- if( end === -1 ) throw new Error( 'Expected end of URI delimiter at offset ' + offset )
1455
- ref = { uri: value.slice( offset + 1, end ) };
1456
- // this.refs.push( ref )
1457
- offset = end;
1458
- state = STATE.URI;
1459
- } else {
1460
- throw new Error( 'Unexpected character "' + value[offset] + '" at offset ' + offset )
1461
- }
1462
- offset++;
1463
- } else if( state === STATE.URI ) {
1464
- if( hasWhitespace( value[offset] ) ) {
1465
- offset++;
1466
- continue
1467
- } else if( value[offset] === ';' ) {
1468
- state = STATE.ATTR;
1469
- offset++;
1470
- } else if( value[offset] === ',' ) {
1471
- state = STATE.IDLE;
1472
- offset++;
1473
- } else {
1474
- throw new Error( 'Unexpected character "' + value[offset] + '" at offset ' + offset )
1475
- }
1476
- } else if( state === STATE.ATTR ) {
1477
- if( value[offset] ===';' || hasWhitespace( value[offset] ) ) {
1478
- offset++;
1479
- continue
1480
- }
1481
- var end = value.indexOf( '=', offset );
1482
- if( end === -1 ) end = value.indexOf( ';', offset );
1483
- if( end === -1 ) end = value.length;
1484
- var attr = trim( value.slice( offset, end ) ).toLowerCase();
1485
- var attrValue = '';
1486
- offset = end + 1;
1487
- offset = skipWhitespace( value, offset );
1488
- if( value[offset] === '"' ) {
1489
- offset++;
1490
- while( offset < length ) {
1491
- if( value[offset] === '"' ) {
1492
- offset++; break
1493
- }
1494
- if( value[offset] === '\\' ) {
1495
- offset++;
1496
- }
1497
- attrValue += value[offset];
1498
- offset++;
1499
- }
1500
- } else {
1501
- var end = offset + 1;
1502
- while( !DELIMITER_PATTERN.test( value[end] ) && end < length ) {
1503
- end++;
1504
- }
1505
- attrValue = value.slice( offset, end );
1506
- offset = end;
1507
- }
1508
- if( ref[ attr ] && Link.isSingleOccurenceAttr( attr ) ) ; else if( attr[ attr.length - 1 ] === '*' ) {
1509
- ref[ attr ] = Link.parseExtendedValue( attrValue );
1510
- } else {
1511
- attrValue = attr === 'type' ?
1512
- attrValue.toLowerCase() : attrValue;
1513
- if( ref[ attr ] != null ) {
1514
- if( Array.isArray( ref[ attr ] ) ) {
1515
- ref[ attr ].push( attrValue );
1516
- } else {
1517
- ref[ attr ] = [ ref[ attr ], attrValue ];
1518
- }
1519
- } else {
1520
- ref[ attr ] = attrValue;
1521
- }
1522
- }
1523
- switch( value[offset] ) {
1524
- case ',': state = STATE.IDLE; break
1525
- case ';': state = STATE.ATTR; break
1526
- }
1527
- offset++;
1528
- } else {
1529
- throw new Error( 'Unknown parser state "' + state + '"' )
1530
- }
1531
- }
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
+ };
1532
1664
 
1533
- if( ref != null ) {
1534
- ref.rel != null ?
1535
- this.refs.push( ...Link.expandRelations( ref ) ) :
1536
- this.refs.push( ref );
1537
- }
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
+ };
1538
1681
 
1539
- 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 ) {
1540
1689
 
1541
- return this
1690
+ var encoding = ( data.encoding || 'utf-8' ).toUpperCase();
1691
+ var language = data.language || 'en';
1542
1692
 
1543
- }
1693
+ var encodedValue = '';
1544
1694
 
1545
- 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
+ }
1546
1703
 
1547
- var refs = [];
1548
- var link = '';
1549
- var ref = null;
1704
+ return attr + '=' + encoding + '\'' +
1705
+ language + '\'' + encodedValue
1550
1706
 
1551
- for( var i = 0; i < this.refs.length; i++ ) {
1552
- ref = this.refs[i];
1553
- link = Object.keys( this.refs[i] ).reduce( function( link, attr ) {
1554
- if( attr === 'uri' ) return link
1555
- return link + '; ' + Link.formatAttribute( attr, ref[ attr ] )
1556
- }, '<' + ref.uri + '>' );
1557
- refs.push( link );
1558
- }
1707
+ };
1559
1708
 
1560
- 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
1561
1743
 
1562
- }
1744
+ };
1563
1745
 
1746
+ link = Link;
1747
+ return link;
1564
1748
  }
1565
1749
 
1566
- /**
1567
- * Determines whether an encoding can be
1568
- * natively handled with a `Buffer`
1569
- * @param {String} value
1570
- * @returns {Boolean}
1571
- */
1572
- Link.isCompatibleEncoding = function( value ) {
1573
- return COMPATIBLE_ENCODING_PATTERN.test( value )
1574
- };
1575
-
1576
- Link.parse = function( value, offset ) {
1577
- return new Link().parse( value, offset )
1578
- };
1579
-
1580
- Link.isSingleOccurenceAttr = function( attr ) {
1581
- return attr === 'rel' || attr === 'type' || attr === 'media' ||
1582
- attr === 'title' || attr === 'title*'
1583
- };
1584
-
1585
- Link.isTokenAttr = function( attr ) {
1586
- return attr === 'rel' || attr === 'type' || attr === 'anchor'
1587
- };
1588
-
1589
- Link.escapeQuotes = function( value ) {
1590
- return value.replace( /"/g, '\\"' )
1591
- };
1592
-
1593
- Link.expandRelations = function( ref ) {
1594
- var rels = ref.rel.split( ' ' );
1595
- return rels.map( function( rel ) {
1596
- var value = Object.assign( {}, ref );
1597
- value.rel = rel;
1598
- return value
1599
- })
1600
- };
1601
-
1602
- /**
1603
- * Parses an extended value and attempts to decode it
1604
- * @internal
1605
- * @param {String} value
1606
- * @return {Object}
1607
- */
1608
- Link.parseExtendedValue = function( value ) {
1609
- var parts = /([^']+)?(?:'([^']*)')?(.+)/.exec( value );
1610
- return {
1611
- language: parts[2].toLowerCase(),
1612
- encoding: Link.isCompatibleEncoding( parts[1] ) ?
1613
- null : parts[1].toLowerCase(),
1614
- value: Link.isCompatibleEncoding( parts[1] ) ?
1615
- decodeURIComponent( parts[3] ) : parts[3]
1616
- }
1617
- };
1618
-
1619
- /**
1620
- * Format a given extended attribute and it's value
1621
- * @param {String} attr
1622
- * @param {Object} data
1623
- * @return {String}
1624
- */
1625
- Link.formatExtendedAttribute = function( attr, data ) {
1626
-
1627
- var encoding = ( data.encoding || 'utf-8' ).toUpperCase();
1628
- var language = data.language || 'en';
1629
-
1630
- var encodedValue = '';
1631
-
1632
- if( Buffer.isBuffer( data.value ) && Link.isCompatibleEncoding( encoding ) ) {
1633
- encodedValue = data.value.toString( encoding );
1634
- } else if( Buffer.isBuffer( data.value ) ) {
1635
- encodedValue = data.value.toString( 'hex' )
1636
- .replace( /[0-9a-f]{2}/gi, '%$1' );
1637
- } else {
1638
- encodedValue = encodeURIComponent( data.value );
1639
- }
1640
-
1641
- return attr + '=' + encoding + '\'' +
1642
- language + '\'' + encodedValue
1643
-
1644
- };
1645
-
1646
- /**
1647
- * Format a given attribute and it's value
1648
- * @param {String} attr
1649
- * @param {String|Object} value
1650
- * @return {String}
1651
- */
1652
- Link.formatAttribute = function( attr, value ) {
1653
-
1654
- if( Array.isArray( value ) ) {
1655
- return value.map(( item ) => {
1656
- return Link.formatAttribute( attr, item )
1657
- }).join( '; ' )
1658
- }
1659
-
1660
- if( attr[ attr.length - 1 ] === '*' || typeof value !== 'string' ) {
1661
- return Link.formatExtendedAttribute( attr, value )
1662
- }
1663
-
1664
- if( Link.isTokenAttr( attr ) ) {
1665
- value = needsQuotes( value ) ?
1666
- '"' + Link.escapeQuotes( value ) + '"' :
1667
- Link.escapeQuotes( value );
1668
- } else if( needsQuotes( value ) ) {
1669
- value = encodeURIComponent( value );
1670
- // We don't need to escape <SP> <,> <;> within quotes
1671
- value = value
1672
- .replace( /%20/g, ' ' )
1673
- .replace( /%2C/g, ',' )
1674
- .replace( /%3B/g, ';' );
1675
-
1676
- value = '"' + value + '"';
1677
- }
1678
-
1679
- return attr + '=' + value
1680
-
1681
- };
1682
-
1683
- var link = Link;
1750
+ var linkExports = requireLink();
1751
+ var LinkHeader = /*@__PURE__*/getDefaultExportFromCjs(linkExports);
1684
1752
 
1685
1753
  /**
1686
1754
  * @param response
@@ -1695,7 +1763,7 @@ function linkHeaderHandler(response, content, stopper) {
1695
1763
  */
1696
1764
  function parseHeader(linkHeader) {
1697
1765
  if (linkHeader) {
1698
- var links = link.parse(linkHeader);
1766
+ var links = LinkHeader.parse(linkHeader);
1699
1767
  return links.refs.map(function (reference) {
1700
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*']);
1701
1769
  var parsedParameters = (parameters === null || parameters === void 0 ? void 0 : parameters.value)
@@ -1883,7 +1951,7 @@ var WayChaserResponse = /** @class */ (function () {
1883
1951
  this.fullContent = fullContent || content;
1884
1952
  this.content = content;
1885
1953
  this.operations = OperationArray.create();
1886
- var thisContext = flat({ this: content });
1954
+ var thisContext = flatten({ this: content });
1887
1955
  if (parentOperations && anchor && defaultOptions) {
1888
1956
  this.allOperations = parentOperations;
1889
1957
  try {
@@ -1958,7 +2026,7 @@ var WayChaserResponse = /** @class */ (function () {
1958
2026
  * @throws {WayChaserProblem}
1959
2027
  */
1960
2028
  WayChaserResponse.create = function (baseResponse, content, defaultOptions, mergedOptions) {
1961
- if (content instanceof ProblemDocument_1) {
2029
+ if (content instanceof libExports.ProblemDocument) {
1962
2030
  throw new WayChaserProblem({
1963
2031
  response: new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions: defaultOptions, baseResponse: baseResponse, content: content, parameters: mergedOptions.parameters }),
1964
2032
  problem: content,
@@ -2254,12 +2322,12 @@ function _waychaser(uriOrRequest, defaultOptions, options) {
2254
2322
  case 4:
2255
2323
  error_1 = _l.sent();
2256
2324
  response = new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions: defaultOptions, baseResponse: baseResponse, content: error_1, parameters: mergedOptions.parameters });
2257
- wayChaserProblem = error_1 instanceof ProblemDocument_1 ? new WayChaserProblem({
2325
+ wayChaserProblem = error_1 instanceof libExports.ProblemDocument ? new WayChaserProblem({
2258
2326
  response: response,
2259
2327
  problem: error_1,
2260
2328
  }) : new WayChaserProblem({
2261
2329
  response: response,
2262
- problem: new ProblemDocument_1({
2330
+ problem: new libExports.ProblemDocument({
2263
2331
  type: "https://waychaser.io/unexected-error",
2264
2332
  title: "An unexpected error occurred",
2265
2333
  error: error_1
@@ -2313,7 +2381,7 @@ function tryParseJson(content, contentType) {
2313
2381
  return JSON.parse(content);
2314
2382
  }
2315
2383
  catch (error) {
2316
- throw new ProblemDocument_1({
2384
+ throw new libExports.ProblemDocument({
2317
2385
  type: "https://waychaser.io/invalid-json",
2318
2386
  title: "JSON response could not be parsed",
2319
2387
  detail: "The response document with content type '".concat(contentType, "' could not be parsed as json"),
@@ -2349,7 +2417,7 @@ var wayChaserDefaults = {
2349
2417
  if (contentType === null || contentType === void 0 ? void 0 : contentType.endsWith('json')) {
2350
2418
  jsonContent = tryParseJson(content, contentType);
2351
2419
  if (contentType === 'application/problem+json') {
2352
- throw Object.assign(new ProblemDocument_1(jsonContent), jsonContent);
2420
+ throw Object.assign(new libExports.ProblemDocument(jsonContent), jsonContent);
2353
2421
  }
2354
2422
  else {
2355
2423
  return [2 /*return*/, jsonContent];