@scalar/helpers 0.4.0 → 0.4.2

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.
Files changed (113) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/array/add-to-map-array.js +7 -8
  3. package/dist/array/is-defined.js +12 -5
  4. package/dist/array/sort-by-order.js +60 -18
  5. package/dist/consts/content-types.js +13 -14
  6. package/dist/dom/freeze-element.js +56 -42
  7. package/dist/dom/scroll-to-id.js +33 -27
  8. package/dist/file/json2xml.js +79 -61
  9. package/dist/general/create-limiter.js +47 -31
  10. package/dist/general/debounce.js +86 -66
  11. package/dist/general/extract-config-secrets.js +29 -27
  12. package/dist/general/has-modifier.js +9 -8
  13. package/dist/general/is-mac-os.d.ts +1 -5
  14. package/dist/general/is-mac-os.d.ts.map +1 -1
  15. package/dist/general/is-mac-os.js +24 -11
  16. package/dist/http/can-method-have-body.js +4 -6
  17. package/dist/http/http-info.js +63 -61
  18. package/dist/http/http-methods.js +4 -7
  19. package/dist/http/http-status-codes.js +316 -320
  20. package/dist/http/is-http-method.js +3 -6
  21. package/dist/http/normalize-http-method.js +19 -19
  22. package/dist/json/escape-json-pointer.js +6 -5
  23. package/dist/json/parse-json-pointer-segments.js +11 -6
  24. package/dist/json/pretty-print-json.d.ts +9 -0
  25. package/dist/json/pretty-print-json.d.ts.map +1 -0
  26. package/dist/json/pretty-print-json.js +42 -0
  27. package/dist/json/unescape-json-pointer.js +7 -5
  28. package/dist/node/path.js +168 -138
  29. package/dist/object/get-value-at-path.js +17 -11
  30. package/dist/object/is-object.js +24 -10
  31. package/dist/object/local-storage.js +50 -42
  32. package/dist/object/object-entries.js +2 -5
  33. package/dist/object/object-keys.js +5 -5
  34. package/dist/object/object-replace.js +13 -12
  35. package/dist/object/omit-undefined-values.js +18 -18
  36. package/dist/object/prevent-pollution.js +27 -10
  37. package/dist/object/to-json-compatible.js +71 -62
  38. package/dist/queue/queue.js +103 -84
  39. package/dist/regex/find-variables.js +13 -8
  40. package/dist/regex/regex-helpers.js +17 -17
  41. package/dist/regex/replace-variables.js +21 -19
  42. package/dist/string/camel-to-title.js +10 -5
  43. package/dist/string/capitalize.js +5 -5
  44. package/dist/string/create-hash.js +19 -16
  45. package/dist/string/generate-hash.js +153 -127
  46. package/dist/string/iterate-title.js +13 -11
  47. package/dist/string/truncate.js +16 -9
  48. package/dist/testing/console-spies.js +19 -24
  49. package/dist/testing/measure.js +42 -19
  50. package/dist/testing/measure.test-d.js +12 -9
  51. package/dist/testing/sleep.js +5 -5
  52. package/dist/url/ensure-protocol.js +8 -10
  53. package/dist/url/extract-server-from-path.js +53 -28
  54. package/dist/url/is-local-url.js +24 -18
  55. package/dist/url/is-relative-path.js +15 -13
  56. package/dist/url/is-valid-url.js +17 -10
  57. package/dist/url/make-url-absolute.js +39 -28
  58. package/dist/url/merge-urls.js +74 -52
  59. package/dist/url/redirect-to-proxy.js +68 -39
  60. package/package.json +5 -9
  61. package/dist/array/add-to-map-array.js.map +0 -7
  62. package/dist/array/is-defined.js.map +0 -7
  63. package/dist/array/sort-by-order.js.map +0 -7
  64. package/dist/consts/content-types.js.map +0 -7
  65. package/dist/dom/freeze-element.js.map +0 -7
  66. package/dist/dom/scroll-to-id.js.map +0 -7
  67. package/dist/file/json2xml.js.map +0 -7
  68. package/dist/general/create-limiter.js.map +0 -7
  69. package/dist/general/debounce.js.map +0 -7
  70. package/dist/general/extract-config-secrets.js.map +0 -7
  71. package/dist/general/has-modifier.js.map +0 -7
  72. package/dist/general/is-mac-os.js.map +0 -7
  73. package/dist/http/can-method-have-body.js.map +0 -7
  74. package/dist/http/http-info.js.map +0 -7
  75. package/dist/http/http-methods.js.map +0 -7
  76. package/dist/http/http-status-codes.js.map +0 -7
  77. package/dist/http/is-http-method.js.map +0 -7
  78. package/dist/http/normalize-http-method.js.map +0 -7
  79. package/dist/json/escape-json-pointer.js.map +0 -7
  80. package/dist/json/parse-json-pointer-segments.js.map +0 -7
  81. package/dist/json/unescape-json-pointer.js.map +0 -7
  82. package/dist/node/path.js.map +0 -7
  83. package/dist/object/get-value-at-path.js.map +0 -7
  84. package/dist/object/is-object.js.map +0 -7
  85. package/dist/object/local-storage.js.map +0 -7
  86. package/dist/object/object-entries.js.map +0 -7
  87. package/dist/object/object-keys.js.map +0 -7
  88. package/dist/object/object-replace.js.map +0 -7
  89. package/dist/object/omit-undefined-values.js.map +0 -7
  90. package/dist/object/prevent-pollution.js.map +0 -7
  91. package/dist/object/to-json-compatible.js.map +0 -7
  92. package/dist/queue/queue.js.map +0 -7
  93. package/dist/regex/find-variables.js.map +0 -7
  94. package/dist/regex/regex-helpers.js.map +0 -7
  95. package/dist/regex/replace-variables.js.map +0 -7
  96. package/dist/string/camel-to-title.js.map +0 -7
  97. package/dist/string/capitalize.js.map +0 -7
  98. package/dist/string/create-hash.js.map +0 -7
  99. package/dist/string/generate-hash.js.map +0 -7
  100. package/dist/string/iterate-title.js.map +0 -7
  101. package/dist/string/truncate.js.map +0 -7
  102. package/dist/testing/console-spies.js.map +0 -7
  103. package/dist/testing/measure.js.map +0 -7
  104. package/dist/testing/measure.test-d.js.map +0 -7
  105. package/dist/testing/sleep.js.map +0 -7
  106. package/dist/url/ensure-protocol.js.map +0 -7
  107. package/dist/url/extract-server-from-path.js.map +0 -7
  108. package/dist/url/is-local-url.js.map +0 -7
  109. package/dist/url/is-relative-path.js.map +0 -7
  110. package/dist/url/is-valid-url.js.map +0 -7
  111. package/dist/url/make-url-absolute.js.map +0 -7
  112. package/dist/url/merge-urls.js.map +0 -7
  113. package/dist/url/redirect-to-proxy.js.map +0 -7
@@ -1,6 +1,3 @@
1
- import { httpMethods } from "./http-methods.js";
2
- const isHttpMethod = (method) => method && typeof method === "string" ? httpMethods.has(method.toLowerCase()) : false;
3
- export {
4
- isHttpMethod
5
- };
6
- //# sourceMappingURL=is-http-method.js.map
1
+ import { httpMethods } from './http-methods.js';
2
+ /** Type guard which takes in a string and returns true if it is in fact an HTTPMethod */
3
+ export const isHttpMethod = (method) => method && typeof method === 'string' ? httpMethods.has(method.toLowerCase()) : false;
@@ -1,20 +1,20 @@
1
- import { isHttpMethod } from "./is-http-method.js";
2
- const DEFAULT_REQUEST_METHOD = "get";
3
- const normalizeHttpMethod = (method) => {
4
- if (typeof method !== "string") {
5
- console.warn(`Request method is not a string. Using ${DEFAULT_REQUEST_METHOD} as the default.`);
6
- return DEFAULT_REQUEST_METHOD;
7
- }
8
- const normalizedMethod = method.trim().toLowerCase();
9
- if (!isHttpMethod(normalizedMethod)) {
10
- console.warn(
11
- `${method || "Request method"} is not a valid request method. Using ${DEFAULT_REQUEST_METHOD} as the default.`
12
- );
13
- return DEFAULT_REQUEST_METHOD;
14
- }
15
- return normalizedMethod;
1
+ import { isHttpMethod } from './is-http-method.js';
2
+ const DEFAULT_REQUEST_METHOD = 'get';
3
+ /**
4
+ * Get a normalized request method (e.g. get, post, etc.)
5
+ * Lowercases the method and returns the default if it is not a valid method so you will always have a valid method
6
+ */
7
+ export const normalizeHttpMethod = (method) => {
8
+ // Make sure it's a string
9
+ if (typeof method !== 'string') {
10
+ console.warn(`Request method is not a string. Using ${DEFAULT_REQUEST_METHOD} as the default.`);
11
+ return DEFAULT_REQUEST_METHOD;
12
+ }
13
+ // Normalize the string
14
+ const normalizedMethod = method.trim().toLowerCase();
15
+ if (!isHttpMethod(normalizedMethod)) {
16
+ console.warn(`${method || 'Request method'} is not a valid request method. Using ${DEFAULT_REQUEST_METHOD} as the default.`);
17
+ return DEFAULT_REQUEST_METHOD;
18
+ }
19
+ return normalizedMethod;
16
20
  };
17
- export {
18
- normalizeHttpMethod
19
- };
20
- //# sourceMappingURL=normalize-http-method.js.map
@@ -1,5 +1,6 @@
1
- const escapeJsonPointer = (str) => str.replace(/~/g, "~0").replace(/\//g, "~1");
2
- export {
3
- escapeJsonPointer
4
- };
5
- //# sourceMappingURL=escape-json-pointer.js.map
1
+ /**
2
+ * Escapes a JSON pointer string.
3
+ *
4
+ * Example: `/foo/bar~baz` -> `~1foo~1bar~0baz`
5
+ */
6
+ export const escapeJsonPointer = (str) => str.replace(/~/g, '~0').replace(/\//g, '~1');
@@ -1,6 +1,11 @@
1
- import { unescapeJsonPointer } from "./unescape-json-pointer.js";
2
- const parseJsonPointerSegments = (path) => path.split("/").slice(1).map(unescapeJsonPointer);
3
- export {
4
- parseJsonPointerSegments
5
- };
6
- //# sourceMappingURL=parse-json-pointer-segments.js.map
1
+ import { unescapeJsonPointer } from './unescape-json-pointer.js';
2
+ /**
3
+ * Translate `/paths/~1test` to `['paths', '/test']`
4
+ */
5
+ export const parseJsonPointerSegments = (path) => path
6
+ // ['', 'paths', '~1test']
7
+ .split('/')
8
+ // ['paths', '~1test']
9
+ .slice(1)
10
+ // ['paths', '/test']
11
+ .map(unescapeJsonPointer);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Takes JSON and formats it.
3
+ */
4
+ export declare const prettyPrintJson: (value: string | number | any[] | Record<any, any>) => string;
5
+ /**
6
+ * JSON.stringify, but with circular dependencies replaced with '[Circular]'
7
+ */
8
+ export declare function replaceCircularDependencies(content: any): string;
9
+ //# sourceMappingURL=pretty-print-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pretty-print-json.d.ts","sourceRoot":"","sources":["../../src/json/pretty-print-json.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,KAAG,MAyBnF,CAAA;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,GAAG,UAiBvD"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Takes JSON and formats it.
3
+ */
4
+ export const prettyPrintJson = (value) => {
5
+ // When the values is already a string it should be parsable
6
+ if (typeof value === 'string') {
7
+ try {
8
+ const parsed = JSON.parse(value);
9
+ if (typeof parsed === 'object' && parsed !== null) {
10
+ return JSON.stringify(parsed, null, 2);
11
+ }
12
+ return value;
13
+ }
14
+ catch {
15
+ return value;
16
+ }
17
+ }
18
+ if (typeof value === 'object') {
19
+ try {
20
+ return JSON.stringify(value, null, 2);
21
+ }
22
+ catch {
23
+ return replaceCircularDependencies(value);
24
+ }
25
+ }
26
+ return value?.toString() ?? '';
27
+ };
28
+ /**
29
+ * JSON.stringify, but with circular dependencies replaced with '[Circular]'
30
+ */
31
+ export function replaceCircularDependencies(content) {
32
+ const cache = new Set();
33
+ return JSON.stringify(content, (_key, value) => {
34
+ if (typeof value === 'object' && value !== null) {
35
+ if (cache.has(value)) {
36
+ return '[Circular]';
37
+ }
38
+ cache.add(value);
39
+ }
40
+ return value;
41
+ }, 2);
42
+ }
@@ -1,5 +1,7 @@
1
- const unescapeJsonPointer = (uri) => decodeURI(uri.replace(/~1/g, "/").replace(/~0/g, "~"));
2
- export {
3
- unescapeJsonPointer
4
- };
5
- //# sourceMappingURL=unescape-json-pointer.js.map
1
+ /**
2
+ * Unescape JSON pointer
3
+ *
4
+ * Examples:
5
+ * /foo~1bar~0baz -> /foo/bar~baz
6
+ */
7
+ export const unescapeJsonPointer = (uri) => decodeURI(uri.replace(/~1/g, '/').replace(/~0/g, '~'));
package/dist/node/path.js CHANGED
@@ -1,157 +1,187 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+ // resolves . and .. elements in a path array with directory names there
22
+ // must be no slashes, empty elements, or device names (c:\) in the array
23
+ // (so also no leading and trailing slashes - it does not distinguish
24
+ // relative and absolute paths)
25
+ // !! WARNING !!
26
+ // The original implementation included ponyfills for `filters` and `substr`.
27
+ // These have been removed in favor of native implementations supported by the current platforms.
28
+ // See: https://github.com/scalar/scalar/pull/7235#discussion_r2484230212
1
29
  function normalizeArray(parts, allowAboveRoot) {
2
- let up = 0;
3
- for (let i = parts.length - 1; i >= 0; i--) {
4
- const last = parts[i];
5
- if (last === ".") {
6
- parts.splice(i, 1);
7
- } else if (last === "..") {
8
- parts.splice(i, 1);
9
- up++;
10
- } else if (up) {
11
- parts.splice(i, 1);
12
- up--;
30
+ // if the path tries to go above the root, `up` ends up > 0
31
+ let up = 0;
32
+ for (let i = parts.length - 1; i >= 0; i--) {
33
+ const last = parts[i];
34
+ if (last === '.') {
35
+ parts.splice(i, 1);
36
+ }
37
+ else if (last === '..') {
38
+ parts.splice(i, 1);
39
+ up++;
40
+ }
41
+ else if (up) {
42
+ parts.splice(i, 1);
43
+ up--;
44
+ }
13
45
  }
14
- }
15
- if (allowAboveRoot) {
16
- for (; up--; up) {
17
- parts.unshift("..");
46
+ // if the path is allowed to go above the root, restore leading ..s
47
+ if (allowAboveRoot) {
48
+ for (; up--; up) {
49
+ parts.unshift('..');
50
+ }
18
51
  }
19
- }
20
- return parts;
52
+ return parts;
21
53
  }
54
+ // Split a filename into [root, dir, basename, ext], unix version
55
+ // 'root' is just a slash, or nothing.
22
56
  const splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^/]+?|)(\.[^./]*|))(?:[/]*)$/;
23
57
  const splitPath = (filename) => splitPathRe.exec(filename).slice(1);
24
- function resolve(...parameters) {
25
- let resolvedPath = "", resolvedAbsolute = false;
26
- for (let i = parameters.length - 1; i >= -1 && !resolvedAbsolute; i--) {
27
- const path2 = i >= 0 ? parameters[i] : "/";
28
- if (typeof path2 !== "string") {
29
- throw new TypeError("Arguments to path.resolve must be strings");
58
+ // path.resolve([from ...], to)
59
+ // posix version
60
+ export function resolve(...parameters) {
61
+ let resolvedPath = '', resolvedAbsolute = false;
62
+ for (let i = parameters.length - 1; i >= -1 && !resolvedAbsolute; i--) {
63
+ const path = i >= 0 ? parameters[i] : '/';
64
+ // Skip empty and invalid entries
65
+ if (typeof path !== 'string') {
66
+ throw new TypeError('Arguments to path.resolve must be strings');
67
+ }
68
+ if (!path) {
69
+ continue;
70
+ }
71
+ resolvedPath = path + '/' + resolvedPath;
72
+ resolvedAbsolute = path.charAt(0) === '/';
30
73
  }
31
- if (!path2) {
32
- continue;
33
- }
34
- resolvedPath = path2 + "/" + resolvedPath;
35
- resolvedAbsolute = path2.charAt(0) === "/";
36
- }
37
- resolvedPath = normalizeArray(
38
- resolvedPath.split("/").filter((p) => !!p),
39
- !resolvedAbsolute
40
- ).join("/");
41
- return (resolvedAbsolute ? "/" : "") + resolvedPath || ".";
74
+ // At this point the path should be resolved to a full absolute path, but
75
+ // handle relative paths to be safe (might happen when process.cwd() fails)
76
+ // Normalize the path
77
+ resolvedPath = normalizeArray(resolvedPath.split('/').filter((p) => !!p), !resolvedAbsolute).join('/');
78
+ return (resolvedAbsolute ? '/' : '') + resolvedPath || '.';
42
79
  }
43
- function normalize(inputPath) {
44
- const isPathAbsolute = isAbsolute(inputPath), trailingSlash = inputPath.slice(-1) === "/";
45
- let path2 = normalizeArray(
46
- inputPath.split("/").filter((p) => !!p),
47
- !isPathAbsolute
48
- ).join("/");
49
- if (!path2 && !isPathAbsolute) {
50
- path2 = ".";
51
- }
52
- if (path2 && trailingSlash) {
53
- path2 += "/";
54
- }
55
- return (isPathAbsolute ? "/" : "") + path2;
80
+ // path.normalize(path)
81
+ // posix version
82
+ export function normalize(inputPath) {
83
+ const isPathAbsolute = isAbsolute(inputPath), trailingSlash = inputPath.slice(-1) === '/';
84
+ // Normalize the path
85
+ let path = normalizeArray(inputPath.split('/').filter((p) => !!p), !isPathAbsolute).join('/');
86
+ if (!path && !isPathAbsolute) {
87
+ path = '.';
88
+ }
89
+ if (path && trailingSlash) {
90
+ path += '/';
91
+ }
92
+ return (isPathAbsolute ? '/' : '') + path;
56
93
  }
57
- function isAbsolute(path2) {
58
- return path2.charAt(0) === "/";
94
+ // posix version
95
+ export function isAbsolute(path) {
96
+ return path.charAt(0) === '/';
59
97
  }
60
- function join(...paths) {
61
- return normalize(
62
- paths.filter((p) => {
63
- if (typeof p !== "string") {
64
- throw new TypeError("Arguments to path.join must be strings");
65
- }
66
- return p;
67
- }).join("/")
68
- );
98
+ // posix version
99
+ export function join(...paths) {
100
+ return normalize(paths
101
+ .filter((p) => {
102
+ if (typeof p !== 'string') {
103
+ throw new TypeError('Arguments to path.join must be strings');
104
+ }
105
+ return p;
106
+ })
107
+ .join('/'));
69
108
  }
70
- function relative(from, to) {
71
- const fromResolved = resolve(from).substring(1);
72
- const toResolved = resolve(to).substring(1);
73
- function trim(arr) {
74
- let start = 0;
75
- for (; start < arr.length; start++) {
76
- if (arr[start] !== "") {
77
- break;
78
- }
79
- }
80
- let end = arr.length - 1;
81
- for (; end >= 0; end--) {
82
- if (arr[end] !== "") {
83
- break;
84
- }
109
+ // path.relative(from, to)
110
+ // posix version
111
+ export function relative(from, to) {
112
+ const fromResolved = resolve(from).substring(1);
113
+ const toResolved = resolve(to).substring(1);
114
+ function trim(arr) {
115
+ let start = 0;
116
+ for (; start < arr.length; start++) {
117
+ if (arr[start] !== '') {
118
+ break;
119
+ }
120
+ }
121
+ let end = arr.length - 1;
122
+ for (; end >= 0; end--) {
123
+ if (arr[end] !== '') {
124
+ break;
125
+ }
126
+ }
127
+ if (start > end) {
128
+ return [];
129
+ }
130
+ return arr.slice(start, end - start + 1);
85
131
  }
86
- if (start > end) {
87
- return [];
132
+ const fromParts = trim(fromResolved.split('/'));
133
+ const toParts = trim(toResolved.split('/'));
134
+ const length = Math.min(fromParts.length, toParts.length);
135
+ let samePartsLength = length;
136
+ for (let i = 0; i < length; i++) {
137
+ if (fromParts[i] !== toParts[i]) {
138
+ samePartsLength = i;
139
+ break;
140
+ }
88
141
  }
89
- return arr.slice(start, end - start + 1);
90
- }
91
- const fromParts = trim(fromResolved.split("/"));
92
- const toParts = trim(toResolved.split("/"));
93
- const length = Math.min(fromParts.length, toParts.length);
94
- let samePartsLength = length;
95
- for (let i = 0; i < length; i++) {
96
- if (fromParts[i] !== toParts[i]) {
97
- samePartsLength = i;
98
- break;
142
+ let outputParts = [];
143
+ for (let i = samePartsLength; i < fromParts.length; i++) {
144
+ outputParts.push('..');
99
145
  }
100
- }
101
- let outputParts = [];
102
- for (let i = samePartsLength; i < fromParts.length; i++) {
103
- outputParts.push("..");
104
- }
105
- outputParts = outputParts.concat(toParts.slice(samePartsLength));
106
- return outputParts.join("/");
146
+ outputParts = outputParts.concat(toParts.slice(samePartsLength));
147
+ return outputParts.join('/');
107
148
  }
108
- const sep = "/";
109
- const delimiter = ":";
110
- function dirname(path2) {
111
- const result = splitPath(path2);
112
- const root = result[0];
113
- let dir = result[1];
114
- if (!root && !dir) {
115
- return ".";
116
- }
117
- if (dir) {
118
- dir = dir.slice(0, -1);
119
- }
120
- return root + dir;
149
+ export const sep = '/';
150
+ export const delimiter = ':';
151
+ export function dirname(path) {
152
+ const result = splitPath(path);
153
+ const root = result[0];
154
+ let dir = result[1];
155
+ if (!root && !dir) {
156
+ // No dirname whatsoever
157
+ return '.';
158
+ }
159
+ if (dir) {
160
+ // It has a dirname, strip trailing slash
161
+ dir = dir.slice(0, -1);
162
+ }
163
+ return root + dir;
121
164
  }
122
- function basename(path2, ext) {
123
- let f = splitPath(path2)[2];
124
- if (ext && f.slice(-ext.length) === ext) {
125
- f = f.slice(0, -ext.length);
126
- }
127
- return f;
165
+ export function basename(path, ext) {
166
+ let f = splitPath(path)[2];
167
+ // TODO: make this comparison case-insensitive on windows?
168
+ if (ext && f.slice(-ext.length) === ext) {
169
+ f = f.slice(0, -ext.length);
170
+ }
171
+ return f;
128
172
  }
129
- function extname(path2) {
130
- return splitPath(path2)[3];
173
+ export function extname(path) {
174
+ return splitPath(path)[3];
131
175
  }
132
- const path = {
133
- extname,
134
- basename,
135
- dirname,
136
- sep,
137
- delimiter,
138
- relative,
139
- join,
140
- isAbsolute,
141
- normalize,
142
- resolve
143
- };
144
- export {
145
- basename,
146
- delimiter,
147
- dirname,
148
- extname,
149
- isAbsolute,
150
- join,
151
- normalize,
152
- path,
153
- relative,
154
- resolve,
155
- sep
176
+ export const path = {
177
+ extname,
178
+ basename,
179
+ dirname,
180
+ sep,
181
+ delimiter,
182
+ relative,
183
+ join,
184
+ isAbsolute,
185
+ normalize,
186
+ resolve,
156
187
  };
157
- //# sourceMappingURL=path.js.map
@@ -1,12 +1,18 @@
1
- function getValueAtPath(obj, pointer) {
2
- return pointer.reduce((acc, part) => {
3
- if (acc === void 0 || acc === null) {
4
- return void 0;
5
- }
6
- return acc[part];
7
- }, obj);
1
+ /**
2
+ * Retrieves a nested value from the source document using a path array
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * getValueByPath(document, ['components', 'schemas', 'User'])
7
+ *
8
+ * { id: '123', name: 'John Doe' }
9
+ * ```
10
+ */
11
+ export function getValueAtPath(obj, pointer) {
12
+ return pointer.reduce((acc, part) => {
13
+ if (acc === undefined || acc === null) {
14
+ return undefined;
15
+ }
16
+ return acc[part];
17
+ }, obj);
8
18
  }
9
- export {
10
- getValueAtPath
11
- };
12
- //# sourceMappingURL=get-value-at-path.js.map
@@ -1,11 +1,25 @@
1
- const isObject = (value) => {
2
- if (value === null || typeof value !== "object") {
3
- return false;
4
- }
5
- const proto = Object.getPrototypeOf(value);
6
- return proto === Object.prototype || proto === null;
1
+ /**
2
+ * Returns true if the provided value is a record object
3
+ * (i.e. not null, not an array, and has an actual object as the prototype).
4
+ *
5
+ * Differs from the previous isObject in that it returns false for Date,
6
+ * RegExp, Error, Map, Set, WeakMap, WeakSet, Promise, and other non-plain objects.
7
+ *
8
+ * Examples:
9
+ * isObject({}) // true
10
+ * isObject({ a: 1 }) // true
11
+ * isObject([]) // false (Array)
12
+ * isObject(null) // false
13
+ * isObject(123) // false
14
+ * isObject('string') // false
15
+ * isObject(new Error('test')) // false
16
+ * isObject(new Date()) // false
17
+ * isObject(Object.create(null)) // true
18
+ */
19
+ export const isObject = (value) => {
20
+ if (value === null || typeof value !== 'object') {
21
+ return false;
22
+ }
23
+ const proto = Object.getPrototypeOf(value);
24
+ return proto === Object.prototype || proto === null;
7
25
  };
8
- export {
9
- isObject
10
- };
11
- //# sourceMappingURL=is-object.js.map
@@ -1,45 +1,53 @@
1
- const LS_KEYS = {
2
- COLLECTION: "collection",
3
- COOKIE: "cookie",
4
- ENVIRONMENT: "environment",
5
- REQUEST: "request",
6
- REQUEST_EXAMPLE: "requestExample",
7
- SECURITY_SCHEME: "securityScheme",
8
- SERVER: "server",
9
- TAG: "tag",
10
- WORKSPACE: "workspace"
1
+ /**
2
+ * localStorage keys for resources
3
+ * DO NOT CHANGE THESE AS IT WILL BREAK THE MIGRATION
4
+ */
5
+ export const LS_KEYS = {
6
+ COLLECTION: 'collection',
7
+ COOKIE: 'cookie',
8
+ ENVIRONMENT: 'environment',
9
+ REQUEST: 'request',
10
+ REQUEST_EXAMPLE: 'requestExample',
11
+ SECURITY_SCHEME: 'securityScheme',
12
+ SERVER: 'server',
13
+ TAG: 'tag',
14
+ WORKSPACE: 'workspace',
11
15
  };
12
- const REFERENCE_LS_KEYS = {
13
- /**
14
- * Store the selected client as a string in localStorage
15
- */
16
- SELECTED_CLIENT: "scalar-reference-selected-client-v2",
17
- /**
18
- * Store the auth as a string in localStorage
19
- */
20
- AUTH: "scalar-reference-auth"
16
+ /**
17
+ * localStorage keys for all reference resources
18
+ * to ensure we do not have any conflicts
19
+ */
20
+ export const REFERENCE_LS_KEYS = {
21
+ /**
22
+ * Store the selected client as a string in localStorage
23
+ */
24
+ SELECTED_CLIENT: 'scalar-reference-selected-client-v2',
25
+ /**
26
+ * Store the auth as a string in localStorage
27
+ */
28
+ AUTH: 'scalar-reference-auth',
21
29
  };
22
- const CLIENT_LS_KEYS = {
23
- /**
24
- * @deprecated This key is deprecated and will be removed in a future release.
25
- * We are now storing the entire document for the api-client instead.
26
- */
27
- AUTH: "scalar-client-auth",
28
- /**
29
- * @deprecated This key is deprecated and will be removed in a future release.
30
- * We are now storing the entire document for the api-client instead.
31
- */
32
- SELECTED_SECURITY_SCHEMES: "scalar-client-selected-security-schemes"
30
+ /**
31
+ * localStorage keys for all client resources
32
+ * to ensure we do not have any conflicts
33
+ */
34
+ export const CLIENT_LS_KEYS = {
35
+ /**
36
+ * @deprecated This key is deprecated and will be removed in a future release.
37
+ * We are now storing the entire document for the api-client instead.
38
+ */
39
+ AUTH: 'scalar-client-auth',
40
+ /**
41
+ * @deprecated This key is deprecated and will be removed in a future release.
42
+ * We are now storing the entire document for the api-client instead.
43
+ */
44
+ SELECTED_SECURITY_SCHEMES: 'scalar-client-selected-security-schemes',
33
45
  };
34
- const safeLocalStorage = () => typeof window === "undefined" ? {
35
- getItem: () => null,
36
- setItem: () => null,
37
- removeItem: () => null
38
- } : localStorage;
39
- export {
40
- CLIENT_LS_KEYS,
41
- LS_KEYS,
42
- REFERENCE_LS_KEYS,
43
- safeLocalStorage
44
- };
45
- //# sourceMappingURL=local-storage.js.map
46
+ /** SSR safe alias for localStorage */
47
+ export const safeLocalStorage = () => typeof window === 'undefined'
48
+ ? {
49
+ getItem: () => null,
50
+ setItem: () => null,
51
+ removeItem: () => null,
52
+ }
53
+ : localStorage;