cliodot 1.2.3 → 1.2.4
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/LICENSE +201 -0
- package/README.md +2 -0
- package/dist/AuthAppClient.d.ts +1 -0
- package/dist/AuthAppClient.d.ts.map +1 -1
- package/dist/AuthAppClient.js +199 -1
- package/dist/CommercialAppClient.d.ts +50 -9
- package/dist/CommercialAppClient.d.ts.map +1 -1
- package/dist/CommercialAppClient.js +576 -1
- package/dist/ConnectorBuilder.js +104 -1
- package/dist/Events.d.ts +2 -0
- package/dist/Events.d.ts.map +1 -1
- package/dist/Events.js +325 -1
- package/dist/Flosync.js +296 -1
- package/dist/FlosyncClient.js +429 -1
- package/dist/FunctionBuilder.js +65 -1
- package/dist/IdentityAppClient.d.ts +1 -0
- package/dist/IdentityAppClient.d.ts.map +1 -1
- package/dist/IdentityAppClient.js +197 -1
- package/dist/MemoryAppClient.d.ts +1 -0
- package/dist/MemoryAppClient.d.ts.map +1 -1
- package/dist/MemoryAppClient.js +149 -1
- package/dist/MemoryClient.js +20 -1
- package/dist/OAuthAppClient.d.ts +1 -0
- package/dist/OAuthAppClient.d.ts.map +1 -1
- package/dist/OAuthAppClient.js +269 -1
- package/dist/ProviderServicesClient.d.ts +24 -0
- package/dist/ProviderServicesClient.d.ts.map +1 -0
- package/dist/ProviderServicesClient.js +158 -0
- package/dist/Surface.d.ts +2 -0
- package/dist/Surface.d.ts.map +1 -1
- package/dist/Surface.js +255 -1
- package/dist/ValidatorBuilder.js +24 -1
- package/dist/Webhooks.js +61 -1
- package/dist/WorkflowBuilder.js +279 -1
- package/dist/__tests__/CommercialAppClient.test.d.ts +2 -0
- package/dist/__tests__/CommercialAppClient.test.d.ts.map +1 -0
- package/dist/__tests__/CommercialAppClient.test.js +217 -0
- package/dist/__tests__/Events.test.js +191 -1
- package/dist/__tests__/IdentityAppClient.test.js +232 -1
- package/dist/__tests__/OAuthAppClient.test.js +300 -1
- package/dist/__tests__/ProviderServicesClient.test.d.ts +2 -0
- package/dist/__tests__/ProviderServicesClient.test.d.ts.map +1 -0
- package/dist/__tests__/ProviderServicesClient.test.js +131 -0
- package/dist/__tests__/Surface.test.js +150 -1
- package/dist/__tests__/errors.test.js +54 -1
- package/dist/__tests__/function.test.js +58 -1
- package/dist/__tests__/helpers.d.ts +5 -0
- package/dist/__tests__/helpers.d.ts.map +1 -0
- package/dist/__tests__/helpers.js +10 -0
- package/dist/__tests__/localhost-lookup.test.d.ts +2 -0
- package/dist/__tests__/localhost-lookup.test.d.ts.map +1 -0
- package/dist/__tests__/localhost-lookup.test.js +26 -0
- package/dist/__tests__/parse-api-error.test.js +26 -1
- package/dist/__tests__/runner.test.js +156 -1
- package/dist/connectors/builtin.js +354 -1
- package/dist/connectors/registry.js +300 -1
- package/dist/decorators/build.js +105 -1
- package/dist/decorators/connector.js +56 -1
- package/dist/decorators/index.js +34 -1
- package/dist/decorators/metadata.js +338 -1
- package/dist/decorators/steps.js +220 -1
- package/dist/decorators/workflow.js +52 -1
- package/dist/errors.js +76 -1
- package/dist/http/__tests__/cliodot-request.environment.test.d.ts +2 -0
- package/dist/http/__tests__/cliodot-request.environment.test.d.ts.map +1 -0
- package/dist/http/__tests__/cliodot-request.environment.test.js +37 -0
- package/dist/http/__tests__/cliodot-result.test.d.ts +2 -0
- package/dist/http/__tests__/cliodot-result.test.d.ts.map +1 -0
- package/dist/http/__tests__/cliodot-result.test.js +57 -0
- package/dist/http/__tests__/events-instance-id.test.d.ts +2 -0
- package/dist/http/__tests__/events-instance-id.test.d.ts.map +1 -0
- package/dist/http/__tests__/events-instance-id.test.js +45 -0
- package/dist/http/cliodot-request.d.ts +35 -0
- package/dist/http/cliodot-request.d.ts.map +1 -0
- package/dist/http/cliodot-request.js +105 -0
- package/dist/http/cliodot-result.d.ts +40 -0
- package/dist/http/cliodot-result.d.ts.map +1 -0
- package/dist/http/cliodot-result.js +139 -0
- package/dist/http/create-client.d.ts +3 -0
- package/dist/http/create-client.d.ts.map +1 -0
- package/dist/http/create-client.js +14 -0
- package/dist/http/events-instance-id.d.ts +11 -0
- package/dist/http/events-instance-id.d.ts.map +1 -0
- package/dist/http/events-instance-id.js +86 -0
- package/dist/http/localhost-lookup.d.ts +12 -0
- package/dist/http/localhost-lookup.d.ts.map +1 -0
- package/dist/http/localhost-lookup.js +67 -0
- package/dist/http/parse-api-error.js +56 -1
- package/dist/http/sanitize-execution-headers.js +79 -1
- package/dist/identity-offline-verify.js +174 -1
- package/dist/identity-token-cache.js +51 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -1
- package/dist/runner/ProcessorEngine.js +1311 -1
- package/dist/runner/connector.executor.js +1786 -1
- package/dist/runner/utilities/math.executor.js +153 -1
- package/dist/runner/utilities/random.executor.js +151 -1
- package/dist/runner/utilities/string.executor.js +825 -1
- package/dist/template.js +127 -1
- package/dist/transformers/StepsToNodesTransformer.js +214 -1
- package/dist/transformers/WorkflowTransformer.js +189 -1
- package/dist/types/auth-app.api.d.ts +2 -0
- package/dist/types/auth-app.api.d.ts.map +1 -1
- package/dist/types/auth-app.api.js +2 -1
- package/dist/types/builtin.js +2 -1
- package/dist/types/client.api.js +2 -1
- package/dist/types/commercial-app.api.d.ts +407 -11
- package/dist/types/commercial-app.api.d.ts.map +1 -1
- package/dist/types/commercial-app.api.js +2 -1
- package/dist/types/connector.js +2 -1
- package/dist/types/context.js +2 -1
- package/dist/types/event-app.api.d.ts +8 -0
- package/dist/types/event-app.api.d.ts.map +1 -1
- package/dist/types/event-app.api.js +2 -1
- package/dist/types/function.js +2 -1
- package/dist/types/identity-app.api.d.ts +2 -0
- package/dist/types/identity-app.api.d.ts.map +1 -1
- package/dist/types/identity-app.api.js +2 -1
- package/dist/types/index.js +23 -1
- package/dist/types/memory-app.api.d.ts +2 -0
- package/dist/types/memory-app.api.d.ts.map +1 -1
- package/dist/types/memory-app.api.js +2 -1
- package/dist/types/oauth-app.api.d.ts +2 -0
- package/dist/types/oauth-app.api.d.ts.map +1 -1
- package/dist/types/oauth-app.api.js +105 -1
- package/dist/types/provider-services.api.d.ts +98 -0
- package/dist/types/provider-services.api.d.ts.map +1 -0
- package/dist/types/provider-services.api.js +2 -0
- package/dist/types/validator.js +2 -1
- package/dist/types/webhook-app.api.js +2 -1
- package/dist/types/workflow.js +33 -1
- package/dist/validators/validators.js +478 -1
- package/dist/variable.js +37 -1
- package/package.json +3 -2
|
@@ -1 +1,153 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeMath = executeMath;
|
|
4
|
+
function executeMath(opts, actionMethod) {
|
|
5
|
+
const o = opts;
|
|
6
|
+
switch (actionMethod) {
|
|
7
|
+
case "add": {
|
|
8
|
+
const numbers = o.numbers ?? (o.a !== undefined && o.b !== undefined ? [o.a, o.b] : [o.a ?? o.value ?? 0, o.b ?? 0]);
|
|
9
|
+
if (!Array.isArray(numbers))
|
|
10
|
+
return { value: Number(o.a ?? o.value ?? 0) + Number(o.b ?? 0) };
|
|
11
|
+
return { value: numbers.reduce((sum, n) => sum + Number(n), 0) };
|
|
12
|
+
}
|
|
13
|
+
case "subtract": {
|
|
14
|
+
const a = o.a ?? o.numbers?.[0] ?? o.value ?? 0;
|
|
15
|
+
const b = o.b ?? o.numbers?.[1] ?? 0;
|
|
16
|
+
return { value: Number(a) - Number(b) };
|
|
17
|
+
}
|
|
18
|
+
case "multiply": {
|
|
19
|
+
const numbers = o.numbers ?? [o.a ?? 1, o.b ?? 1];
|
|
20
|
+
if (!Array.isArray(numbers))
|
|
21
|
+
return { value: Number(o.a ?? 1) * Number(o.b ?? 1) };
|
|
22
|
+
return { value: numbers.reduce((prod, n) => prod * Number(n), 1) };
|
|
23
|
+
}
|
|
24
|
+
case "divide": {
|
|
25
|
+
const dividend = o.dividend ?? o.a ?? o.value ?? 0;
|
|
26
|
+
const divisor = o.divisor ?? o.b ?? 1;
|
|
27
|
+
if (divisor === 0)
|
|
28
|
+
throw new Error("Division by zero is not allowed");
|
|
29
|
+
let result = Number(dividend) / Number(divisor);
|
|
30
|
+
if (o.precision !== undefined)
|
|
31
|
+
result = parseFloat(result.toFixed(o.precision));
|
|
32
|
+
return { value: result };
|
|
33
|
+
}
|
|
34
|
+
case "modulo": {
|
|
35
|
+
const { dividend, divisor } = o;
|
|
36
|
+
if (dividend === undefined || divisor === undefined)
|
|
37
|
+
throw new Error("Dividend and divisor are required");
|
|
38
|
+
return { value: Number(dividend) % Number(divisor) };
|
|
39
|
+
}
|
|
40
|
+
case "power": {
|
|
41
|
+
const { base, exponent } = o;
|
|
42
|
+
if (base === undefined || exponent === undefined)
|
|
43
|
+
throw new Error("Base and exponent are required");
|
|
44
|
+
return { value: Math.pow(Number(base), Number(exponent)) };
|
|
45
|
+
}
|
|
46
|
+
case "round": {
|
|
47
|
+
const { number, decimals = 0 } = o;
|
|
48
|
+
if (number === undefined)
|
|
49
|
+
throw new Error("Number is required");
|
|
50
|
+
return { value: parseFloat(Number(number).toFixed(decimals)) };
|
|
51
|
+
}
|
|
52
|
+
case "floor": {
|
|
53
|
+
const { number } = o;
|
|
54
|
+
if (number === undefined)
|
|
55
|
+
throw new Error("Number is required");
|
|
56
|
+
return { value: Math.floor(Number(number)) };
|
|
57
|
+
}
|
|
58
|
+
case "ceil": {
|
|
59
|
+
const { number } = o;
|
|
60
|
+
if (number === undefined)
|
|
61
|
+
throw new Error("Number is required");
|
|
62
|
+
return { value: Math.ceil(Number(number)) };
|
|
63
|
+
}
|
|
64
|
+
case "abs": {
|
|
65
|
+
const { number } = o;
|
|
66
|
+
if (number === undefined)
|
|
67
|
+
throw new Error("Number is required");
|
|
68
|
+
return { value: Math.abs(Number(number)) };
|
|
69
|
+
}
|
|
70
|
+
case "min": {
|
|
71
|
+
const { numbers } = o;
|
|
72
|
+
if (!Array.isArray(numbers) || numbers.length === 0)
|
|
73
|
+
throw new Error("Numbers array is required and must not be empty");
|
|
74
|
+
return { value: Math.min(...numbers.map((n) => Number(n))) };
|
|
75
|
+
}
|
|
76
|
+
case "max": {
|
|
77
|
+
const { numbers } = o;
|
|
78
|
+
if (!Array.isArray(numbers) || numbers.length === 0)
|
|
79
|
+
throw new Error("Numbers array is required and must not be empty");
|
|
80
|
+
return { value: Math.max(...numbers.map((n) => Number(n))) };
|
|
81
|
+
}
|
|
82
|
+
case "average": {
|
|
83
|
+
const { numbers, precision } = o;
|
|
84
|
+
if (!Array.isArray(numbers) || numbers.length === 0)
|
|
85
|
+
throw new Error("Numbers array is required and must not be empty");
|
|
86
|
+
const sum = numbers.reduce((s, n) => s + Number(n), 0);
|
|
87
|
+
let avg = sum / numbers.length;
|
|
88
|
+
if (precision !== undefined)
|
|
89
|
+
avg = parseFloat(avg.toFixed(precision));
|
|
90
|
+
return { value: avg };
|
|
91
|
+
}
|
|
92
|
+
case "sum": {
|
|
93
|
+
const { numbers } = o;
|
|
94
|
+
if (!Array.isArray(numbers))
|
|
95
|
+
throw new Error("Numbers array is required");
|
|
96
|
+
return { value: numbers.reduce((sum, n) => sum + Number(n), 0) };
|
|
97
|
+
}
|
|
98
|
+
case "clamp": {
|
|
99
|
+
const { number, min, max } = o;
|
|
100
|
+
if (number === undefined || min === undefined || max === undefined)
|
|
101
|
+
throw new Error("Number, min, and max are required");
|
|
102
|
+
const num = Number(number);
|
|
103
|
+
return { value: Math.min(Math.max(num, Number(min)), Number(max)) };
|
|
104
|
+
}
|
|
105
|
+
case "random_between": {
|
|
106
|
+
const { min, max, integer = false, precision = 2 } = o;
|
|
107
|
+
if (min === undefined || max === undefined)
|
|
108
|
+
throw new Error("Min and max are required");
|
|
109
|
+
const value = Math.random() * (Number(max) - Number(min)) + Number(min);
|
|
110
|
+
return { value: integer ? Math.floor(value) : parseFloat(value.toFixed(precision)) };
|
|
111
|
+
}
|
|
112
|
+
case "percentage": {
|
|
113
|
+
const { value, total, precision = 2 } = o;
|
|
114
|
+
if (value === undefined || total === undefined)
|
|
115
|
+
throw new Error("Value and total are required");
|
|
116
|
+
if (total === 0)
|
|
117
|
+
throw new Error("Total cannot be zero");
|
|
118
|
+
const percent = (Number(value) / Number(total)) * 100;
|
|
119
|
+
return { value: parseFloat(percent.toFixed(precision)) };
|
|
120
|
+
}
|
|
121
|
+
case "percentage_of": {
|
|
122
|
+
const { percentage, of, precision = 2 } = o;
|
|
123
|
+
if (percentage === undefined || of === undefined)
|
|
124
|
+
throw new Error("Percentage and of are required");
|
|
125
|
+
const result = (Number(percentage) / 100) * Number(of);
|
|
126
|
+
return { value: parseFloat(result.toFixed(precision)) };
|
|
127
|
+
}
|
|
128
|
+
case "sqrt": {
|
|
129
|
+
const { number, precision } = o;
|
|
130
|
+
if (number === undefined)
|
|
131
|
+
throw new Error("Number is required");
|
|
132
|
+
if (number < 0)
|
|
133
|
+
throw new Error("Cannot calculate square root of negative number");
|
|
134
|
+
let result = Math.sqrt(Number(number));
|
|
135
|
+
if (precision !== undefined)
|
|
136
|
+
result = parseFloat(result.toFixed(precision));
|
|
137
|
+
return { value: result };
|
|
138
|
+
}
|
|
139
|
+
case "log": {
|
|
140
|
+
const { number, base, precision } = o;
|
|
141
|
+
if (number === undefined)
|
|
142
|
+
throw new Error("Number is required");
|
|
143
|
+
if (number <= 0)
|
|
144
|
+
throw new Error("Number must be greater than zero");
|
|
145
|
+
let result = base ? Math.log(Number(number)) / Math.log(Number(base)) : Math.log(Number(number));
|
|
146
|
+
if (precision !== undefined)
|
|
147
|
+
result = parseFloat(result.toFixed(precision));
|
|
148
|
+
return { value: result };
|
|
149
|
+
}
|
|
150
|
+
default:
|
|
151
|
+
return { value: Number(o.value ?? o.a ?? 0) };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -1 +1,151 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeRandom = executeRandom;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
function randomInt(min, max) {
|
|
6
|
+
return Math.floor(Math.random() * (max - min)) + min;
|
|
7
|
+
}
|
|
8
|
+
function executeRandom(opts, actionMethod) {
|
|
9
|
+
const o = opts;
|
|
10
|
+
switch (actionMethod) {
|
|
11
|
+
case "random_int": {
|
|
12
|
+
const min = o.min ?? 0;
|
|
13
|
+
const max = o.max ?? 100;
|
|
14
|
+
return { value: randomInt(+min, +max + 1) };
|
|
15
|
+
}
|
|
16
|
+
case "random_float": {
|
|
17
|
+
const min = o.min ?? 0;
|
|
18
|
+
const max = o.max ?? 1;
|
|
19
|
+
const decimals = o.decimals ?? 2;
|
|
20
|
+
const value = Math.random() * (max - min) + min;
|
|
21
|
+
return { value: parseFloat(value.toFixed(decimals)) };
|
|
22
|
+
}
|
|
23
|
+
case "random_string": {
|
|
24
|
+
const { length = 10, charset = "alphanumeric", custom_charset, case: caseOption = "mixed" } = o;
|
|
25
|
+
let chars = "";
|
|
26
|
+
if (charset === "custom" && custom_charset)
|
|
27
|
+
chars = custom_charset;
|
|
28
|
+
else if (charset === "alphanumeric")
|
|
29
|
+
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
30
|
+
else if (charset === "alphabetic")
|
|
31
|
+
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
32
|
+
else if (charset === "numeric")
|
|
33
|
+
chars = "0123456789";
|
|
34
|
+
else if (charset === "hex")
|
|
35
|
+
chars = "0123456789abcdef";
|
|
36
|
+
if (caseOption === "lower")
|
|
37
|
+
chars = chars.toLowerCase();
|
|
38
|
+
else if (caseOption === "upper")
|
|
39
|
+
chars = chars.toUpperCase();
|
|
40
|
+
let result = "";
|
|
41
|
+
for (let i = 0; i < length; i++)
|
|
42
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
43
|
+
return { value: result };
|
|
44
|
+
}
|
|
45
|
+
case "random_uuid":
|
|
46
|
+
case "uuid": {
|
|
47
|
+
const format = o.format ?? "standard";
|
|
48
|
+
const bytes = (0, crypto_1.randomBytes)(16);
|
|
49
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
50
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
51
|
+
let uuid = bytes.toString("hex").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5");
|
|
52
|
+
if (format === "compact")
|
|
53
|
+
uuid = uuid.replace(/-/g, "");
|
|
54
|
+
return { value: uuid };
|
|
55
|
+
}
|
|
56
|
+
case "random_boolean": {
|
|
57
|
+
const probability = o.probability ?? 0.5;
|
|
58
|
+
return { value: Math.random() < probability };
|
|
59
|
+
}
|
|
60
|
+
case "random_choice": {
|
|
61
|
+
const { choices, count = 1, unique = true } = o;
|
|
62
|
+
if (!Array.isArray(choices) || choices.length === 0)
|
|
63
|
+
throw new Error("Choices array is required and must not be empty");
|
|
64
|
+
const selected = [];
|
|
65
|
+
const used = new Set();
|
|
66
|
+
const maxCount = unique ? Math.min(count, choices.length) : count;
|
|
67
|
+
for (let i = 0; i < maxCount; i++) {
|
|
68
|
+
let index;
|
|
69
|
+
if (unique) {
|
|
70
|
+
do
|
|
71
|
+
index = Math.floor(Math.random() * choices.length);
|
|
72
|
+
while (used.has(index));
|
|
73
|
+
used.add(index);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
index = Math.floor(Math.random() * choices.length);
|
|
77
|
+
}
|
|
78
|
+
selected.push(choices[index]);
|
|
79
|
+
}
|
|
80
|
+
return { value: count === 1 ? selected[0] : selected };
|
|
81
|
+
}
|
|
82
|
+
case "random_password": {
|
|
83
|
+
const { length = 16, include_uppercase = true, include_lowercase = true, include_numbers = true, include_symbols = true, exclude_similar = false, exclude_ambiguous = false, } = o;
|
|
84
|
+
let chars = "";
|
|
85
|
+
if (include_lowercase)
|
|
86
|
+
chars += exclude_similar ? "abcdefghjkmnpqrstuvwxyz" : "abcdefghijklmnopqrstuvwxyz";
|
|
87
|
+
if (include_uppercase)
|
|
88
|
+
chars += exclude_similar ? "ABCDEFGHJKMNPQRSTUVWXYZ" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
89
|
+
if (include_numbers)
|
|
90
|
+
chars += exclude_similar ? "23456789" : "0123456789";
|
|
91
|
+
if (include_symbols)
|
|
92
|
+
chars += exclude_ambiguous ? "!@#$%^&*" : "!@#$%^&*()_+-=[]{}|;:,.<>?";
|
|
93
|
+
if (chars.length === 0)
|
|
94
|
+
throw new Error("At least one character set must be included");
|
|
95
|
+
let password = "";
|
|
96
|
+
for (let i = 0; i < length; i++)
|
|
97
|
+
password += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
98
|
+
return { value: password };
|
|
99
|
+
}
|
|
100
|
+
case "random_hex": {
|
|
101
|
+
const { length = 16, prefix = "", uppercase = false } = o;
|
|
102
|
+
const hex = (0, crypto_1.randomBytes)(Math.ceil(length / 2)).toString("hex").slice(0, length);
|
|
103
|
+
return { value: prefix + (uppercase ? hex.toUpperCase() : hex) };
|
|
104
|
+
}
|
|
105
|
+
case "random_alphanumeric": {
|
|
106
|
+
const { length = 10, case: caseOption = "mixed" } = o;
|
|
107
|
+
return executeRandom({ length, charset: "alphanumeric", case: caseOption }, "random_string");
|
|
108
|
+
}
|
|
109
|
+
case "random_date": {
|
|
110
|
+
const { start_date, end_date, format } = o;
|
|
111
|
+
const start = start_date ? new Date(start_date).getTime() : 0;
|
|
112
|
+
const end = end_date ? new Date(end_date).getTime() : Date.now();
|
|
113
|
+
const randomTime = Math.random() * (end - start) + start;
|
|
114
|
+
const date = new Date(randomTime);
|
|
115
|
+
const result = { value: date.toISOString() };
|
|
116
|
+
if (format)
|
|
117
|
+
result.formatted = date.toISOString();
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
case "random_color": {
|
|
121
|
+
const { format = "hex", alpha = 1 } = o;
|
|
122
|
+
const r = Math.floor(Math.random() * 256);
|
|
123
|
+
const g = Math.floor(Math.random() * 256);
|
|
124
|
+
const b = Math.floor(Math.random() * 256);
|
|
125
|
+
if (format === "hex")
|
|
126
|
+
return { value: `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}` };
|
|
127
|
+
if (format === "rgb")
|
|
128
|
+
return { value: `rgb(${r}, ${g}, ${b})` };
|
|
129
|
+
if (format === "rgba")
|
|
130
|
+
return { value: `rgba(${r}, ${g}, ${b}, ${alpha})` };
|
|
131
|
+
return { value: `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}` };
|
|
132
|
+
}
|
|
133
|
+
case "shuffle_array": {
|
|
134
|
+
const { array, in_place = false } = o;
|
|
135
|
+
if (!Array.isArray(array))
|
|
136
|
+
throw new Error("Array is required");
|
|
137
|
+
const shuffled = in_place ? array : [...array];
|
|
138
|
+
for (let i = shuffled.length - 1; i > 0; i--) {
|
|
139
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
140
|
+
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
141
|
+
}
|
|
142
|
+
return { value: shuffled };
|
|
143
|
+
}
|
|
144
|
+
default: {
|
|
145
|
+
const bytes = (0, crypto_1.randomBytes)(16);
|
|
146
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
147
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
148
|
+
return { value: bytes.toString("hex").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5") };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|