本文整理汇总了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);
}