How to use text-encoding - 10 common examples

To help you get started, we’ve selected a few text-encoding examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github killercup / wasm-experiments / src / type-converter.js View on Github external
arg(data, exports) {
      ensure(typeof data === "string", "Can only use `Uint8Array` as `&[u8]`");

      // @ts-ignore -- yes accessing these exports works
      const { alloc, memory } = exports;
      ensure(alloc, "You need to export an `alloc` function to get strings from WASM");
      ensure(memory, "You need to export the main memory to get strings from WASM");

      const utf8Encoder = new TextEncoder("UTF-8");
      const stringBuffer = utf8Encoder.encode(data);

      return newSlice(memory, alloc, stringBuffer);
    },
    /**
github mudchina / webtelnet / webtelnet-proxy.js View on Github external
reset: function() {
    this.io = null;
    this.logTraffic = false;

    this.isRunning = false;
    this.timer = 0;
    this.lastTick = 0;

    this.sockets = {};  // sid -> socket
    this.socketsCount = 0;
    
    this.port = 23;
    this.host = '127.0.0.1';
    this.decoder = new TextDecoder('utf-8');
    return this;
  },
github jeka-kiselyov / mdict / mdict-parser.js View on Github external
attrs.Encoding = attrs.Encoding || 'UTF-16';
      
      _searchTextLen = (attrs.Encoding === 'UTF-16') 
                          ?   function(dv, offset) {
                                offset = offset;
                                var mark = offset;
                                while (dv.getUint16(offset++)) { /* scan for NUL */ };
                                return offset - mark;
                          } : function(dv, offset) {
                                offset = offset;
                                var mark = offset;
                                while (dv.getUint8(offset++)) { /* scan for NUL */ }
                                return offset - mark - 1;
                          };
      
      _decoder = new TextDecoder(attrs.Encoding || 'UTF-16LE');

      _bpu = (attrs.Encoding === 'UTF-16') ? 2 : 1;
      
      if (parseInt(attrs.GeneratedByEngineVersion, 10) >= 2.0) {
        _v2 = true;
        _tail = _bpu;

          // HUGE dictionary file (>4G) is not supported, take only lower 32-bit
        _readNum     = function(scanner) { return scanner.forward(4), scanner.readInt(); };
        _readShort   = function(scanner) { return scanner.readUint16(); };
        _checksum_v2 = function(scanner) { return scanner.checksum(); };
      } else {
        _tail = 0;
      }
      
      // keyword index decrypted?
github yoichiro / actions-tools / src / conversation.ts View on Github external
_handleScreenOut(data: AssistResponse, response: ConversationResponse): void {
        if (data.screen_out) {
            if (data.screen_out.format === 1) { // HTML
                // const html = Buffer.from(data.screen_out.data!.buffer).toString()
                const html = new te.TextDecoder("utf-8").decode(data.screen_out.data!)
                response.screenOut = {
                    format: data.screen_out.format,
                    data: html,
                }
            }
        }
    }
github EOSIO / eosio-explorer / packages / api-rpc / src / api / push_action.ts View on Github external
export default async (query: {
  endpoint: string,
  account_name: string,
  private_key: string,
  actor: string,
  permission: string,
  action_name: string,
  payload: any
}) => {
  try{
    let { endpoint, account_name, private_key, actor, permission, action_name, payload } = query;

    const rpc = new JsonRpc(endpoint);
    const signatureProvider = new JsSignatureProvider([private_key]);
    const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });


    if (account_name === "eosio" && action_name==="setabi"){
      const buffer = new Serialize.SerialBuffer({
        textEncoder: api.textEncoder,
        textDecoder: api.textDecoder,
      });

      let abi = payload.abi;
      const abiDefinition = api.abiTypes.get('abi_def');
      // need to make sure abi has every field in abiDefinition.fields
      // otherwise serialize throws error
      abi = abiDefinition!.fields.reduce(
          (acc, { name: fieldName }) => Object.assign(acc, { [fieldName]: acc[fieldName] || [] }),
          abi,
      );
github emailjs / emailjs-mime-parser / src / mimeparser-unit.js View on Github external
it('should decode unencoded 7bit input', function () {
    var fixture = 'Content-Type: text/plain\r\n' +
      '\r\n' +
      'xxxx\r\n' +
      'yyyy'
    const root = parse(fixture)
    expect(new TextDecoder('utf-8').decode(root.content)).to.equal('xxxx\nyyyy')
  })
github emailjs / emailjs-mime-parser / src / mimeparser-unit.js View on Github external
it('should ignore charset for plaintext attachment', function () {
    var fixture = 'Content-Type: text/plain; charset="latin_1"\r\n' +
      'Content-Disposition: attachment\r\n' +
      'Content-Transfer-Encoding: quoted-printable\r\n' +
      '\r\n' +
      'l=F5petam'
    var expectedText = 'lõpetam'
    const root = parse(fixture)
    expect(new TextDecoder('iso-8859-1').decode(root.content)).to.equal(expectedText)
  })
github popcodeorg / popcode / src / templates.js View on Github external
import base64 from 'base64-js';
import {TextEncoder} from 'text-encoding';
import spinnerPageHtml from '../templates/github-export.html';

export const spinnerPage = base64.fromByteArray(
  new TextEncoder('utf-8').encode(spinnerPageHtml),
);
github uber / xviz / modules / builder / src / writers / glb-writer / glb-encoder.js View on Github external
function convertObjectToJsonChunk(json) {
  const jsonChunkString = JSON.stringify(json);
  const textEncoder = new TextEncoder('utf8');
  return textEncoder.encode(jsonChunkString);
}
github IBM / ipfs-social-proof / src / utils.js View on Github external
function t2a (text) {
  return new TextEncoder("utf-8").encode(text)
}

text-encoding

Polyfill for the Encoding Living Standard's API.

(Unlicense OR Apache-2.0)
Latest version published 6 years ago

Package Health Score

56 / 100
Full package analysis