本文整理匯總了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'))