本文整理匯總了TypeScript中glob.hasMagic函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript hasMagic函數的具體用法?TypeScript hasMagic怎麽用?TypeScript hasMagic使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了hasMagic函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: expandFiles
export function expandFiles(patterns?: string[] | string) {
if (!patterns) {
patterns = [];
} else if (!Array.isArray(patterns)) {
patterns = [patterns];
}
const excludes: string[] = [];
const includes: string[] = [];
const paths: string[] = [];
for (let pattern of patterns) {
if (pattern[0] === '!') {
excludes.push(pattern.slice(1));
} else {
if (hasMagic(pattern)) {
includes.push(pattern);
} else {
paths.push(pattern);
}
}
}
const allPaths = includes
.map(pattern => glob(pattern, { ignore: excludes }))
.reduce((allFiles, files) => allFiles.concat(files), paths);
const uniquePaths: { [name: string]: boolean } = {};
allPaths.forEach(path => (uniquePaths[path] = true));
return Object.keys(uniquePaths);
}
示例2: expandFiles
export function expandFiles(patterns?: string[] | string) {
if (!patterns) {
patterns = [];
} else if (!Array.isArray(patterns)) {
patterns = [patterns];
}
const excludes: string[] = [];
const includes: string[] = [];
const paths: string[] = [];
for (let pattern of patterns) {
if (pattern[0] === '!') {
excludes.push(pattern.slice(1));
} else {
if (hasMagic(pattern)) {
includes.push(pattern);
} else {
paths.push(pattern);
}
}
}
return includes
.map(pattern => glob(pattern, { ignore: excludes }))
.reduce((allFiles, files) => allFiles.concat(files), paths);
}
示例3: resolveFilePatterns
/**
* Resolve a list of file patterns into a list of individual file paths.
*
* @param {Array.<string> | string} patterns
* @param {=boolean} opt_omitWarnings Whether to omit did not match warnings
* @param {=string} opt_relativeTo Path to resolve patterns against
*
* @return {Array} The resolved file paths.
*/
public static resolveFilePatterns(
patterns: string[]|string, opt_omitWarnings?: boolean, opt_relativeTo?: string): string[] {
let resolvedFiles: string[] = [];
let cwd = opt_relativeTo || process.cwd();
patterns = (typeof patterns === 'string') ? [patterns] : patterns;
if (patterns) {
for (let fileName of patterns) {
let matches = glob.hasMagic(fileName) ? glob.sync(fileName, {cwd}) : [fileName];
if (!matches.length && !opt_omitWarnings) {
logger.warn('pattern ' + fileName + ' did not match any files.');
}
for (let match of matches) {
let resolvedPath = path.resolve(cwd, match);
resolvedFiles.push(resolvedPath);
}
}
}
return resolvedFiles;
}
示例4: isGlob
public isGlob(potentialGlob: string): boolean {
return Glob.hasMagic(potentialGlob);
}