本文整理汇总了TypeScript中shell-quote.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getConfig
export function getConfig(fileOrArgv?: string | string[], argv?: string[]) {
let args: { [key: string]: any } = {};
let file = typeof fileOrArgv === 'string' ? fileOrArgv : undefined;
argv = Array.isArray(fileOrArgv) ? fileOrArgv : argv;
const userArgs = (argv || process.argv).slice(2);
if (process.env['INTERN_ARGS']) {
mixin(args, parseArgs(parse(process.env['INTERN_ARGS'] || '')));
}
if (userArgs.length > 0) {
mixin(args, parseArgs(userArgs));
}
if (file) {
args.config = file;
}
let load: Task<{ [key: string]: any }>;
if (args.config) {
// If a config parameter was provided, load it and mix in any other
// command line args.
const { configFile, childConfig } = splitConfigPath(args.config, sep);
file = resolve(configFile || 'intern.json');
load = loadConfig(file, loadText, args, childConfig);
} else {
// If no config parameter was provided, try 'intern.json', or just
// resolve to the original args
file = resolve('intern.json');
load = loadConfig(file, loadText, args, undefined).catch(
(error: NodeJS.ErrnoException) => {
if (error.code === 'ENOENT') {
file = undefined;
return args;
}
throw error;
}
);
}
return load
.then(config => {
// If a basePath wasn't set in the config or via a query arg, and we
// have a config file path, use that.
if (file) {
config.basePath = getBasePath(
file,
config.basePath,
isAbsolute,
sep
);
}
return config;
})
.then(config => ({ config, file }));
}
示例2: parse
export function parse(a: string): string {
if (a.startsWith('"')) {
a = a.replace(/\\n/g, '\n')
} else if (a.startsWith("'")) {
a = a.replace(/\\\\/g, '\\')
}
let parsed = shell.parse(a)
if (parsed.length > 1) throw new Error(`Invalid token: ${a}`)
return parsed[0]
// return parsed[0].replace(/\\\\n/g, '\n')
}
示例3: getConfig
export function getConfig(configFile?: string) {
let args: { [key: string]: any } = {};
if (process.env['INTERN_ARGS']) {
mixin(args, parseArgs(parse(process.env['INTERN_ARGS'])));
}
if (process.argv.length > 2) {
mixin(args, parseArgs(process.argv.slice(2)));
}
if (configFile) {
args.config = configFile;
}
if (args.config) {
// If a config parameter was provided, load it and mix in any other
// command line args.
const { configFile, childConfig } = splitConfigPath(args.config, sep);
return loadConfig(
configFile || 'intern.json',
loadText,
args,
childConfig
);
} else {
// If no config parameter was provided, try 'intern.json', or just
// resolve to the original args
return loadConfig(
'intern.json',
loadText,
args
).catch((error: NodeJS.ErrnoException) => {
if (error.code === 'ENOENT') {
return args;
}
throw error;
});
}
}
示例4: quote
import { parse, quote } from 'shell-quote';
quote([ 'a', 'b c d', '$f', '"g"' ]);
parse('a "b c" \\$def \'it\\\'s great\'');
parse('beep --boop="$PWD"', { PWD: '/home/robot' });
parse('beep --boop="$PWD"', { PWD: '/home/robot' }, { escape: '^' });
parse('beep --boop="$PWD"', (key: string) => '/home/robot');
parse('beep --boop="$PWD"', (key: string) => ({ op: '||' }));