@scalar/json-magic 0.7.0 → 0.8.0
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/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +13 -0
- package/dist/bundle/bundle.d.ts.map +1 -1
- package/dist/bundle/bundle.js +1 -1
- package/dist/bundle/bundle.js.map +2 -2
- package/dist/bundle/value-generator.d.ts +6 -4
- package/dist/bundle/value-generator.d.ts.map +1 -1
- package/dist/bundle/value-generator.js +2 -5
- package/dist/bundle/value-generator.js.map +2 -2
- package/dist/helpers/generate-hash.d.ts +11 -0
- package/dist/helpers/generate-hash.d.ts.map +1 -0
- package/dist/helpers/generate-hash.js +16 -0
- package/dist/helpers/generate-hash.js.map +7 -0
- package/esbuild.ts +1 -0
- package/package.json +8 -2
- package/src/bundle/bundle.test.ts +17 -17
- package/src/bundle/bundle.ts +2 -1
- package/src/bundle/value-generator.ts +11 -15
- package/src/dereference/dereference.test.ts +4 -4
- package/src/helpers/generate-hash.test.ts +74 -0
- package/src/helpers/generate-hash.ts +29 -0
- package/dist/polyfills/index.d.ts +0 -2
- package/dist/polyfills/index.d.ts.map +0 -1
- package/dist/polyfills/index.js +0 -25
- package/dist/polyfills/index.js.map +0 -7
- package/dist/polyfills/path.d.ts +0 -24
- package/dist/polyfills/path.d.ts.map +0 -1
- package/dist/polyfills/path.js +0 -174
- package/dist/polyfills/path.js.map +0 -7
- package/src/polyfills/index.ts +0 -12
- package/src/polyfills/path.ts +0 -248
|
@@ -1,27 +1,23 @@
|
|
|
1
|
+
import { generateHash } from '@/helpers/generate-hash'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* Generates a short
|
|
4
|
+
* Generates a short hash from a string value using xxhash.
|
|
5
|
+
*
|
|
3
6
|
* This function is used to create unique identifiers for external references
|
|
4
|
-
* while keeping the hash length manageable. It uses
|
|
5
|
-
*
|
|
7
|
+
* while keeping the hash length manageable. It uses xxhash-wasm instead of
|
|
8
|
+
* crypto.subtle because crypto.subtle is only available in secure contexts (HTTPS) or on localhost.
|
|
9
|
+
* Returns the first 7 characters of the hash string.
|
|
6
10
|
* If the hash would be all numbers, it ensures at least one letter is included.
|
|
7
11
|
*
|
|
8
12
|
* @param value - The string to hash
|
|
9
|
-
* @returns A 7-character hexadecimal hash with at least one letter
|
|
13
|
+
* @returns A Promise that resolves to a 7-character hexadecimal hash with at least one letter
|
|
10
14
|
* @example
|
|
11
15
|
* // Returns "2ae91d7"
|
|
12
16
|
* await getHash("https://example.com/schema.json")
|
|
13
17
|
*/
|
|
14
|
-
export async function getHash(value: string) {
|
|
15
|
-
//
|
|
16
|
-
const
|
|
17
|
-
const data = encoder.encode(value)
|
|
18
|
-
|
|
19
|
-
// Hash the data
|
|
20
|
-
const hashBuffer = await crypto.subtle.digest('SHA-1', data)
|
|
21
|
-
|
|
22
|
-
// Convert buffer to hex string
|
|
23
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer))
|
|
24
|
-
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')
|
|
18
|
+
export async function getHash(value: string): Promise<string> {
|
|
19
|
+
// Hash the data using xxhash
|
|
20
|
+
const hashHex = await generateHash(value)
|
|
25
21
|
|
|
26
22
|
// Return first 7 characters of the hash, ensuring at least one letter
|
|
27
23
|
const hash = hashHex.substring(0, 7)
|
|
@@ -101,7 +101,7 @@ describe('dereference', () => {
|
|
|
101
101
|
success: true,
|
|
102
102
|
data: {
|
|
103
103
|
profile: {
|
|
104
|
-
'$ref': '#/x-ext/
|
|
104
|
+
'$ref': '#/x-ext/f87db7e',
|
|
105
105
|
'$ref-value': {
|
|
106
106
|
name: 'Jane Doe',
|
|
107
107
|
age: 25,
|
|
@@ -112,17 +112,17 @@ describe('dereference', () => {
|
|
|
112
112
|
},
|
|
113
113
|
},
|
|
114
114
|
address: {
|
|
115
|
-
'$ref': '#/x-ext/
|
|
115
|
+
'$ref': '#/x-ext/f87db7e/address',
|
|
116
116
|
'$ref-value': {
|
|
117
117
|
city: 'Los Angeles',
|
|
118
118
|
street: 'Sunset Boulevard',
|
|
119
119
|
},
|
|
120
120
|
},
|
|
121
121
|
'x-ext': {
|
|
122
|
-
'
|
|
122
|
+
'f87db7e': userProfile,
|
|
123
123
|
},
|
|
124
124
|
'x-ext-urls': {
|
|
125
|
-
'
|
|
125
|
+
'f87db7e': `${url}/users`,
|
|
126
126
|
},
|
|
127
127
|
},
|
|
128
128
|
})
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { generateHash } from './generate-hash'
|
|
4
|
+
|
|
5
|
+
describe('generateHash', () => {
|
|
6
|
+
it('generates a hash from a simple string', async () => {
|
|
7
|
+
const result = await generateHash('hello world')
|
|
8
|
+
|
|
9
|
+
// Should return a non-empty string
|
|
10
|
+
expect(result).toBeTruthy()
|
|
11
|
+
expect(typeof result).toBe('string')
|
|
12
|
+
expect(result.length).toBeGreaterThan(0)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('produces consistent hashes for the same input', async () => {
|
|
16
|
+
const input = 'consistent-test-string'
|
|
17
|
+
const hash1 = await generateHash(input)
|
|
18
|
+
const hash2 = await generateHash(input)
|
|
19
|
+
const hash3 = await generateHash(input)
|
|
20
|
+
|
|
21
|
+
// Same input should always produce the same hash
|
|
22
|
+
expect(hash1).toBe(hash2)
|
|
23
|
+
expect(hash2).toBe(hash3)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('produces different hashes for different inputs', async () => {
|
|
27
|
+
const hash1 = await generateHash('first string')
|
|
28
|
+
const hash2 = await generateHash('second string')
|
|
29
|
+
const hash3 = await generateHash('first strinG') // Case-sensitive
|
|
30
|
+
|
|
31
|
+
// Different inputs should produce different hashes
|
|
32
|
+
expect(hash1).not.toBe(hash2)
|
|
33
|
+
expect(hash1).not.toBe(hash3)
|
|
34
|
+
expect(hash2).not.toBe(hash3)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('handles empty string', async () => {
|
|
38
|
+
const result = await generateHash('')
|
|
39
|
+
|
|
40
|
+
// Should handle empty strings without throwing
|
|
41
|
+
expect(result).toBeTruthy()
|
|
42
|
+
expect(typeof result).toBe('string')
|
|
43
|
+
|
|
44
|
+
// Empty string should produce a consistent hash
|
|
45
|
+
const result2 = await generateHash('')
|
|
46
|
+
expect(result).toBe(result2)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('handles special characters and unicode', async () => {
|
|
50
|
+
const inputs = [
|
|
51
|
+
'🚀 emoji test',
|
|
52
|
+
'special chars: !@#$%^&*()',
|
|
53
|
+
'unicode: こんにちは世界',
|
|
54
|
+
'newlines\nand\ttabs',
|
|
55
|
+
'mixed: 👾 special!@# unicode: 你好',
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
const hashes = await Promise.all(inputs.map((input) => generateHash(input)))
|
|
59
|
+
|
|
60
|
+
// All should produce valid hashes
|
|
61
|
+
hashes.forEach((hash) => {
|
|
62
|
+
expect(hash).toBeTruthy()
|
|
63
|
+
expect(typeof hash).toBe('string')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
// All should be unique
|
|
67
|
+
const uniqueHashes = new Set(hashes)
|
|
68
|
+
expect(uniqueHashes.size).toBe(inputs.length)
|
|
69
|
+
|
|
70
|
+
// Should be consistent on repeated calls
|
|
71
|
+
const repeatedHash = await generateHash('🚀 emoji test')
|
|
72
|
+
expect(repeatedHash).toBe(hashes[0])
|
|
73
|
+
})
|
|
74
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import xxhash from 'xxhash-wasm'
|
|
2
|
+
|
|
3
|
+
let hasherInstance: Awaited<ReturnType<typeof xxhash>> | null = null
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Initialize the xxhash hasher instance lazily
|
|
7
|
+
*
|
|
8
|
+
* This is just a workaround because we cannot use top level await in a UMD module (standalone references)
|
|
9
|
+
*/
|
|
10
|
+
const getHasher = async () => {
|
|
11
|
+
if (!hasherInstance) {
|
|
12
|
+
hasherInstance = await xxhash()
|
|
13
|
+
}
|
|
14
|
+
return hasherInstance
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Generate a hash from a string using the xxhash algorithm
|
|
19
|
+
*
|
|
20
|
+
* We cannot use crypto.subtle because it is only available in secure contexts (HTTPS) or on localhost.
|
|
21
|
+
* So this is just a wrapper around the xxhash-wasm library instead.
|
|
22
|
+
*
|
|
23
|
+
* @param input - The string to hash
|
|
24
|
+
* @returns A Promise that resolves to the hash of the input string
|
|
25
|
+
*/
|
|
26
|
+
export const generateHash = async (input: string): Promise<string> => {
|
|
27
|
+
const { h64ToString } = await getHasher()
|
|
28
|
+
return h64ToString(input)
|
|
29
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/polyfills/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,SAAS,EACT,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,GAAG,EACH,SAAS,EACT,OAAO,EACP,QAAQ,EACR,OAAO,GACR,MAAM,QAAQ,CAAA"}
|
package/dist/polyfills/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolve,
|
|
3
|
-
normalize,
|
|
4
|
-
isAbsolute,
|
|
5
|
-
join,
|
|
6
|
-
relative,
|
|
7
|
-
sep,
|
|
8
|
-
delimiter,
|
|
9
|
-
dirname,
|
|
10
|
-
basename,
|
|
11
|
-
extname
|
|
12
|
-
} from "./path.js";
|
|
13
|
-
export {
|
|
14
|
-
basename,
|
|
15
|
-
delimiter,
|
|
16
|
-
dirname,
|
|
17
|
-
extname,
|
|
18
|
-
isAbsolute,
|
|
19
|
-
join,
|
|
20
|
-
normalize,
|
|
21
|
-
relative,
|
|
22
|
-
resolve,
|
|
23
|
-
sep
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/polyfills/index.ts"],
|
|
4
|
-
"sourcesContent": ["export {\n resolve,\n normalize,\n isAbsolute,\n join,\n relative,\n sep,\n delimiter,\n dirname,\n basename,\n extname,\n} from './path'\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/polyfills/path.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare function resolve(...parameters: any[]): string;
|
|
2
|
-
export declare function normalize(path: any): string;
|
|
3
|
-
export declare function isAbsolute(path: any): boolean;
|
|
4
|
-
export declare function join(...paths: string[]): string;
|
|
5
|
-
export declare function relative(from: any, to: any): string;
|
|
6
|
-
export declare const sep = "/";
|
|
7
|
-
export declare const delimiter = ":";
|
|
8
|
-
export declare function dirname(path: any): string;
|
|
9
|
-
export declare function basename(path: any, ext: any): string;
|
|
10
|
-
export declare function extname(path: any): string;
|
|
11
|
-
declare const _default: {
|
|
12
|
-
extname: typeof extname;
|
|
13
|
-
basename: typeof basename;
|
|
14
|
-
dirname: typeof dirname;
|
|
15
|
-
sep: string;
|
|
16
|
-
delimiter: string;
|
|
17
|
-
relative: typeof relative;
|
|
18
|
-
join: typeof join;
|
|
19
|
-
isAbsolute: typeof isAbsolute;
|
|
20
|
-
normalize: typeof normalize;
|
|
21
|
-
resolve: typeof resolve;
|
|
22
|
-
};
|
|
23
|
-
export default _default;
|
|
24
|
-
//# sourceMappingURL=path.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/polyfills/path.ts"],"names":[],"mappings":"AA4DA,wBAAgB,OAAO,CAAC,GAAG,UAAU,OAAA,UA6BpC;AAID,wBAAgB,SAAS,CAAC,IAAI,KAAA,UAkB7B;AAGD,wBAAgB,UAAU,CAAC,IAAI,KAAA,WAE9B;AAGD,wBAAgB,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,UAStC;AAID,wBAAgB,QAAQ,CAAC,IAAI,KAAA,EAAE,EAAE,KAAA,UA6ChC;AAED,eAAO,MAAM,GAAG,MAAM,CAAA;AACtB,eAAO,MAAM,SAAS,MAAM,CAAA;AAE5B,wBAAgB,OAAO,CAAC,IAAI,KAAA,UAiB3B;AAED,wBAAgB,QAAQ,CAAC,IAAI,KAAA,EAAE,GAAG,KAAA,UAOjC;AAED,wBAAgB,OAAO,CAAC,IAAI,KAAA,UAE3B;;;;;;;;;;;;;AACD,wBAWC"}
|
package/dist/polyfills/path.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
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--;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
if (allowAboveRoot) {
|
|
16
|
-
for (; up--; up) {
|
|
17
|
-
parts.unshift("..");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return parts;
|
|
21
|
-
}
|
|
22
|
-
const splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^/]+?|)(\.[^./]*|))(?:[/]*)$/;
|
|
23
|
-
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 path = i >= 0 ? parameters[i] : "/";
|
|
28
|
-
if (typeof path !== "string") {
|
|
29
|
-
throw new TypeError("Arguments to path.resolve must be strings");
|
|
30
|
-
}
|
|
31
|
-
if (!path) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
resolvedPath = path + "/" + resolvedPath;
|
|
35
|
-
resolvedAbsolute = path.charAt(0) === "/";
|
|
36
|
-
}
|
|
37
|
-
resolvedPath = normalizeArray(
|
|
38
|
-
filter(resolvedPath.split("/"), (p) => !!p),
|
|
39
|
-
!resolvedAbsolute
|
|
40
|
-
).join("/");
|
|
41
|
-
return (resolvedAbsolute ? "/" : "") + resolvedPath || ".";
|
|
42
|
-
}
|
|
43
|
-
function normalize(path) {
|
|
44
|
-
const isPathAbsolute = isAbsolute(path), trailingSlash = substr(path, -1) === "/";
|
|
45
|
-
path = normalizeArray(
|
|
46
|
-
filter(path.split("/"), (p) => !!p),
|
|
47
|
-
!isPathAbsolute
|
|
48
|
-
).join("/");
|
|
49
|
-
if (!path && !isPathAbsolute) {
|
|
50
|
-
path = ".";
|
|
51
|
-
}
|
|
52
|
-
if (path && trailingSlash) {
|
|
53
|
-
path += "/";
|
|
54
|
-
}
|
|
55
|
-
return (isPathAbsolute ? "/" : "") + path;
|
|
56
|
-
}
|
|
57
|
-
function isAbsolute(path) {
|
|
58
|
-
return path.charAt(0) === "/";
|
|
59
|
-
}
|
|
60
|
-
function join(...paths) {
|
|
61
|
-
return normalize(
|
|
62
|
-
filter(paths, (p, _index) => {
|
|
63
|
-
if (typeof p !== "string") {
|
|
64
|
-
throw new TypeError("Arguments to path.join must be strings");
|
|
65
|
-
}
|
|
66
|
-
return p;
|
|
67
|
-
}).join("/")
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
function relative(from, to) {
|
|
71
|
-
from = resolve(from).substr(1);
|
|
72
|
-
to = resolve(to).substr(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
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (start > end) {
|
|
87
|
-
return [];
|
|
88
|
-
}
|
|
89
|
-
return arr.slice(start, end - start + 1);
|
|
90
|
-
}
|
|
91
|
-
const fromParts = trim(from.split("/"));
|
|
92
|
-
const toParts = trim(to.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;
|
|
99
|
-
}
|
|
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("/");
|
|
107
|
-
}
|
|
108
|
-
const sep = "/";
|
|
109
|
-
const delimiter = ":";
|
|
110
|
-
function dirname(path) {
|
|
111
|
-
const result = splitPath(path), root = result[0];
|
|
112
|
-
let dir = result[1];
|
|
113
|
-
if (!root && !dir) {
|
|
114
|
-
return ".";
|
|
115
|
-
}
|
|
116
|
-
if (dir) {
|
|
117
|
-
dir = dir.substr(0, dir.length - 1);
|
|
118
|
-
}
|
|
119
|
-
return root + dir;
|
|
120
|
-
}
|
|
121
|
-
function basename(path, ext) {
|
|
122
|
-
let f = splitPath(path)[2];
|
|
123
|
-
if (ext && f.substr(-1 * ext.length) === ext) {
|
|
124
|
-
f = f.substr(0, f.length - ext.length);
|
|
125
|
-
}
|
|
126
|
-
return f;
|
|
127
|
-
}
|
|
128
|
-
function extname(path) {
|
|
129
|
-
return splitPath(path)[3];
|
|
130
|
-
}
|
|
131
|
-
var path_default = {
|
|
132
|
-
extname,
|
|
133
|
-
basename,
|
|
134
|
-
dirname,
|
|
135
|
-
sep,
|
|
136
|
-
delimiter,
|
|
137
|
-
relative,
|
|
138
|
-
join,
|
|
139
|
-
isAbsolute,
|
|
140
|
-
normalize,
|
|
141
|
-
resolve
|
|
142
|
-
};
|
|
143
|
-
function filter(xs, f) {
|
|
144
|
-
if (xs.filter) {
|
|
145
|
-
return xs.filter(f);
|
|
146
|
-
}
|
|
147
|
-
const res = [];
|
|
148
|
-
for (let i = 0; i < xs.length; i++) {
|
|
149
|
-
if (f(xs[i], i, xs)) {
|
|
150
|
-
res.push(xs[i]);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return res;
|
|
154
|
-
}
|
|
155
|
-
const substr = "ab".substr(-1) === "b" ? (str, start, len) => str.substr(start, len) : (str, start, len) => {
|
|
156
|
-
if (start < 0) {
|
|
157
|
-
start = str.length + start;
|
|
158
|
-
}
|
|
159
|
-
return str.substr(start, len);
|
|
160
|
-
};
|
|
161
|
-
export {
|
|
162
|
-
basename,
|
|
163
|
-
path_default as default,
|
|
164
|
-
delimiter,
|
|
165
|
-
dirname,
|
|
166
|
-
extname,
|
|
167
|
-
isAbsolute,
|
|
168
|
-
join,
|
|
169
|
-
normalize,
|
|
170
|
-
relative,
|
|
171
|
-
resolve,
|
|
172
|
-
sep
|
|
173
|
-
};
|
|
174
|
-
//# sourceMappingURL=path.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/polyfills/path.ts"],
|
|
4
|
-
"sourcesContent": ["// @ts-nocheck\n\n// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n// resolves . and .. elements in a path array with directory names there\n// must be no slashes, empty elements, or device names (c:\\) in the array\n// (so also no leading and trailing slashes - it does not distinguish\n// relative and absolute paths)\nfunction normalizeArray(parts, allowAboveRoot) {\n // if the path tries to go above the root, `up` ends up > 0\n let up = 0\n for (let i = parts.length - 1; i >= 0; i--) {\n const last = parts[i]\n if (last === '.') {\n parts.splice(i, 1)\n } else if (last === '..') {\n parts.splice(i, 1)\n up++\n } else if (up) {\n parts.splice(i, 1)\n up--\n }\n }\n\n // if the path is allowed to go above the root, restore leading ..s\n if (allowAboveRoot) {\n for (; up--; up) {\n parts.unshift('..')\n }\n }\n\n return parts\n}\n\n// Split a filename into [root, dir, basename, ext], unix version\n// 'root' is just a slash, or nothing.\nconst splitPathRe = /^(\\/?|)([\\s\\S]*?)((?:\\.{1,2}|[^/]+?|)(\\.[^./]*|))(?:[/]*)$/\nconst splitPath = (filename) => splitPathRe.exec(filename).slice(1)\n\n// path.resolve([from ...], to)\n// posix version\nexport function resolve(...parameters) {\n let resolvedPath = '',\n resolvedAbsolute = false\n\n for (let i = parameters.length - 1; i >= -1 && !resolvedAbsolute; i--) {\n const path = i >= 0 ? parameters[i] : '/'\n\n // Skip empty and invalid entries\n if (typeof path !== 'string') {\n throw new TypeError('Arguments to path.resolve must be strings')\n }\n if (!path) {\n continue\n }\n\n resolvedPath = path + '/' + resolvedPath\n resolvedAbsolute = path.charAt(0) === '/'\n }\n\n // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when process.cwd() fails)\n\n // Normalize the path\n resolvedPath = normalizeArray(\n filter(resolvedPath.split('/'), (p) => !!p),\n !resolvedAbsolute,\n ).join('/')\n\n return (resolvedAbsolute ? '/' : '') + resolvedPath || '.'\n}\n\n// path.normalize(path)\n// posix version\nexport function normalize(path) {\n const isPathAbsolute = isAbsolute(path),\n trailingSlash = substr(path, -1) === '/'\n\n // Normalize the path\n path = normalizeArray(\n filter(path.split('/'), (p) => !!p),\n !isPathAbsolute,\n ).join('/')\n\n if (!path && !isPathAbsolute) {\n path = '.'\n }\n if (path && trailingSlash) {\n path += '/'\n }\n\n return (isPathAbsolute ? '/' : '') + path\n}\n\n// posix version\nexport function isAbsolute(path) {\n return path.charAt(0) === '/'\n}\n\n// posix version\nexport function join(...paths: string[]) {\n return normalize(\n filter(paths, (p, _index) => {\n if (typeof p !== 'string') {\n throw new TypeError('Arguments to path.join must be strings')\n }\n return p\n }).join('/'),\n )\n}\n\n// path.relative(from, to)\n// posix version\nexport function relative(from, to) {\n from = resolve(from).substr(1)\n to = resolve(to).substr(1)\n\n function trim(arr) {\n let start = 0\n for (; start < arr.length; start++) {\n if (arr[start] !== '') {\n break\n }\n }\n\n let end = arr.length - 1\n for (; end >= 0; end--) {\n if (arr[end] !== '') {\n break\n }\n }\n\n if (start > end) {\n return []\n }\n return arr.slice(start, end - start + 1)\n }\n\n const fromParts = trim(from.split('/'))\n const toParts = trim(to.split('/'))\n\n const length = Math.min(fromParts.length, toParts.length)\n let samePartsLength = length\n for (let i = 0; i < length; i++) {\n if (fromParts[i] !== toParts[i]) {\n samePartsLength = i\n break\n }\n }\n\n let outputParts = []\n for (let i = samePartsLength; i < fromParts.length; i++) {\n outputParts.push('..')\n }\n\n outputParts = outputParts.concat(toParts.slice(samePartsLength))\n\n return outputParts.join('/')\n}\n\nexport const sep = '/'\nexport const delimiter = ':'\n\nexport function dirname(path) {\n const result = splitPath(path),\n root = result[0]\n\n let dir = result[1]\n\n if (!root && !dir) {\n // No dirname whatsoever\n return '.'\n }\n\n if (dir) {\n // It has a dirname, strip trailing slash\n dir = dir.substr(0, dir.length - 1)\n }\n\n return root + dir\n}\n\nexport function basename(path, ext) {\n let f = splitPath(path)[2]\n // TODO: make this comparison case-insensitive on windows?\n if (ext && f.substr(-1 * ext.length) === ext) {\n f = f.substr(0, f.length - ext.length)\n }\n return f\n}\n\nexport function extname(path) {\n return splitPath(path)[3]\n}\nexport default {\n extname: extname,\n basename: basename,\n dirname: dirname,\n sep: sep,\n delimiter: delimiter,\n relative: relative,\n join: join,\n isAbsolute: isAbsolute,\n normalize: normalize,\n resolve: resolve,\n}\nfunction filter(xs, f) {\n if (xs.filter) {\n return xs.filter(f)\n }\n const res = []\n for (let i = 0; i < xs.length; i++) {\n if (f(xs[i], i, xs)) {\n res.push(xs[i])\n }\n }\n return res\n}\n\n// String.prototype.substr - negative index don't work in IE8\nconst substr =\n 'ab'.substr(-1) === 'b'\n ? (str, start, len) => str.substr(start, len)\n : (str, start, len) => {\n if (start < 0) {\n start = str.length + start\n }\n return str.substr(start, len)\n }\n"],
|
|
5
|
-
"mappings": "AA2BA,SAAS,eAAe,OAAO,gBAAgB;AAE7C,MAAI,KAAK;AACT,WAAS,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;AAC1C,UAAM,OAAO,MAAM,CAAC;AACpB,QAAI,SAAS,KAAK;AAChB,YAAM,OAAO,GAAG,CAAC;AAAA,IACnB,WAAW,SAAS,MA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