本文整理汇总了TypeScript中fs-promise.readFile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readFile函数的具体用法?TypeScript readFile怎么用?TypeScript readFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readFile函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: checkPage
async function checkPage(beforePath: string, afterPath: string) {
const before = new JSDOM(await fs.readFile(beforePath))
const after = new JSDOM(await fs.readFile(afterPath))
const replacer = createReplacer()
await replacer.replace(before.window.document as Node)
assert.strictEqual(before.window.document.body.textContent, after.window.document.body.textContent)
}
示例2: readFile
public async readFile(path: string, resourceType: ResourceType): Promise<Object> {
let data: Object = { };
try {
let str: string = await fs.readFile(path + ".meta", "utf8");
data = yaml.safeLoad(str);
}
catch (err) {
// There isn't a meta file...
}
data["body"] = await fs.readFile(path);
return data;
}
示例3: async
const resetTestModule = async () => {
await fs.remove(testModulePath);
await fs.mkdirs(testModulePath);
await fs.writeFile(path.resolve(testModulePath, 'package.json'), await fs.readFile(path.resolve(__dirname, '../test/fixture/native-app1/package.json'), 'utf8'));
await spawnPromise('npm', ['install'], {
cwd: testModulePath,
stdio: 'inherit',
});
};
示例4: readFile
public async readFile(path: string, resourceType: ResourceType): Promise<Object> {
let parseFrontmatter = !!resourceType ? resourceType.parseFrontmatter : true;
let encoding = resolveEncoding(resourceType);
let str = await fs.readFile(path, encoding);
let data = this.readString(str, parseFrontmatter);
// Allow frontmatter of resource to override the resource's output encoding.
data["_encoding"] = data["_encoding"] || encoding;
return data;
}
示例5: getFileData
export function getFileData(filePath: string): Q.Promise<any[]> {
return fs.readFile(filePath, 'utf-8').then((fileData) => {
try {
return parseData(fileData, path.extname(filePath));
} catch (e) {
throw new Error(`could not parse '${filePath}': ${e.message}`);
}
}).then((fileJSON) => {
fileJSON.forEach((d: PseudoDatum) => {
d['time'] = new Date(d['time']);
});
return fileJSON;
});
}
示例6: readPackageJson
export async function readPackageJson(dir: string, safe = false) {
let packageData;
try {
packageData = await fs.readFile(path.resolve(dir, 'package.json'), 'utf8');
} catch (err) {
if (safe) {
packageData = '{}';
} else {
throw err;
}
}
return JSON.parse(packageData);
};
示例8: fromSourceFile
/**
* Initializes a new instance of the SourceFilePrinter class.
*
* @param sourceFile The source file to be printed.
* @param settings Settings to run Typespace.
* @returns A promise for a new instance of the SourceFilePrinter class.
*/
public static async fromSourceFile(sourceFile: SourceFile, settings: ITypespaceSettings): Promise<SourceFilePrinter> {
return new SourceFilePrinter(
sourceFile,
(await fs.readFile(sourceFile.fullPath)).toString(),
settings);
}
示例9:
const files = await Promise.all(paths.map((path: String) => fs.readFile(`docs/${path}`, 'utf8')));
示例10: createFileContentItemForPath
async function createFileContentItemForPath(rootDirectory: string, relativePath: string): Promise<ContentItem> {
const fullPath = path.join(rootDirectory, relativePath);
const content = await fsp.readFile(fullPath, UTF8);
return new ContentItemBuilder(false, relativePath)
.withContent(content).build();
}