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


TypeScript text-encoding-utf-8.TextEncoder类代码示例

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


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

示例1: test_encoder

function test_encoder() {
    const text = "plain text";
    let uint8array: Uint8Array;

    // constructor
    uint8array = new TextEncoder().encode(text);
    uint8array = new TextEncoder('utf-8').encode(text);

    uint8array = TextEncoder().encode(text);
    uint8array = TextEncoder('utf-8').encode(text);

    // attributes
    const encoder = new TextEncoder();
    encoder.encoding = 'utf-8';
    const encoding: string = encoder.encoding;

    // methods
    encoder.encode();
    encoder.encode(text);
}
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:20,代码来源:text-encoding-utf-8-tests.ts

示例2: FlatListData

describe(`DictionaryVector`, () => {
    const dictionary = ['foo', 'bar', 'baz'];
    const extras = ['abc', '123']; // values to search for that should NOT be found
    let offset = 0;
    const offsets = Uint32Array.of(0, ...dictionary.map((d) => { offset += d.length; return offset; }));
    const dictionary_vec = new Utf8Vector(new FlatListData(new Utf8(), dictionary.length, null, offsets, utf8Encoder.encode(dictionary.join(''))));

    const indices = Array.from({length: 50}, () => Math.random() * 3 | 0);

    describe(`index with nullCount == 0`, () => {
        const indices_data = new FlatData(new Int32(), indices.length, new Uint8Array(0), indices);

        const values = Array.from(indices).map((d) => dictionary[d]);
        const vector = new DictionaryVector(new DictionaryData(new Dictionary(dictionary_vec.type, indices_data.type), dictionary_vec, indices_data));

        basicVectorTests(vector, values, extras);

        describe(`sliced`, () => {
            basicVectorTests(vector.slice(10, 20), values.slice(10,20), extras);
        });
    });

    describe(`index with nullCount > 0`, () => {
        const validity = Array.from({length: indices.length}, () => Math.random() > 0.2 ? true : false);
        const indices_data = new FlatData(new Int32(), indices.length, packBools(validity), indices, 0, validity.reduce((acc, d) => acc + (d ? 0 : 1), 0));
        const values = Array.from(indices).map((d, i) => validity[i] ? dictionary[d] : null);
        const vector = new DictionaryVector(new DictionaryData(new Dictionary(dictionary_vec.type, indices_data.type), dictionary_vec, indices_data));

        basicVectorTests(vector, values, ['abc', '123']);
        describe(`sliced`, () => {
            basicVectorTests(vector.slice(10, 20), values.slice(10,20), extras);
        });
    });
});
开发者ID:CodingCat,项目名称:arrow,代码行数:34,代码来源:vector-tests.ts

示例3: toTypedArray

 protected readData<T extends DataType>(type: T, { offset }: BufferMetadata = this.getBufferMetadata()) {
     const { sources } = this;
     if (DataType.isTimestamp(type) === true) {
         return new Uint8Array(int64DataFromJSON(sources[offset] as string[]));
     } else if ((DataType.isInt(type) || DataType.isTime(type)) && type.bitWidth === 64) {
         return new Uint8Array(int64DataFromJSON(sources[offset] as string[]));
     } else if (DataType.isDate(type) && type.unit === DateUnit.MILLISECOND) {
         return new Uint8Array(int64DataFromJSON(sources[offset] as string[]));
     } else if (DataType.isDecimal(type) === true) {
         return new Uint8Array(decimalDataFromJSON(sources[offset] as string[]));
     } else if (DataType.isBinary(type) === true || DataType.isFixedSizeBinary(type) === true) {
         return new Uint8Array(binaryDataFromJSON(sources[offset] as string[]));
     } else if (DataType.isBool(type) === true) {
         return new Uint8Array(packBools(sources[offset] as number[]).buffer);
     } else if (DataType.isUtf8(type) === true) {
         return utf8Encoder.encode((sources[offset] as string[]).join(''));
     } else {
         return toTypedArray(type.ArrayType, sources[offset].map((x) => +x)) as any;
     }
 }
开发者ID:dremio,项目名称:arrow,代码行数:20,代码来源:json.ts

示例4: ArrayConstructor

function createDataArray<T extends TypedArray>(sources: any[][], field: Field, _fieldNode: FieldNode, buffer: Buffer, ArrayConstructor: TypedArrayConstructor<T>): T {
    let type = field.type, data: ArrayLike<number> | ArrayBufferLike;
    if (type.isTimestamp() === true) {
        data = int64sFromJSON(sources[buffer.offset.low] as string[]);
    } else if ((type.isInt() || type.isTime()) && type.bitWidth === 64) {
        data = int64sFromJSON(sources[buffer.offset.low] as string[]);
    } else if (type.isDate() && type.unit === DateUnit.MILLISECOND) {
        data = int64sFromJSON(sources[buffer.offset.low] as string[]);
    } else if (type.isDecimal() === true) {
        data = decimalFromJSON(sources[buffer.offset.low] as string[]);
    } else if (type.isBinary() === true) {
        data = binaryFromJSON(sources[buffer.offset.low] as string[]);
    } else if (type.isBool() === true) {
        data = booleanFromJSON(sources[buffer.offset.low] as number[]).buffer;
    } else if (type.isUtf8() === true) {
        data = encoder.encode((sources[buffer.offset.low] as string[]).join(''));
    } else {
        data = (sources[buffer.offset.low]).map((x) => +x);
    }
    return new ArrayConstructor(data);
}
开发者ID:giantwhale,项目名称:arrow,代码行数:21,代码来源:json.ts


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