@wocker/utils 1.0.0 → 1.0.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.
- package/lib/demuxOutput.d.ts +2 -0
- package/lib/demuxOutput.js +19 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/normalizeOptions.d.ts +10 -0
- package/lib/normalizeOptions.js +23 -0
- package/lib/promptConfig.d.ts +14 -0
- package/lib/promptConfig.js +79 -0
- package/lib/promptConfirm.d.ts +1 -1
- package/lib/promptSelect.d.ts +10 -8
- package/lib/promptSelect.js +20 -18
- package/lib/volumeFormat.d.ts +6 -0
- package/lib/volumeFormat.js +8 -0
- package/lib/volumeParse.d.ts +1 -0
- package/lib/volumeParse.js +11 -0
- package/package.json +6 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.demuxOutput = void 0;
|
|
4
|
+
const demuxOutput = (buffer) => {
|
|
5
|
+
let nextDataLength = null, output = Buffer.from([]);
|
|
6
|
+
while (buffer.length > 0) {
|
|
7
|
+
const header = bufferSlice(8);
|
|
8
|
+
nextDataLength = header.readUInt32BE(4);
|
|
9
|
+
const content = bufferSlice(nextDataLength);
|
|
10
|
+
output = Buffer.concat([output, content]);
|
|
11
|
+
}
|
|
12
|
+
function bufferSlice(end) {
|
|
13
|
+
const out = buffer.slice(0, end);
|
|
14
|
+
buffer = Buffer.from(buffer.slice(end, buffer.length));
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
return output;
|
|
18
|
+
};
|
|
19
|
+
exports.demuxOutput = demuxOutput;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -14,7 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./demuxOutput"), exports);
|
|
18
|
+
__exportStar(require("./promptConfig"), exports);
|
|
17
19
|
__exportStar(require("./promptConfirm"), exports);
|
|
18
20
|
__exportStar(require("./promptGroup"), exports);
|
|
19
21
|
__exportStar(require("./promptSelect"), exports);
|
|
20
22
|
__exportStar(require("./promptText"), exports);
|
|
23
|
+
__exportStar(require("./volumeFormat"), exports);
|
|
24
|
+
__exportStar(require("./volumeParse"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeOptions = void 0;
|
|
4
|
+
const normalizeOptions = (rawOptions) => {
|
|
5
|
+
return Array.isArray(rawOptions)
|
|
6
|
+
? rawOptions.map((option) => {
|
|
7
|
+
return {
|
|
8
|
+
label: typeof option === "string"
|
|
9
|
+
? option
|
|
10
|
+
: option.label || option.value || "",
|
|
11
|
+
value: typeof option === "string"
|
|
12
|
+
? option
|
|
13
|
+
: option.value || ""
|
|
14
|
+
};
|
|
15
|
+
})
|
|
16
|
+
: Object.keys(rawOptions).map((value) => {
|
|
17
|
+
return {
|
|
18
|
+
label: rawOptions[value],
|
|
19
|
+
value
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
exports.normalizeOptions = normalizeOptions;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PromptConfirmOptions } from "./promptConfirm";
|
|
2
|
+
import { PromptSelectOptions } from "./promptSelect";
|
|
3
|
+
import { PromptTextOptions } from "./promptText";
|
|
4
|
+
type ConfirmOptions = PromptConfirmOptions & {
|
|
5
|
+
type: "boolean";
|
|
6
|
+
};
|
|
7
|
+
type SelectOptions = PromptSelectOptions & {
|
|
8
|
+
type: "select";
|
|
9
|
+
};
|
|
10
|
+
type Options = {
|
|
11
|
+
[key: string]: PromptTextOptions | ConfirmOptions | SelectOptions;
|
|
12
|
+
};
|
|
13
|
+
export declare const promptConfig: (options: Options, values?: any) => Promise<any>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.promptConfig = void 0;
|
|
24
|
+
const normalizeOptions_1 = require("./normalizeOptions");
|
|
25
|
+
const promptConfirm_1 = require("./promptConfirm");
|
|
26
|
+
const promptSelect_1 = require("./promptSelect");
|
|
27
|
+
const promptText_1 = require("./promptText");
|
|
28
|
+
const promptConfig = (options, values = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
for (const key in options) {
|
|
30
|
+
const params = options[key];
|
|
31
|
+
switch (params.type) {
|
|
32
|
+
case "number":
|
|
33
|
+
case "int":
|
|
34
|
+
case "string": {
|
|
35
|
+
values[key] = yield (0, promptText_1.promptText)(Object.assign(Object.assign({}, params), { default: values[key] || params.default }));
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
case "boolean": {
|
|
39
|
+
const { type } = params, rest = __rest(params, ["type"]);
|
|
40
|
+
const selected = yield (0, promptConfirm_1.promptConfirm)(Object.assign(Object.assign({}, rest), { default: typeof values[key] !== "undefined"
|
|
41
|
+
? values[key] === "true"
|
|
42
|
+
: params.default }));
|
|
43
|
+
if (selected) {
|
|
44
|
+
values[key] = true;
|
|
45
|
+
}
|
|
46
|
+
else if (key in values) {
|
|
47
|
+
delete values[key];
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case "select": {
|
|
52
|
+
if (params.multiple) {
|
|
53
|
+
const { type } = params, rest = __rest(params, ["type"]);
|
|
54
|
+
const options = (0, normalizeOptions_1.normalizeOptions)(params.options);
|
|
55
|
+
const selected = yield (0, promptSelect_1.promptSelect)(Object.assign(Object.assign({}, rest), { default: options.map((option) => {
|
|
56
|
+
return option.value;
|
|
57
|
+
}).filter((name) => {
|
|
58
|
+
return values[name];
|
|
59
|
+
}) }));
|
|
60
|
+
for (const option of options) {
|
|
61
|
+
if (selected.includes(option.value)) {
|
|
62
|
+
values[option.value] = true;
|
|
63
|
+
}
|
|
64
|
+
else if (option.value in values) {
|
|
65
|
+
delete values[option.value];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const { type } = params, rest = __rest(params, ["type"]);
|
|
71
|
+
values[key] = yield (0, promptSelect_1.promptSelect)(Object.assign(Object.assign({}, rest), { default: values[key] || params.default }));
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return values;
|
|
78
|
+
});
|
|
79
|
+
exports.promptConfig = promptConfig;
|
package/lib/promptConfirm.d.ts
CHANGED
package/lib/promptSelect.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { RawOptions } from "./normalizeOptions";
|
|
1
2
|
type Options = {
|
|
2
3
|
message?: string;
|
|
3
|
-
options:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
label?: string;
|
|
7
|
-
value: string;
|
|
8
|
-
}[];
|
|
4
|
+
options: RawOptions;
|
|
5
|
+
} & ({
|
|
6
|
+
multiple?: false;
|
|
9
7
|
default?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
8
|
+
} | {
|
|
9
|
+
multiple: true;
|
|
10
|
+
default?: string[];
|
|
11
|
+
});
|
|
12
|
+
type ResultType<T extends Options> = T['multiple'] extends true ? string[] : string;
|
|
13
|
+
export declare const promptSelect: <T extends Options>(props: T) => Promise<ResultType<T>>;
|
|
12
14
|
export { Options as PromptSelectOptions };
|
package/lib/promptSelect.js
CHANGED
|
@@ -14,27 +14,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.promptSelect = void 0;
|
|
16
16
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
17
|
+
const normalizeOptions_1 = require("./normalizeOptions");
|
|
17
18
|
const promptSelect = (props) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
const { message, options: rawOptions,
|
|
19
|
-
const options =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
: option.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
19
|
+
const { message, options: rawOptions, } = props;
|
|
20
|
+
const options = (0, normalizeOptions_1.normalizeOptions)(rawOptions);
|
|
21
|
+
if (props.multiple) {
|
|
22
|
+
const { value } = yield inquirer_1.default.prompt({
|
|
23
|
+
message,
|
|
24
|
+
name: "value",
|
|
25
|
+
type: "checkbox",
|
|
26
|
+
choices: options.map((option) => {
|
|
27
|
+
return {
|
|
28
|
+
name: option.label,
|
|
29
|
+
value: option.value,
|
|
30
|
+
checked: Array.isArray(props.default)
|
|
31
|
+
? props.default.includes(option.value)
|
|
32
|
+
: false
|
|
33
|
+
};
|
|
34
|
+
})
|
|
35
35
|
});
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
36
38
|
const defaultOption = options.find((option) => {
|
|
37
|
-
return option.value ===
|
|
39
|
+
return option.value === props.default;
|
|
38
40
|
});
|
|
39
41
|
const { value } = yield inquirer_1.default.prompt({
|
|
40
42
|
choices: options.map((option) => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.volumeFormat = void 0;
|
|
4
|
+
const volumeFormat = (volume) => {
|
|
5
|
+
const { source, destination, options } = volume;
|
|
6
|
+
return `${source}:${destination}` + (options ? `:${options}` : "");
|
|
7
|
+
};
|
|
8
|
+
exports.volumeFormat = volumeFormat;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const volumeParse = (volume) => {
|
|
4
|
+
const regVolume = /^([^:]+):([^:]+)(?::([^:]+))?$/;
|
|
5
|
+
const [, source, destination, options] = regVolume.exec(volume) || [];
|
|
6
|
+
return {
|
|
7
|
+
source,
|
|
8
|
+
destination,
|
|
9
|
+
options
|
|
10
|
+
};
|
|
11
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wocker/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"author": "Kris Papercut <krispcut@gmail.com>",
|
|
5
5
|
"description": "Utils for @wocker",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"types": "lib/index.d.ts",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"wocker"
|
|
11
|
+
],
|
|
9
12
|
"homepage": "https://github.com/kearisp/wocker-utils#readme",
|
|
10
13
|
"repository": {
|
|
11
14
|
"type": "git",
|
|
@@ -21,9 +24,10 @@
|
|
|
21
24
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
22
25
|
},
|
|
23
26
|
"dependencies": {
|
|
24
|
-
"inquirer": "^7.
|
|
27
|
+
"inquirer": "^7.3.3"
|
|
25
28
|
},
|
|
26
29
|
"devDependencies": {
|
|
30
|
+
"@types/inquirer": "^7.3.3",
|
|
27
31
|
"jest": "^29.7.0",
|
|
28
32
|
"typescript": "^5.2.2"
|
|
29
33
|
}
|