locter 0.0.1 → 0.1.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.
- package/dist/locator/async.d.ts +3 -0
- package/dist/locator/async.js +73 -0
- package/dist/locator/async.js.map +1 -0
- package/dist/locator/index.d.ts +2 -1
- package/dist/locator/index.js +2 -1
- package/dist/locator/index.js.map +1 -1
- package/dist/locator/sync.d.ts +3 -0
- package/dist/locator/sync.js +58 -0
- package/dist/locator/sync.js.map +1 -0
- package/dist/locator/type.d.ts +0 -1
- package/dist/locator/utils.js +5 -7
- package/dist/locator/utils.js.map +1 -1
- package/package.json +9 -6
- package/dist/locator/module.d.ts +0 -3
- package/dist/locator/module.js +0 -71
- package/dist/locator/module.js.map +0 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { LocatorInfo, LocatorOptions } from './type';
|
|
2
|
+
export declare function locateFiles(pattern: string, options?: Partial<LocatorOptions>): Promise<LocatorInfo[]>;
|
|
3
|
+
export declare function locateFile(pattern: string, options?: Partial<LocatorOptions>): Promise<LocatorInfo | undefined>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.locateFile = exports.locateFiles = void 0;
|
|
22
|
+
const glob_1 = require("glob");
|
|
23
|
+
const path_1 = __importDefault(require("path"));
|
|
24
|
+
const util_1 = require("util");
|
|
25
|
+
const utils_1 = require("./utils");
|
|
26
|
+
const globAsync = (0, util_1.promisify)(glob_1.glob);
|
|
27
|
+
function locateFiles(pattern, options) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
options = (0, utils_1.buildLocatorOptions)(options);
|
|
30
|
+
const items = [];
|
|
31
|
+
for (let i = 0; i < options.paths.length; i++) {
|
|
32
|
+
const files = yield globAsync(pattern, {
|
|
33
|
+
absolute: true,
|
|
34
|
+
cwd: options.paths[i],
|
|
35
|
+
nodir: true,
|
|
36
|
+
});
|
|
37
|
+
for (let j = 0; j < files.length; j++) {
|
|
38
|
+
const fileInfo = path_1.default.parse(files[j]);
|
|
39
|
+
items.push({
|
|
40
|
+
path: fileInfo.dir.split('/').join(path_1.default.sep),
|
|
41
|
+
fileName: fileInfo.name,
|
|
42
|
+
fileExtension: fileInfo.ext,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return items;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.locateFiles = locateFiles;
|
|
50
|
+
function locateFile(pattern, options) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
options = (0, utils_1.buildLocatorOptions)(options);
|
|
53
|
+
for (let i = 0; i < options.paths.length; i++) {
|
|
54
|
+
const files = yield globAsync(pattern, {
|
|
55
|
+
absolute: true,
|
|
56
|
+
cwd: options.paths[i],
|
|
57
|
+
nodir: true,
|
|
58
|
+
});
|
|
59
|
+
const element = files.shift();
|
|
60
|
+
if (element) {
|
|
61
|
+
const fileInfo = path_1.default.parse(element);
|
|
62
|
+
return {
|
|
63
|
+
path: fileInfo.dir.split('/').join(path_1.default.sep),
|
|
64
|
+
fileName: fileInfo.name,
|
|
65
|
+
fileExtension: fileInfo.ext,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
exports.locateFile = locateFile;
|
|
73
|
+
//# sourceMappingURL=async.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.js","sourceRoot":"","sources":["../../src/locator/async.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;AAEH,+BAA4B;AAC5B,gDAAwB;AACxB,+BAAiC;AAEjC,mCAA8C;AAE9C,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,WAAI,CAAC,CAAC;AAElC,SAAsB,WAAW,CAC7B,OAAe,EACf,OAAiC;;QAEjC,OAAO,GAAG,IAAA,2BAAmB,EAAC,OAAO,CAAC,CAAC;QAEvC,MAAM,KAAK,GAAG,EAAE,CAAC;QAEjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC3C,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE;gBACnC,QAAQ,EAAE,IAAI;gBACd,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;gBACrB,KAAK,EAAE,IAAI;aACd,CAAC,CAAC;YAEH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACnC,MAAM,QAAQ,GAAG,cAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,C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(m, exports) {
|
|
|
20
20
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
__exportStar(require("./
|
|
23
|
+
__exportStar(require("./async"), exports);
|
|
24
|
+
__exportStar(require("./sync"), exports);
|
|
24
25
|
__exportStar(require("./type"), exports);
|
|
25
26
|
__exportStar(require("./utils"), exports);
|
|
26
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/locator/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/locator/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,yCAAuB;AACvB,yCAAuB;AACvB,0CAAwB"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { LocatorInfo, LocatorOptions } from './type';
|
|
2
|
+
export declare function locateFilesSync(pattern: string, options?: Partial<LocatorOptions>): LocatorInfo[];
|
|
3
|
+
export declare function locateFileSync(pattern: string, options?: Partial<LocatorOptions>): LocatorInfo | undefined;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.locateFileSync = exports.locateFilesSync = void 0;
|
|
13
|
+
const glob_1 = require("glob");
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const utils_1 = require("./utils");
|
|
16
|
+
function locateFilesSync(pattern, options) {
|
|
17
|
+
options = (0, utils_1.buildLocatorOptions)(options);
|
|
18
|
+
const items = [];
|
|
19
|
+
for (let i = 0; i < options.paths.length; i++) {
|
|
20
|
+
const files = (0, glob_1.sync)(pattern, {
|
|
21
|
+
absolute: true,
|
|
22
|
+
cwd: options.paths[i],
|
|
23
|
+
nodir: true,
|
|
24
|
+
});
|
|
25
|
+
for (let j = 0; j < files.length; j++) {
|
|
26
|
+
const fileInfo = path_1.default.parse(files[j]);
|
|
27
|
+
items.push({
|
|
28
|
+
path: fileInfo.dir.split('/').join(path_1.default.sep),
|
|
29
|
+
fileName: fileInfo.name,
|
|
30
|
+
fileExtension: fileInfo.ext,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return items;
|
|
35
|
+
}
|
|
36
|
+
exports.locateFilesSync = locateFilesSync;
|
|
37
|
+
function locateFileSync(pattern, options) {
|
|
38
|
+
options = (0, utils_1.buildLocatorOptions)(options);
|
|
39
|
+
for (let i = 0; i < options.paths.length; i++) {
|
|
40
|
+
const files = (0, glob_1.sync)(pattern, {
|
|
41
|
+
absolute: true,
|
|
42
|
+
cwd: options.paths[i],
|
|
43
|
+
nodir: true,
|
|
44
|
+
});
|
|
45
|
+
const element = files.shift();
|
|
46
|
+
if (element) {
|
|
47
|
+
const fileInfo = path_1.default.parse(element);
|
|
48
|
+
return {
|
|
49
|
+
path: fileInfo.dir.split('/').join(path_1.default.sep),
|
|
50
|
+
fileName: fileInfo.name,
|
|
51
|
+
fileExtension: fileInfo.ext,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
exports.locateFileSync = locateFileSync;
|
|
58
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|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M,EAAE,CAAC,EAAE,EAAE;QAC3C,MAAM,KAAK,GAAG,IAAA,WAAQ,EAAC,OAAO,EAAE;YAC5B,QAAQ,EAAE,IAAI;YACd,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;YACrB,KAAK,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;QAC9B,IAAI,OAAO,EAAE;YACT,MAAM,QAAQ,GAAG,cAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAErC,OAAO;gBACH,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAI,CAAC,GAAG,CAAC;gBAC5C,QAAQ,EAAE,QAAQ,CAAC,IAAI;gBACvB,aAAa,EAAE,QAAQ,CAAC,GAAG;aAC9B,CAAC;SACL;KACJ;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AA1BD,wCA0BC"}
|
package/dist/locator/type.d.ts
CHANGED
package/dist/locator/utils.js
CHANGED
|
@@ -12,8 +12,9 @@ function buildLocatorOptions(options) {
|
|
|
12
12
|
options = options || {};
|
|
13
13
|
options.paths = options.paths || [];
|
|
14
14
|
options.paths = (0, utils_1.toArray)(options.paths);
|
|
15
|
-
options.
|
|
16
|
-
(
|
|
15
|
+
if (options.paths.length === 0) {
|
|
16
|
+
options.paths.push(process.cwd());
|
|
17
|
+
}
|
|
17
18
|
return options;
|
|
18
19
|
}
|
|
19
20
|
exports.buildLocatorOptions = buildLocatorOptions;
|
|
@@ -30,11 +31,8 @@ function isLocatorInfo(data) {
|
|
|
30
31
|
typeof data.fileName !== 'string') {
|
|
31
32
|
return false;
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
typeof data.fileExtension !== 'string')
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
return true;
|
|
34
|
+
return !(!(0, utils_1.hasOwnProperty)(data, 'fileExtension') ||
|
|
35
|
+
typeof data.fileExtension !== 'string');
|
|
38
36
|
}
|
|
39
37
|
exports.isLocatorInfo = isLocatorInfo;
|
|
40
38
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/locator/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/locator/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,oCAAmD;AAEnD,SAAgB,mBAAmB,CAAC,OAAiC;IACjE,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IAExB,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;IACpC,OAAO,CAAC,KAAK,GAAG,IAAA,eAAO,EAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5B,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;KACrC;IAED,OAAO,OAAyB,CAAC;AACrC,CAAC;AAVD,kDAUC;AAED,0BAA0B;AAC1B,SAAgB,aAAa,CAAC,IAAa;IACvC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC1B,OAAO,KAAK,CAAC;KAChB;IAED,IACI,CAAC,IAAA,sBAAc,EAAC,IAAI,EAAE,MAAM,CAAC;QAC7B,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAC/B;QACE,OAAO,KAAK,CAAC;KAChB;IAED,IACI,CAAC,IAAA,sBAAc,EAAC,IAAI,EAAE,UAAU,CAAC;QACjC,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ,EACnC;QACE,OAAO,KAAK,CAAC;KAChB;IAED,OAAO,CAAC,CAAC,CAAC,IAAA,sBAAc,EAAC,IAAI,EAAE,eAAe,CAAC;QAC3C,OAAO,IAAI,CAAC,aAAa,KAAK,QAAQ,CAAC,CAAC;AAChD,CAAC;AArBD,sCAqBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Locter is a library to locate a file by criteria and load it",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Peter Placzek",
|
|
@@ -31,18 +31,21 @@
|
|
|
31
31
|
],
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tada5hi/eslint-config-typescript": "^1.0.
|
|
34
|
+
"@tada5hi/eslint-config-typescript": "^1.0.3",
|
|
35
35
|
"@types/glob": "^7.1.3",
|
|
36
36
|
"@types/jest": "^27.5.0",
|
|
37
|
-
"@types/node": "^17.0.
|
|
37
|
+
"@types/node": "^17.0.36",
|
|
38
38
|
"@types/yargs": "^17.0.10",
|
|
39
39
|
"coveralls": "^3.1.0",
|
|
40
40
|
"cross-env": "^7.0.3",
|
|
41
|
-
"eslint": "^8.
|
|
41
|
+
"eslint": "^8.16.0",
|
|
42
42
|
"jest": "^27.5.1",
|
|
43
43
|
"np": "^7.6.1",
|
|
44
44
|
"ts-jest": "^27.1.4",
|
|
45
|
-
"ts-node": "^10.
|
|
46
|
-
"typescript": "^4.
|
|
45
|
+
"ts-node": "^10.8.0",
|
|
46
|
+
"typescript": "^4.7.2"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"glob": "^8.0.3"
|
|
47
50
|
}
|
|
48
51
|
}
|
package/dist/locator/module.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { LocatorInfo, LocatorOptions } from './type';
|
|
2
|
-
export declare function locateFile(fileName: string, options?: Partial<LocatorOptions>): Promise<LocatorInfo | undefined>;
|
|
3
|
-
export declare function locateFileSync(fileName: string, options?: Partial<LocatorOptions>): LocatorInfo | undefined;
|
package/dist/locator/module.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2022.
|
|
4
|
-
* Author Peter Placzek (tada5hi)
|
|
5
|
-
* For the full copyright and license information,
|
|
6
|
-
* view the LICENSE file that was distributed with this source code.
|
|
7
|
-
*/
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.locateFileSync = exports.locateFile = void 0;
|
|
22
|
-
const path_1 = __importDefault(require("path"));
|
|
23
|
-
const fs_1 = __importDefault(require("fs"));
|
|
24
|
-
const utils_1 = require("./utils");
|
|
25
|
-
function locateFile(fileName, options) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
options = (0, utils_1.buildLocatorOptions)(options);
|
|
28
|
-
for (let i = 0; i < options.paths.length; i++) {
|
|
29
|
-
const filePath = path_1.default.join(options.paths[i], fileName);
|
|
30
|
-
for (let j = 0; j < options.extensions.length; j++) {
|
|
31
|
-
const filePathWithExtension = filePath + options.extensions[j];
|
|
32
|
-
try {
|
|
33
|
-
yield fs_1.default.promises.access(filePathWithExtension, fs_1.default.constants.R_OK | fs_1.default.constants.F_OK);
|
|
34
|
-
return {
|
|
35
|
-
path: options.paths[i],
|
|
36
|
-
fileName,
|
|
37
|
-
fileExtension: options.extensions[j],
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
// do nothing ;)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
exports.locateFile = locateFile;
|
|
49
|
-
function locateFileSync(fileName, options) {
|
|
50
|
-
options = (0, utils_1.buildLocatorOptions)(options);
|
|
51
|
-
for (let i = 0; i < options.paths.length; i++) {
|
|
52
|
-
const filePath = path_1.default.join(options.paths[i], fileName);
|
|
53
|
-
for (let j = 0; j < options.extensions.length; j++) {
|
|
54
|
-
const filePathWithExtension = filePath + options.extensions[j];
|
|
55
|
-
try {
|
|
56
|
-
fs_1.default.accessSync(filePathWithExtension, fs_1.default.constants.R_OK | fs_1.default.constants.F_OK);
|
|
57
|
-
return {
|
|
58
|
-
path: options.paths[i],
|
|
59
|
-
fileName,
|
|
60
|
-
fileExtension: options.extensions[j],
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
catch (e) {
|
|
64
|
-
// do nothing ;)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
exports.locateFileSync = locateFileSync;
|
|
71
|
-
//# sourceMappingURL=module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/locator/module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;AAEH,gDAAwB;AACxB,4CAAoB;AAEpB,mCAA8C;AAE9C,SAAsB,UAAU,CAC5B,QAAgB,EAChB,OAAiC;;QAEjC,OAAO,GAAG,IAAA,2BAAmB,E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