當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。