本文整理汇总了TypeScript中lodash.attempt函数的典型用法代码示例。如果您正苦于以下问题:TypeScript attempt函数的具体用法?TypeScript attempt怎么用?TypeScript attempt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了attempt函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: decrypt
/**
* Decrypt a wallet file data
*
* @static
* @param {Uint8Array} passphrase The passphrase to use as decryption key
* @param {Buffer} encWalletData The wallet file data
* @returns
* @throws ErrFailedToDecrypt
* @memberof Wallet
*/
public static decrypt(
passphrase: Uint8Array,
encWalletData: Buffer,
): IWalletData {
const h = blake2.createHash('blake2s');
const hashedPassphrase = h.update(passphrase).digest();
const decData = decrypt(hashedPassphrase, encWalletData);
const isError = _.isError(
_.attempt(JSON.parse, decData.toString('utf-8')),
);
if (isError) {
throw ErrFailedToDecrypt;
}
return JSON.parse(decData.toString('utf-8'));
}
开发者ID:ellcrys,项目名称:safehold,代码行数:25,代码来源:wallet.ts
示例2: isCacheValueValid
/**
* Check if the cache value from the local storage is still valid
* A valid cache value is when:
* - Not null or empty string
* - Not an empty array
* - Not expired
* @param {String} localStorageKey The key in the browser local storage
* @return {String} The cache value if valid, null otherwise
*/
public isCacheValueValid(localStorageKey: string): any {
let value = null;
// Get the current value in local storage
const cachedValue: string = localStorage.getItem(localStorageKey);
if (cachedValue !== null && cachedValue !== undefined) {
// Get the cached value
let localStorageValue = JSON.parse(cachedValue).value;
// If the value is a JSON object
if (!_.isError(_.attempt(() => JSON.parse(localStorageValue)))) {
localStorageValue = JSON.parse(localStorageValue);
}
// Make sure there is a valid value in the cache (not [])
if (localStorageValue.length > 0) {
// Check if the cache value is expired
const expirationValue = JSON.parse(cachedValue).expiration;
if (expirationValue) {
const expirationDate: Date = new Date(JSON.parse(cachedValue).expiration);
const now: Date = new Date();
if (now < expirationDate) {
value = localStorageValue;
}
} else {
value = localStorageValue;
}
}
}
return value;
}
开发者ID:ScoutmanPt,项目名称:PnP,代码行数:50,代码来源:UtilityModule.ts
示例3: express
import * as _ from 'lodash';
import * as express from 'express';
import * as path from 'path';
import * as logger from 'morgan';
import * as bodyParser from 'body-parser';
import * as db from './db';
import api from './api';
import * as utils from './utils';
import * as conf_steps from './steps/conf';
const app = express();
_.attempt(() => require('source-map-support').install());
const staticFilesOptions = { maxAge: process.env.NODE_ENV === 'production' ? 60 * 60 * 1000 : 0 };
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/app/favicon.ico'));
app.use(logger(process.env.NODE_ENV === 'production' ? 'combined' : 'dev'));
app.use("/", express.static(path.join(__dirname, '../app/dist'), staticFilesOptions));
app.use(utils.express_auth);
app.use('/api',
bodyParser.json({type: '*/*'}), // do not bother checking, everything we will get is JSON :)
bodyParser.urlencoded({ extended: false }),
api);
// redo what app/src/router.ts is doing
app.use([ "login", "steps", ...Object.keys(conf_steps.steps) ].map(path => "/" + path), utils.index_html);
db.init(() => {
开发者ID:prigaux,项目名称:compte-externe,代码行数:31,代码来源:start-server.ts
示例4: getFile
const config = vscode.workspace.getConfiguration ().get ( extension );
if ( !config['configPath'] ) delete config['configPath'];
return config;
},
async getFile ( filePath ) {
const content = await Utils.file.read ( filePath );
if ( !content || !content.trim () ) return;
const config: any = _.attempt ( JSON5.parse, content );
if ( _.isError ( config ) ) {
const option = await vscode.window.showErrorMessage ( '[{{displayName}}] Your configuration file contains improperly formatted JSON', { title: 'Overwrite' }, { title: 'Edit' } );
if ( option && option.title === 'Overwrite' ) {
await Utils.file.write ( filePath, '{}' );
return {};
} else {
if ( option && option.title === 'Edit' ) {
开发者ID:fabiospampinato,项目名称:template-vscode-extension,代码行数:29,代码来源:config.ts
注:本文中的lodash.attempt函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论