-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathinput-key.ts
More file actions
28 lines (23 loc) · 860 Bytes
/
input-key.ts
File metadata and controls
28 lines (23 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import escapeStringRegexp from 'escape-string-regexp';
import { ACTOR_ENV_VARS, APIFY_ENV_VARS } from '@apify/consts';
export const CRAWLEE_INPUT_KEY_ENV = 'CRAWLEE_INPUT_KEY';
export const TEMP_INPUT_KEY_PREFIX = '__CLI_';
/**
* Resolves the input key from environment variables in priority order:
* ACTOR_INPUT_KEY > APIFY_INPUT_KEY > CRAWLEE_INPUT_KEY > "INPUT"
*/
export function resolveInputKey(): string {
return (
process.env[ACTOR_ENV_VARS.INPUT_KEY] ||
process.env[APIFY_ENV_VARS.INPUT_KEY] ||
process.env[CRAWLEE_INPUT_KEY_ENV] ||
'INPUT'
);
}
/**
* Creates a RegExp that matches the given key with an optional file extension.
* e.g. inputFileRegExp('INPUT') matches 'INPUT', 'INPUT.json', 'INPUT.bin'
*/
export function inputFileRegExp(key: string): RegExp {
return new RegExp(`(^${escapeStringRegexp(key)}(?:\\.[^.]+)?$)`);
}