本文整理匯總了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: '||' }));