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


TypeScript utf8.encode函數代碼示例

本文整理匯總了TypeScript中utf8.encode函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript encode函數的具體用法?TypeScript encode怎麽用?TypeScript encode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了encode函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: it

 it('test strings', () => {
   const decoder = new Utf8ToUtf32();
   const target = new Uint32Array(500);
   for (let i = 0; i < TEST_STRINGS.length; ++i) {
     const utf8Data = fromByteString(encode(TEST_STRINGS[i]));
     const length = decoder.decode(utf8Data, target);
     assert.equal(toString(target, length), TEST_STRINGS[i]);
     decoder.clear();
   }
 });
開發者ID:sourcelair,項目名稱:xterm.js,代碼行數:10,代碼來源:TextDecoder.test.ts

示例3: 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

示例4:

/// <reference path="./quoted-printable.d.ts" />
/// <reference path="../utf8/utf8.d.ts" />

import * as quotedPrintable from "quoted-printable";
import * as utf8 from "utf8";

quotedPrintable.version === "0.2.1";
quotedPrintable.encode(utf8.encode("foo=bar"));
quotedPrintable.encode(utf8.encode("Iñtërnâtiônàlizætiøn☃💩"));
utf8.decode(quotedPrintable.decode("foo=3Dbar"));
utf8.decode(quotedPrintable.decode("I=C3=B1t=C3=ABrn=C3=A2ti=C3=B4n=C3=A0liz=C3=A6ti=C3=B8n=E2=98=83=F0=9F=92=\r\n=A9"));
開發者ID:CNManning,項目名稱:DefinitelyTyped,代碼行數:11,代碼來源:quoted-printable-tests.ts

示例5: test_encode

function test_encode(): void {
    utf8.encode("\x49");
    utf8.encode("\uD800\uDC01");
}
開發者ID:Agamnentzar,項目名稱:DefinitelyTyped,代碼行數:4,代碼來源:utf8-tests.ts

示例6:

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

示例7: function

_.utf8Encode = function (str: string): string {
  return utf8.encode(str);
};
開發者ID:chen-framework,項目名稱:chen,代碼行數:3,代碼來源:util.ts

示例8: md5Encode

 static md5Encode(data: string, encoding: string ="hex"): string {
     var mySign = crypto.createHash('md5').update(utf8.encode(data)).digest(encoding);
     return mySign;
 }
開發者ID:stableShip,項目名稱:EncryptTool,代碼行數:4,代碼來源:EncryptTool.ts


注:本文中的utf8.encode函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。