当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript jsonfile.writeFile函数代码示例

本文整理汇总了TypeScript中jsonfile.writeFile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript writeFile函数的具体用法?TypeScript writeFile怎么用?TypeScript writeFile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了writeFile函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getSettings

export function getSettings():Isettings{
    //Give some default values
    let settings:Isettings = {
        port : getRandomPort()
    };
    
    // *******************************************
    // Checks that iisexpress.json exist
    // *******************************************
	let settingsFilePath = vscode.workspace.rootPath + "\\.vscode\\iisexpress.json";
    
    //use -> https://www.npmjs.com/package/jsonfile
    var jsonfile = require('jsonfile');
    
    try {
        //Check if we can find the file path (get stat info on it)
        let fileCheck = fs.statSync(settingsFilePath);
        
        //read file .vscode\iisexpress.json and overwrite port property from iisexpress.json
        settings = jsonfile.readFileSync(settingsFilePath);
    }
    catch (err) {
        //file didn't exist so
        //create .vscode\iisexpress.json and append settings object
       	jsonfile.writeFile(settingsFilePath, settings, {spaces: 2}, function (err) {
            console.error(err);
        });
    }
    
    //Return an object back from verifications
    return settings;
    
}
开发者ID:EbXpJ6bp,项目名称:IIS-Express-Code,代码行数:33,代码来源:settings.ts

示例2: function

 ipcMain.on("save", (event, arg) => {
   if (arg.pathToSave) {
     jsonfile.writeFile(arg.pathToSave, arg.spec, function(err) {
       if (!err) {
         event.sender.send("onSaveSuccess", {
           name: arg.name,
           path: arg.pathToSave
         });
       }
     });
   } else {
     dialog.showSaveDialog(
       {
         filters: [
           {
             name: "Json",
             extensions: ["json"]
           }
         ]
       },
       filename => {
         if (filename) {
           jsonfile.writeFile(filename, arg.spec, function(err) {
             if (!err) {
               event.sender.send("onSaveSuccess", {
                 name: arg.name,
                 path: filename
               });
             }
           });
         }
       }
     );
   }
 });
开发者ID:Raathigesh,项目名称:Atmo,代码行数:35,代码来源:messageHandler.ts

示例3: writetoJSON

function writetoJSON(encryptedUsername, encryptedPassword) {
      
   console.log("encrypted username is: " + encryptedUsername);
   var file = 'data.json';
   var obj = {'username': encryptedUsername.toString(), 'password': encryptedPassword.toString()};
    
   jsonfile.writeFile(file, obj, function (err) {
     if (err) throw err;
     console.log('username and password succesfullt saved');
     
   })

}
开发者ID:cchampernowne,项目名称:project-seed,代码行数:13,代码来源:storeCredentials.ts

示例4:

jsonfile.readFile(file).then(obj => {
    // $ExpectType any
    obj;
});
jsonfile.readFile(file, { encoding: 'utf8', throws: true }).then(obj => {
    // $ExpectType any
    obj;
});

// $ExpectType any
jsonfile.readFileSync(file);
jsonfile.readFileSync(file, { encoding: 'utf8', throws: true });

// $ExpectType void
jsonfile.writeFile(file, obj, err => {
    // $ExpectType ErrnoException
    err;
});

// $ExpectType void
jsonfile.writeFile(file, obj, { spaces: 2 }, err => {
    // $ExpectType ErrnoException
    err;
});

// $ExpectType void
jsonfile.writeFile(file, obj, { spaces: 2, EOL: '\r\n' }, err => {
    // $ExpectType ErrnoException
    err;
});

// $ExpectType void
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:32,代码来源:jsonfile-tests.ts

示例5:

// Following are lifted from the samples on the NPM page, modified to pass
//  the linter

import * as jsonfile from 'jsonfile';

const file = '/tmp/data.json';
const obj = {name: 'JP'};

jsonfile.readFile(file, (err: NodeJS.ErrnoException | null, obj: any) => {
  console.dir(obj);
});

console.dir(jsonfile.readFileSync(file));

jsonfile.writeFile(file, obj, (err: NodeJS.ErrnoException) => {
  console.error(err);
});

jsonfile.writeFile(file, obj, {spaces: 2}, (err: NodeJS.ErrnoException) => {
  console.error(err);
});

jsonfile.writeFile(file, obj, {spaces: 2, EOL: '\r\n'}, (err: NodeJS.ErrnoException) => {
  console.error(err);
});

jsonfile.writeFile(file, obj, {flag: 'a'}, (err: NodeJS.ErrnoException) => {
  console.error(err);
});

jsonfile.writeFileSync(file, obj);
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:jsonfile-tests.ts

示例6: writeFile

 writeFile(filename: string, obj: any, options: any, cb?: (err: Error) => void): any {
   return jsonfile.writeFile(filename, obj, options, cb);
 }
开发者ID:jreeme,项目名称:firmament-yargs,代码行数:3,代码来源:safe-json-impl.ts


注:本文中的jsonfile.writeFile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。