當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript lodash.attempt函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。