本文整理汇总了TypeScript中slash.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
export default function(
externals: NormalizedConfig['externals'],
id: string,
parentId?: string
) {
id = slash(id)
if (!Array.isArray(externals)) {
externals = [externals] as NormalizedConfig['externals']
}
for (const external of externals) {
if (
typeof external === 'string' &&
(id === external || id.includes(`/node_modules/${external}/`))
) {
return true
}
if (external instanceof RegExp) {
if (external.test(id)) {
return true
}
}
if (typeof external === 'function') {
if (external(id, parentId)) {
return true
}
}
}
return false
}
示例2: function
/**
* @param {string} rootDir - e.g. /home/typicode/project/
* @param {string} huskyDir - e.g. /home/typicode/project/node_modules/husky/
* @param {string} requireRunNodePath - path to run-node resolved by require e.g. /home/typicode/project/node_modules/run-node/run-node
* @param {string} platform - platform husky installer is running on (used to produce win32 specific script)
* @returns {string} script
*/
export default function(
rootDir: string,
huskyDir: string,
requireRunNodePath: string,
// Additional param used for testing only
platform: string = os.platform()
): string {
const runNodePath = slash(path.relative(rootDir, requireRunNodePath))
// On Windows do not rely on run-node
const node = platform === 'win32' ? 'node' : runNodePath
// Env variable
const pkgHomepage = process && process.env && process.env.npm_package_homepage
const pkgDirectory = process && process.env && process.env.PWD
// Husky package.json
const { homepage, version } = JSON.parse(
fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf-8')
)
// Path to run.js
const runScriptPath = slash(
path.join(path.relative(rootDir, huskyDir), 'run')
)
// Created at
const createdAt = new Date().toLocaleString()
// Render script
return render({
createdAt,
homepage,
node,
pkgDirectory,
pkgHomepage,
platform,
runScriptPath,
version
})
}
示例3: slash
export const formatTestPath = (
config: Config.GlobalConfig | Config.ProjectConfig,
testPath: Config.Path,
) => {
const {dirname, basename} = relativePath(config, testPath);
return slash(chalk.dim(dirname + path.sep) + chalk.bold(basename));
};
示例4: slash
return buffer.reduce((output, {type, message, origin}) => {
origin = slash(path.relative(root, origin));
message = message
.split(/\n/)
.map(line => CONSOLE_INDENT + line)
.join('\n');
let typeMessage = 'console.' + type;
if (type === 'warn') {
message = chalk.yellow(message);
typeMessage = chalk.yellow(typeMessage);
} else if (type === 'error') {
message = chalk.red(message);
typeMessage = chalk.red(typeMessage);
}
return (
output +
TITLE_INDENT +
chalk.dim(typeMessage) +
' ' +
chalk.dim(origin) +
'\n' +
message +
'\n'
);
}, '');
示例5: slash
export const findSiblingsWithFileExtension = (
moduleFileExtensions: Config.ProjectConfig['moduleFileExtensions'],
from: Config.Path,
moduleName: string,
): string => {
if (!path.isAbsolute(moduleName) && path.extname(moduleName) === '') {
const dirname = path.dirname(from);
const pathToModule = path.resolve(dirname, moduleName);
try {
const slashedDirname = slash(dirname);
const matches = glob
.sync(`${pathToModule}.*`)
.map(match => slash(match))
.map(match => {
const relativePath = path.posix.relative(slashedDirname, match);
return path.posix.dirname(match) === slashedDirname
? `./${relativePath}`
: relativePath;
})
.map(match => `\t'${match}'`)
.join('\n');
if (matches) {
const foundMessage = `\n\nHowever, Jest was able to find:\n${matches}`;
const mappedModuleFileExtensions = moduleFileExtensions
.map(ext => `'${ext}'`)
.join(', ');
return (
foundMessage +
"\n\nYou might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently " +
`[${mappedModuleFileExtensions}].\n\nSee https://jestjs.io/docs/en/configuration#modulefileextensions-array-string`
);
}
} catch (ignored) {}
}
return '';
};
示例6: loadBabelConfig
function loadBabelConfig(
cwd: Config.Path,
filename: Config.Path,
): PartialConfig {
// `cwd` first to allow incoming options to override it
const babelConfig = loadPartialConfig({cwd, ...options, filename});
if (!babelConfig) {
throw new Error(
`babel-jest: Babel ignores ${chalk.bold(
slash(path.relative(cwd, filename)),
)} - make sure to include the file in Jest's ${chalk.bold(
'transformIgnorePatterns',
)} as well.`,
);
}
return babelConfig;
}
示例7: getStackTraceLines
export const formatStackTrace = (
stack: string,
config: StackTraceConfig,
options: StackTraceOptions,
testPath?: Path,
) => {
const lines = getStackTraceLines(stack, options);
const topFrame = getTopFrame(lines);
let renderedCallsite = '';
const relativeTestPath = testPath
? slash(path.relative(config.rootDir, testPath))
: null;
if (topFrame) {
const {column, file: filename, line} = topFrame;
if (line && filename && path.isAbsolute(filename)) {
let fileContent;
try {
// TODO: check & read HasteFS instead of reading the filesystem:
// see: https://github.com/facebook/jest/pull/5405#discussion_r164281696
fileContent = fs.readFileSync(filename, 'utf8');
renderedCallsite = getRenderedCallsite(fileContent, line, column);
} catch (e) {
// the file does not exist or is inaccessible, we ignore
}
}
}
const stacktrace = lines
.filter(Boolean)
.map(
line =>
STACK_INDENT + formatPaths(config, relativeTestPath, trimPaths(line)),
)
.join('\n');
return `${renderedCallsite}\n${stacktrace}`;
};
示例8: STACK_TRACE_COLOR
const formatPaths = (
config: StackTraceConfig,
relativeTestPath: Path | null,
line: string,
) => {
// Extract the file path from the trace line.
const match = line.match(/(^\s*at .*?\(?)([^()]+)(:[0-9]+:[0-9]+\)?.*$)/);
if (!match) {
return line;
}
let filePath = slash(path.relative(config.rootDir, match[2]));
// highlight paths from the current test file
if (
(config.testMatch &&
config.testMatch.length &&
micromatch.some(filePath, config.testMatch)) ||
filePath === relativeTestPath
) {
filePath = chalk.reset.cyan(filePath);
}
return STACK_TRACE_COLOR(match[1]) + filePath + STACK_TRACE_COLOR(match[3]);
};
示例9: _getFileCachePath
private _getFileCachePath(
filename: Config.Path,
content: string,
instrument: boolean,
): Config.Path {
const baseCacheDir = HasteMap.getCacheFilePath(
this._config.cacheDirectory,
'jest-transform-cache-' + this._config.name,
VERSION,
);
const cacheKey = this._getCacheKey(content, filename, instrument);
// Create sub folders based on the cacheKey to avoid creating one
// directory with many files.
const cacheDir = path.join(baseCacheDir, cacheKey[0] + cacheKey[1]);
const cachePath = slash(
path.join(
cacheDir,
path.basename(filename, path.extname(filename)) + '_' + cacheKey,
),
);
createDirectory(cacheDir);
return cachePath;
}