@augment-vir/common 13.1.0 → 13.2.1

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.
@@ -21,7 +21,7 @@ async function awaitedBlockingMap(input, callback) {
21
21
  }
22
22
  exports.awaitedBlockingMap = awaitedBlockingMap;
23
23
  async function awaitedFilter(arrayInput, filterCallback, options) {
24
- const callbackResults = (options === null || options === void 0 ? void 0 : options.blocking)
24
+ const callbackResults = options?.blocking
25
25
  ? await awaitedBlockingMap(arrayInput, filterCallback)
26
26
  : await Promise.all(arrayInput.map(filterCallback));
27
27
  return arrayInput.filter((originalValue, index) => !!callbackResults[index]);
@@ -55,7 +55,6 @@ function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps
55
55
  }
56
56
  }
57
57
  matchKeys.forEach((key) => {
58
- var _a;
59
58
  if (!(0, typed_has_property_1.typedHasProperty)(testThisOne, key)) {
60
59
  throw new Error(`test object does not have key "${String(key)}" from expected shape.`);
61
60
  }
@@ -65,13 +64,12 @@ function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps
65
64
  const testValue = testThisOne[key];
66
65
  const shouldMatch = compareToThisOne[key];
67
66
  if (!noCheckInnerValueOfTheseKeys[key]) {
68
- compareInnerValue(testValue, shouldMatch, throwKeyError, allowExtraProps, (_a = noCheckInnerValueOfTheseKeys[key]) !== null && _a !== void 0 ? _a : {});
67
+ compareInnerValue(testValue, shouldMatch, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys[key] ?? {});
69
68
  }
70
69
  });
71
70
  }
72
71
  exports.assertMatchesObjectShape = assertMatchesObjectShape;
73
72
  function compareInnerValue(testValue, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys) {
74
- var _a;
75
73
  const testType = typeof testValue;
76
74
  const shouldMatchType = typeof matchValue;
77
75
  if (testType !== shouldMatchType) {
@@ -81,7 +79,7 @@ function compareInnerValue(testValue, matchValue, throwKeyError, allowExtraProps
81
79
  if ((0, typed_has_property_1.typedHasProperty)(matchValue, 'constructor')) {
82
80
  if (!(0, typed_has_property_1.typedHasProperty)(testValue, 'constructor') ||
83
81
  testValue.constructor !== matchValue.constructor) {
84
- throwKeyError(`constructor "${(_a = testValue === null || testValue === void 0 ? void 0 : testValue.constructor) === null || _a === void 0 ? void 0 : _a.name}" did not match expected constructor "${matchValue.constructor}"`);
82
+ throwKeyError(`constructor "${testValue?.constructor?.name}" did not match expected constructor "${matchValue.constructor}"`);
85
83
  }
86
84
  }
87
85
  }
@@ -12,10 +12,11 @@ function getObjectTypedKeys(input) {
12
12
  reflectKeys = Reflect.ownKeys(input);
13
13
  }
14
14
  catch (error) { }
15
- return (reflectKeys !== null && reflectKeys !== void 0 ? reflectKeys : [
16
- ...Object.keys(input),
17
- ...Object.getOwnPropertySymbols(input),
18
- ]);
15
+ return (reflectKeys ??
16
+ [
17
+ ...Object.keys(input),
18
+ ...Object.getOwnPropertySymbols(input),
19
+ ]);
19
20
  }
20
21
  exports.getObjectTypedKeys = getObjectTypedKeys;
21
22
  function getObjectTypedValues(input) {
@@ -15,6 +15,6 @@ function addRegExpFlags(originalRegExp, flags) {
15
15
  exports.addRegExpFlags = addRegExpFlags;
16
16
  function safeMatch(input, regExp) {
17
17
  const match = input.match(regExp);
18
- return match !== null && match !== void 0 ? match : [];
18
+ return match ?? [];
19
19
  }
20
20
  exports.safeMatch = safeMatch;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Joins all given arguments together as if they were parts of a URL. Preserves trailing slashes and
3
- * removes consecutive slashes in the path. This also encodes each part of the
3
+ * removes consecutive slashes in the path. This also encodes each URL part.
4
4
  *
5
5
  * @example: joinToUrl('https://example.com', 'path1', 'path2/', '/path3/') === 'https://example.com/path1/path2/path3/'
6
6
  */
@@ -4,7 +4,7 @@ exports.joinUrlParts = void 0;
4
4
  const protocolSplit = '://';
5
5
  /**
6
6
  * Joins all given arguments together as if they were parts of a URL. Preserves trailing slashes and
7
- * removes consecutive slashes in the path. This also encodes each part of the
7
+ * removes consecutive slashes in the path. This also encodes each URL part.
8
8
  *
9
9
  * @example: joinToUrl('https://example.com', 'path1', 'path2/', '/path3/') === 'https://example.com/path1/path2/path3/'
10
10
  */
@@ -16,10 +16,54 @@ function joinUrlParts(...urlParts) {
16
16
  '',
17
17
  rawJoined,
18
18
  ];
19
+ let mapSearchParamsStarted = false;
20
+ let reduceSearchParamsStarted = false;
19
21
  const fixedRest = rawRest
20
22
  .replace(/\/{2,}/g, '/')
21
23
  .split('/')
22
- .map((part) => encodeURIComponent(part));
24
+ .map((part) => {
25
+ if (part.includes('?') || mapSearchParamsStarted) {
26
+ mapSearchParamsStarted = true;
27
+ return part;
28
+ }
29
+ else {
30
+ return encodeURIComponent(part);
31
+ }
32
+ })
33
+ .reduce((fillingUpArray, currentEntry, currentIndex, inputArray) => {
34
+ if (reduceSearchParamsStarted) {
35
+ return fillingUpArray;
36
+ }
37
+ const nextEntry = inputArray[currentIndex + 1];
38
+ let newEntry = currentEntry;
39
+ const nextHasQuestion = !currentEntry.includes('?') && nextEntry?.startsWith('?');
40
+ if (nextEntry?.startsWith('?') || nextHasQuestion) {
41
+ reduceSearchParamsStarted = true;
42
+ let foundHash = false;
43
+ const subsequentSearchParams = inputArray
44
+ .slice(nextHasQuestion ? currentIndex + 2 : currentIndex + 1)
45
+ .reduce((joinedParams, currentParam) => {
46
+ if (currentParam.includes('#')) {
47
+ foundHash = true;
48
+ }
49
+ if (foundHash) {
50
+ return joinedParams.concat(currentParam);
51
+ }
52
+ else {
53
+ return [
54
+ joinedParams,
55
+ currentParam,
56
+ ].join('&');
57
+ }
58
+ }, '');
59
+ newEntry = [
60
+ currentEntry,
61
+ nextEntry,
62
+ subsequentSearchParams,
63
+ ].join('');
64
+ }
65
+ return fillingUpArray.concat(newEntry);
66
+ }, []);
23
67
  return [
24
68
  protocol,
25
69
  protocol ? protocolSplit : '',
@@ -16,7 +16,7 @@ export async function awaitedBlockingMap(input, callback) {
16
16
  return mappedValues;
17
17
  }
18
18
  export async function awaitedFilter(arrayInput, filterCallback, options) {
19
- const callbackResults = (options === null || options === void 0 ? void 0 : options.blocking)
19
+ const callbackResults = options?.blocking
20
20
  ? await awaitedBlockingMap(arrayInput, filterCallback)
21
21
  : await Promise.all(arrayInput.map(filterCallback));
22
22
  return arrayInput.filter((originalValue, index) => !!callbackResults[index]);
@@ -51,7 +51,6 @@ export function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExt
51
51
  }
52
52
  }
53
53
  matchKeys.forEach((key) => {
54
- var _a;
55
54
  if (!typedHasProperty(testThisOne, key)) {
56
55
  throw new Error(`test object does not have key "${String(key)}" from expected shape.`);
57
56
  }
@@ -61,12 +60,11 @@ export function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExt
61
60
  const testValue = testThisOne[key];
62
61
  const shouldMatch = compareToThisOne[key];
63
62
  if (!noCheckInnerValueOfTheseKeys[key]) {
64
- compareInnerValue(testValue, shouldMatch, throwKeyError, allowExtraProps, (_a = noCheckInnerValueOfTheseKeys[key]) !== null && _a !== void 0 ? _a : {});
63
+ compareInnerValue(testValue, shouldMatch, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys[key] ?? {});
65
64
  }
66
65
  });
67
66
  }
68
67
  function compareInnerValue(testValue, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys) {
69
- var _a;
70
68
  const testType = typeof testValue;
71
69
  const shouldMatchType = typeof matchValue;
72
70
  if (testType !== shouldMatchType) {
@@ -76,7 +74,7 @@ function compareInnerValue(testValue, matchValue, throwKeyError, allowExtraProps
76
74
  if (typedHasProperty(matchValue, 'constructor')) {
77
75
  if (!typedHasProperty(testValue, 'constructor') ||
78
76
  testValue.constructor !== matchValue.constructor) {
79
- throwKeyError(`constructor "${(_a = testValue === null || testValue === void 0 ? void 0 : testValue.constructor) === null || _a === void 0 ? void 0 : _a.name}" did not match expected constructor "${matchValue.constructor}"`);
77
+ throwKeyError(`constructor "${testValue?.constructor?.name}" did not match expected constructor "${matchValue.constructor}"`);
80
78
  }
81
79
  }
82
80
  }
@@ -8,10 +8,11 @@ export function getObjectTypedKeys(input) {
8
8
  reflectKeys = Reflect.ownKeys(input);
9
9
  }
10
10
  catch (error) { }
11
- return (reflectKeys !== null && reflectKeys !== void 0 ? reflectKeys : [
12
- ...Object.keys(input),
13
- ...Object.getOwnPropertySymbols(input),
14
- ]);
11
+ return (reflectKeys ??
12
+ [
13
+ ...Object.keys(input),
14
+ ...Object.getOwnPropertySymbols(input),
15
+ ]);
15
16
  }
16
17
  export function getObjectTypedValues(input) {
17
18
  return getObjectTypedKeys(input).map((key) => input[key]);
@@ -10,5 +10,5 @@ export function addRegExpFlags(originalRegExp, flags) {
10
10
  }
11
11
  export function safeMatch(input, regExp) {
12
12
  const match = input.match(regExp);
13
- return match !== null && match !== void 0 ? match : [];
13
+ return match ?? [];
14
14
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Joins all given arguments together as if they were parts of a URL. Preserves trailing slashes and
3
- * removes consecutive slashes in the path. This also encodes each part of the
3
+ * removes consecutive slashes in the path. This also encodes each URL part.
4
4
  *
5
5
  * @example: joinToUrl('https://example.com', 'path1', 'path2/', '/path3/') === 'https://example.com/path1/path2/path3/'
6
6
  */
@@ -1,7 +1,7 @@
1
1
  const protocolSplit = '://';
2
2
  /**
3
3
  * Joins all given arguments together as if they were parts of a URL. Preserves trailing slashes and
4
- * removes consecutive slashes in the path. This also encodes each part of the
4
+ * removes consecutive slashes in the path. This also encodes each URL part.
5
5
  *
6
6
  * @example: joinToUrl('https://example.com', 'path1', 'path2/', '/path3/') === 'https://example.com/path1/path2/path3/'
7
7
  */
@@ -13,10 +13,54 @@ export function joinUrlParts(...urlParts) {
13
13
  '',
14
14
  rawJoined,
15
15
  ];
16
+ let mapSearchParamsStarted = false;
17
+ let reduceSearchParamsStarted = false;
16
18
  const fixedRest = rawRest
17
19
  .replace(/\/{2,}/g, '/')
18
20
  .split('/')
19
- .map((part) => encodeURIComponent(part));
21
+ .map((part) => {
22
+ if (part.includes('?') || mapSearchParamsStarted) {
23
+ mapSearchParamsStarted = true;
24
+ return part;
25
+ }
26
+ else {
27
+ return encodeURIComponent(part);
28
+ }
29
+ })
30
+ .reduce((fillingUpArray, currentEntry, currentIndex, inputArray) => {
31
+ if (reduceSearchParamsStarted) {
32
+ return fillingUpArray;
33
+ }
34
+ const nextEntry = inputArray[currentIndex + 1];
35
+ let newEntry = currentEntry;
36
+ const nextHasQuestion = !currentEntry.includes('?') && nextEntry?.startsWith('?');
37
+ if (nextEntry?.startsWith('?') || nextHasQuestion) {
38
+ reduceSearchParamsStarted = true;
39
+ let foundHash = false;
40
+ const subsequentSearchParams = inputArray
41
+ .slice(nextHasQuestion ? currentIndex + 2 : currentIndex + 1)
42
+ .reduce((joinedParams, currentParam) => {
43
+ if (currentParam.includes('#')) {
44
+ foundHash = true;
45
+ }
46
+ if (foundHash) {
47
+ return joinedParams.concat(currentParam);
48
+ }
49
+ else {
50
+ return [
51
+ joinedParams,
52
+ currentParam,
53
+ ].join('&');
54
+ }
55
+ }, '');
56
+ newEntry = [
57
+ currentEntry,
58
+ nextEntry,
59
+ subsequentSearchParams,
60
+ ].join('');
61
+ }
62
+ return fillingUpArray.concat(newEntry);
63
+ }, []);
20
64
  return [
21
65
  protocol,
22
66
  protocol ? protocolSplit : '',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Joins all given arguments together as if they were parts of a URL. Preserves trailing slashes and
3
- * removes consecutive slashes in the path. This also encodes each part of the
3
+ * removes consecutive slashes in the path. This also encodes each URL part.
4
4
  *
5
5
  * @example: joinToUrl('https://example.com', 'path1', 'path2/', '/path3/') === 'https://example.com/path1/path2/path3/'
6
6
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "13.1.0",
3
+ "version": "13.2.1",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"