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


TypeScript base-64.encode函数代码示例

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


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

示例1: autenthicate

async function autenthicate(): Promise<boolean> {
    // <base64 encoded client_id:client_secret>
    const keys = `${config.get("spotify.clientId")}:${config.get("spotify.clientSecret")}`;
    const encodedKeys = base64.encode(utf8.encode(keys));

    const requestParams = querystring.stringify({
        grant_type: "client_credentials"
    });

    try {
        const authResult = await spotifyAccountApi.post<SpotifyAuthResponse>("token", requestParams, {
            headers: {
                "Authorization": `Basic ${encodedKeys}`,
                "Content-Type": "application/x-www-form-urlencoded"
            }
        });

        authToken = authResult.data.access_token;
        const oneMinute = 60;
        const msInMin = 1000;
        const reAuthDelay = authResult.data.expires_in - oneMinute;
        setTimeout(() => {
            authToken = "";
        }, reAuthDelay * msInMin);
        return true;
    } catch (e) {
        logError("Spotify Auth", e);
        return false;
    }
}
开发者ID:endway,项目名称:songSearchBot,代码行数:30,代码来源:spotify.ts

示例2: switch

    ws.on('message', (data) => {
        const obj = JSON.parse(data);
        switch (obj.msg) {
            case MESSAGES.TEXT:
                const rawText = JSON.parse(data).text.trim() || '';
                const text = base64.encode(utf8.encode(rawText));
                const trytes = iota.utils.toTrytes(text);
                if (!text || !isValidText(text, trytes)) {
                    if(ws.readyState !== 1) return;
                    ws.send(payload(MESSAGES.TEXT_INVALID, 'text is not convertible (symbols not supported)'));
                    return;
                }
                if (trytes.length > MAX_MESSAGE) {
                    if(ws.readyState !== 1) return;
                    ws.send(payload(MESSAGES.TEXT_INVALID, 'text is too long'));
                    return;
                }

                // chop up the message into txs to fit the message
                let transfers = [];
                let msg = '';
                let i = 0;
                for (; i < trytes.length; i++) {
                    msg += trytes.charAt(i);
                    if (i !== 0 && i + 1 % MAX_TRYTES === 0) {
                        transfers.push(newTransferObj(msg));
                        // reset message for next segment
                        msg = '';
                    }
                }
                if (i + 1 % MAX_TRYTES !== 0) {
                    transfers.push(newTransferObj(msg));
                }

                let snip = transfers.reduce((prev, current) => {
                    return prev + current.message;
                }, '');

                if (snip !== trytes) {
                    throw Error("segments not split correctly");
                }

                // create transfer
                if(ws.readyState !== 1) return;
                ws.send(payload(MESSAGES.PREPARING_TRANSFER));
                iota.api.prepareTransfers(SEED, transfers, {security: 1}, (err, transferTrytes) => {
                    // send transaction
                    if (err) {
                        if(ws.readyState !== 1) return;
                        ws.send(payload(MESSAGES.TX_SEND_ERROR, err));
                        return;
                    }
                    if (ws.readyState !== 1) return;
                    ws.send(payload(MESSAGES.SENDING_TX));
                    iota.api.sendTrytes(transferTrytes, DEPTH, MWM, (err, txs) => {
                        if (err) {
                            if (ws.readyState !== 1) return;
                            ws.send(payload(MESSAGES.TX_SEND_ERROR, err));
                            return;
                        }
                        if (ws.readyState !== 1) return;
                        ws.send(payload(MESSAGES.TX_SEND_SUCCESS, txs));

                    });
                });
                break;

            default:
                console.log('sending unknown message');
                ws.send(payload(MESSAGES.UNKNOWN));
        }
    });
开发者ID:luca-moser,项目名称:tangle-paste,代码行数:72,代码来源:server.ts

示例3:

import * as base64 from 'base-64';
import * as utf8 from 'utf8';

let text = 'foo © bar 𝌆 baz';
let bytes = utf8.encode(text);
let encoded = base64.encode(bytes);
// → 'Zm9vIMKpIGJhciDwnYyGIGJheg=='

encoded = 'Zm9vIMKpIGJhciDwnYyGIGJheg==';
bytes = base64.decode(encoded);
text = utf8.decode(bytes);

const version = base64.version;
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:13,代码来源:base-64-tests.ts

示例4: createCursor

 public createCursor(obj: ICursor = { skip: 0, sort: {} }): string {
     return encode(JSON.stringify(obj));
 }
开发者ID:vnenkpet,项目名称:japanese,代码行数:3,代码来源:Pagination.ts


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