@scalar/helpers 0.4.1 → 0.4.3
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.
- package/CHANGELOG.md +13 -0
- package/dist/array/add-to-map-array.js +7 -8
- package/dist/array/is-defined.js +12 -5
- package/dist/array/sort-by-order.js +60 -18
- package/dist/consts/content-types.js +13 -14
- package/dist/dom/freeze-element.js +56 -42
- package/dist/dom/get-selector.d.ts +7 -0
- package/dist/dom/get-selector.d.ts.map +1 -0
- package/dist/dom/get-selector.js +31 -0
- package/dist/dom/scroll-to-id.js +33 -27
- package/dist/file/json2xml.js +79 -61
- package/dist/formatters/format-bytes.d.ts +7 -0
- package/dist/formatters/format-bytes.d.ts.map +1 -0
- package/dist/formatters/format-bytes.js +18 -0
- package/dist/formatters/format-milliseconds.d.ts +6 -0
- package/dist/formatters/format-milliseconds.d.ts.map +1 -0
- package/dist/formatters/format-milliseconds.js +10 -0
- package/dist/general/create-limiter.js +47 -31
- package/dist/general/debounce.js +86 -66
- package/dist/general/extract-config-secrets.js +29 -27
- package/dist/general/has-modifier.js +9 -8
- package/dist/general/is-mac-os.js +23 -21
- package/dist/http/can-method-have-body.js +4 -6
- package/dist/http/http-info.js +63 -61
- package/dist/http/http-methods.js +4 -7
- package/dist/http/http-status-codes.js +316 -320
- package/dist/http/is-http-method.js +3 -6
- package/dist/http/normalize-http-method.js +19 -19
- package/dist/json/escape-json-pointer.js +6 -5
- package/dist/json/parse-json-pointer-segments.js +11 -6
- package/dist/json/pretty-print-json.d.ts +9 -0
- package/dist/json/pretty-print-json.d.ts.map +1 -0
- package/dist/json/pretty-print-json.js +42 -0
- package/dist/json/unescape-json-pointer.js +7 -5
- package/dist/markdown/get-markdown-headings.d.ts +11 -0
- package/dist/markdown/get-markdown-headings.d.ts.map +1 -0
- package/dist/markdown/get-markdown-headings.js +99 -0
- package/dist/node/path.js +168 -138
- package/dist/object/get-value-at-path.js +17 -11
- package/dist/object/is-object.js +24 -10
- package/dist/object/local-storage.js +50 -42
- package/dist/object/object-entries.js +2 -5
- package/dist/object/object-keys.js +5 -5
- package/dist/object/object-replace.js +13 -12
- package/dist/object/omit-undefined-values.js +18 -18
- package/dist/object/prevent-pollution.js +27 -10
- package/dist/object/to-json-compatible.js +71 -62
- package/dist/queue/queue.js +103 -84
- package/dist/regex/find-variables.js +13 -8
- package/dist/regex/regex-helpers.js +17 -17
- package/dist/regex/replace-variables.js +21 -19
- package/dist/string/camel-to-title.js +10 -5
- package/dist/string/capitalize.js +5 -5
- package/dist/string/create-hash.js +19 -16
- package/dist/string/generate-hash.js +153 -127
- package/dist/string/iterate-title.js +13 -11
- package/dist/string/truncate.js +16 -9
- package/dist/testing/console-spies.js +19 -24
- package/dist/testing/measure.js +42 -19
- package/dist/testing/measure.test-d.js +12 -9
- package/dist/testing/sleep.js +5 -5
- package/dist/url/ensure-protocol.js +8 -10
- package/dist/url/extract-server-from-path.js +53 -28
- package/dist/url/is-local-url.js +24 -18
- package/dist/url/is-relative-path.js +15 -13
- package/dist/url/is-valid-url.js +17 -10
- package/dist/url/make-url-absolute.js +39 -28
- package/dist/url/merge-urls.js +74 -52
- package/dist/url/redirect-to-proxy.js +68 -39
- package/package.json +15 -9
- package/dist/array/add-to-map-array.js.map +0 -7
- package/dist/array/is-defined.js.map +0 -7
- package/dist/array/sort-by-order.js.map +0 -7
- package/dist/consts/content-types.js.map +0 -7
- package/dist/dom/freeze-element.js.map +0 -7
- package/dist/dom/scroll-to-id.js.map +0 -7
- package/dist/file/json2xml.js.map +0 -7
- package/dist/general/create-limiter.js.map +0 -7
- package/dist/general/debounce.js.map +0 -7
- package/dist/general/extract-config-secrets.js.map +0 -7
- package/dist/general/has-modifier.js.map +0 -7
- package/dist/general/is-mac-os.js.map +0 -7
- package/dist/http/can-method-have-body.js.map +0 -7
- package/dist/http/http-info.js.map +0 -7
- package/dist/http/http-methods.js.map +0 -7
- package/dist/http/http-status-codes.js.map +0 -7
- package/dist/http/is-http-method.js.map +0 -7
- package/dist/http/normalize-http-method.js.map +0 -7
- package/dist/json/escape-json-pointer.js.map +0 -7
- package/dist/json/parse-json-pointer-segments.js.map +0 -7
- package/dist/json/unescape-json-pointer.js.map +0 -7
- package/dist/node/path.js.map +0 -7
- package/dist/object/get-value-at-path.js.map +0 -7
- package/dist/object/is-object.js.map +0 -7
- package/dist/object/local-storage.js.map +0 -7
- package/dist/object/object-entries.js.map +0 -7
- package/dist/object/object-keys.js.map +0 -7
- package/dist/object/object-replace.js.map +0 -7
- package/dist/object/omit-undefined-values.js.map +0 -7
- package/dist/object/prevent-pollution.js.map +0 -7
- package/dist/object/to-json-compatible.js.map +0 -7
- package/dist/queue/queue.js.map +0 -7
- package/dist/regex/find-variables.js.map +0 -7
- package/dist/regex/regex-helpers.js.map +0 -7
- package/dist/regex/replace-variables.js.map +0 -7
- package/dist/string/camel-to-title.js.map +0 -7
- package/dist/string/capitalize.js.map +0 -7
- package/dist/string/create-hash.js.map +0 -7
- package/dist/string/generate-hash.js.map +0 -7
- package/dist/string/iterate-title.js.map +0 -7
- package/dist/string/truncate.js.map +0 -7
- package/dist/testing/console-spies.js.map +0 -7
- package/dist/testing/measure.js.map +0 -7
- package/dist/testing/measure.test-d.js.map +0 -7
- package/dist/testing/sleep.js.map +0 -7
- package/dist/url/ensure-protocol.js.map +0 -7
- package/dist/url/extract-server-from-path.js.map +0 -7
- package/dist/url/is-local-url.js.map +0 -7
- package/dist/url/is-relative-path.js.map +0 -7
- package/dist/url/is-valid-url.js.map +0 -7
- package/dist/url/make-url-absolute.js.map +0 -7
- package/dist/url/merge-urls.js.map +0 -7
- package/dist/url/redirect-to-proxy.js.map +0 -7
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { httpMethods } from
|
|
2
|
-
|
|
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
|
|
2
|
-
const DEFAULT_REQUEST_METHOD =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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, '~'));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract all headings from a Markdown string without any library dependencies.
|
|
3
|
+
*
|
|
4
|
+
* Correctly skips headings inside fenced code blocks (``` or ~~~) and
|
|
5
|
+
* indented code blocks (4+ spaces or tab).
|
|
6
|
+
*/
|
|
7
|
+
export declare function getMarkdownHeadings(markdown: string): {
|
|
8
|
+
depth: number;
|
|
9
|
+
value: string;
|
|
10
|
+
}[];
|
|
11
|
+
//# sourceMappingURL=get-markdown-headings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-markdown-headings.d.ts","sourceRoot":"","sources":["../../src/markdown/get-markdown-headings.ts"],"names":[],"mappings":"AA8BA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG;IACrD,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd,EAAE,CA2EF"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strips inline Markdown formatting to extract plain text.
|
|
3
|
+
*
|
|
4
|
+
* Handles: links, images, bold/italic, inline code, strikethrough, and HTML tags.
|
|
5
|
+
*/
|
|
6
|
+
function stripInlineMarkdown(text) {
|
|
7
|
+
return (text
|
|
8
|
+
// Images:  → alt
|
|
9
|
+
.replace(/!\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
10
|
+
// Links: [text](url) → text
|
|
11
|
+
.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
12
|
+
// Bold/italic combos: ***text*** or ___text___
|
|
13
|
+
.replace(/(\*{3}|_{3})(.+?)\1/g, '$2')
|
|
14
|
+
// Bold: **text** or __text__
|
|
15
|
+
.replace(/(\*{2}|_{2})(.+?)\1/g, '$2')
|
|
16
|
+
// Italic: *text* or _text_
|
|
17
|
+
.replace(/(\*|_)(.+?)\1/g, '$2')
|
|
18
|
+
// Strikethrough: ~~text~~
|
|
19
|
+
.replace(/~~(.+?)~~/g, '$1')
|
|
20
|
+
// Inline code: `code`
|
|
21
|
+
.replace(/`([^`]+)`/g, '$1')
|
|
22
|
+
// HTML tags
|
|
23
|
+
.replace(/<[^>]+>/g, '')
|
|
24
|
+
// Remove any remaining angle brackets to avoid partial/malformed HTML fragments
|
|
25
|
+
.replace(/[<>]/g, '')
|
|
26
|
+
.trim());
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Extract all headings from a Markdown string without any library dependencies.
|
|
30
|
+
*
|
|
31
|
+
* Correctly skips headings inside fenced code blocks (``` or ~~~) and
|
|
32
|
+
* indented code blocks (4+ spaces or tab).
|
|
33
|
+
*/
|
|
34
|
+
export function getMarkdownHeadings(markdown) {
|
|
35
|
+
const lines = markdown.split(/\r?\n/);
|
|
36
|
+
const headings = [];
|
|
37
|
+
let inFencedBlock = false;
|
|
38
|
+
let fenceChar = '';
|
|
39
|
+
let fenceLength = 0;
|
|
40
|
+
for (let index = 0; index < lines.length; index++) {
|
|
41
|
+
const line = lines[index] ?? '';
|
|
42
|
+
const trimmed = line.trimStart();
|
|
43
|
+
if (!inFencedBlock) {
|
|
44
|
+
const fence = /^(`{3,}|~{3,})/.exec(trimmed)?.[1];
|
|
45
|
+
if (fence) {
|
|
46
|
+
inFencedBlock = true;
|
|
47
|
+
fenceChar = fence.charAt(0);
|
|
48
|
+
fenceLength = fence.length;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const closeFence = /^(`{3,}|~{3,})\s*$/.exec(trimmed)?.[1];
|
|
54
|
+
if (closeFence && closeFence[0] === fenceChar && closeFence.length >= fenceLength) {
|
|
55
|
+
inFencedBlock = false;
|
|
56
|
+
}
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
// Skip indented code blocks (4 spaces or 1 tab)
|
|
60
|
+
if (/^(?: {4}|\t)/.test(line)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
// Match ATX headings: 1-6 # characters followed by a space
|
|
64
|
+
const headingMatch = /^(#{1,6})\s+(.+?)(?:\s+#+\s*)?$/.exec(trimmed);
|
|
65
|
+
const hashes = headingMatch?.[1];
|
|
66
|
+
const rawText = headingMatch?.[2];
|
|
67
|
+
if (hashes && rawText) {
|
|
68
|
+
const value = stripInlineMarkdown(rawText);
|
|
69
|
+
if (value) {
|
|
70
|
+
headings.push({
|
|
71
|
+
depth: hashes.length,
|
|
72
|
+
value,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
// Match setext headings:
|
|
78
|
+
// Heading level 1: Text followed by ===
|
|
79
|
+
// Heading level 2: Text followed by ---
|
|
80
|
+
const nextLine = lines[index + 1];
|
|
81
|
+
if (!nextLine || /^(?: {4}|\t)/.test(nextLine)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const underline = /^(=+|-+)\s*$/.exec(nextLine.trim())?.[1];
|
|
85
|
+
if (!underline) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const value = stripInlineMarkdown(trimmed);
|
|
89
|
+
if (!value) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
headings.push({
|
|
93
|
+
depth: underline[0] === '=' ? 1 : 2,
|
|
94
|
+
value,
|
|
95
|
+
});
|
|
96
|
+
index++;
|
|
97
|
+
}
|
|
98
|
+
return headings;
|
|
99
|
+
}
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
resolvedPath =
|
|
35
|
-
resolvedAbsolute
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
inputPath
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
58
|
-
|
|
94
|
+
// posix version
|
|
95
|
+
export function isAbsolute(path) {
|
|
96
|
+
return path.charAt(0) === '/';
|
|
59
97
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
paths
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
87
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
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(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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(
|
|
130
|
-
|
|
173
|
+
export function extname(path) {
|
|
174
|
+
return splitPath(path)[3];
|
|
131
175
|
}
|
|
132
|
-
const path = {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|