本文整理汇总了TypeScript中fs.readFileAsync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readFileAsync函数的具体用法?TypeScript readFileAsync怎么用?TypeScript readFileAsync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readFileAsync函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: readDownSQL
export function readDownSQL(migration: Migration): Promise<string> {
if (migration.split) {
return fs.readFileAsync(migration.downPath, {encoding: 'utf8'})
.then(R.trim);
}
return fs.readFileAsync(migration.path, {encoding: 'utf8'})
.then(R.split(MIGRATION_SQL_SPLIT_REGEXP))
.tap(R.partial(assertSQLSections, migration))
.then(R.nth(1))
.then(R.trim);
}
示例2: uploadStockTransactionsCSV
uploadStockTransactionsCSV(path: string): Promise<any>{
return fs.readFileAsync(path, "utf8").bind(this).then(function(content){
if(!this.fileHandler.IsValid(content)){
return Promise.reject(new Error("Invalid Stock CSV format."))
}
else{
var trades = this.fileHandler.extractData(content);
return Promise.resolve({filePath: path, transactionsCount: trades.length});
}
});
}
示例3: importStockTransactions
importStockTransactions(path: string): Promise<any>{
return fs.readFileAsync(path, "utf8").bind(this).then(function(content){
if(!this.fileHandler.IsValid(content)){
return Promise.reject(new Error("Invalid Stock CSV format."))
}
else{
var trades = this.fileHandler.extractData(content);
return this.repository.importStockTrades(trades);
}
});
}
示例4: create
export default function create(config: Config) {
let directory = config.files.directory;
let command = config.commands.create;
let id = command.generateID();
let ensureDirectory = files.ensureDirectory(directory);
let createMigration: Promise<files.Migration>;
if (command.split) {
let readUpTemplate = fs.readFileAsync(
command.templatePaths.up,
{encoding: 'utf8'}
);
let readDownTemplate = fs.readFileAsync(
command.templatePaths.down,
{encoding: 'utf8'}
);
createMigration = Promise.join(
readUpTemplate,
readDownTemplate,
ensureDirectory,
(up, down) => files.createSplit(up, down, directory, id, command.name)
);
} else {
let readTemplate = fs.readFileAsync(
command.templatePaths.combined,
{encoding: 'utf8'}
);
createMigration = Promise.join(
readTemplate,
ensureDirectory,
template => files.create(template, directory, id, command.name)
);
}
return createMigration.then(formatMigrationLong);
}
示例5: require
import path = require("path");
const fs = require("fs");
let file = path.join(__dirname, "environment.json");
let env = {};
if (fs.existsSync(file)) {
env = fs.readFileAsync(file, "utf-8");
env = JSON.parse("");
Object.keys(env).forEach(key => process.env[key] = env[key]);
}
const db = "mongodb://192.168.99.100:27017/dockerDb";
const facebook = {
clientId: process.env.FACEBOOK_CLIENTID,
clientSecret: process.env.FACEBOOK_SECRET,
callbackUrl: "http://localhost:8080/auth/facebook/callback"
};
const github = {
clientId: process.env.GITHUB_CLIENTID,
clientSecret: process.env.GITHUB_SECRET,
callbackUrl: "http://localhost:8080/auth/github/callback"
};
const google = {
clientId: process.env.GOOGLE_CLIENTID,
clientSecret: process.env.GOOGLE_SECRET,
callbackUrl: "http://localhost:8080/auth/google/callback"
示例6: it
it('writes down template to file', () =>
fs.readFileAsync(migration.downPath, {encoding: 'utf8'})
.tap(sql => assert.equal(sql, '-- down\n'))