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


TypeScript iconv-lite.encode函数代码示例

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


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

示例1: it

 it("Big5", () => {
     const testData = "能 脊 胼 胯 臭 臬 舀 舐 航 舫 舨 般 芻 茫 荒 荔";
     const textEncoding = "Big5";
     writeFileSync(editor.tempFile, encode(testData, textEncoding), {encoding: "binary"});
     const result = editor.run();
     assert.equal(testData, result);
 });
开发者ID:mrkmg,项目名称:node-external-editor,代码行数:7,代码来源:main.spec.ts

示例2: it

			it('detects and decodes utf-16be bom document', () => {
				var doc = linez(Buffer.concat([
					new Buffer([0xfe, 0xff]),
					iconv.encode('foo', 'utf16be')
				]));
				expect(doc.charset).to.eq('utf-16be');
				expect(doc.lines[0].text).to.eq('foo');
			});
开发者ID:jedmao,项目名称:linez,代码行数:8,代码来源:linez.spec.ts

示例3: getMacHexCode

function getMacHexCode(str: string, i: number, macCodePages: any) {
  const code = str.charCodeAt(i)
  if (code < 128) {
    return code.toString(16)
  }
  else if (code < 256) {
    return iconv.encode(str[i], "macroman").toString("hex")
  }
  else {
    for (let i = 0; i < macCodePages.length; i++) {
      const result = iconv.encode(str[i], macCodePages[i]).toString("hex")
      if (result !== undefined) {
        return result
      }
    }
  }
  return code
}
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:18,代码来源:licenseButtons.ts

示例4: Buffer

(() => {
	// Convert from an encoded buffer to js string.
	const str: string = iconv.decode(new Buffer([0x68, 0x65, 0x6c, 0x6c, 0x6f]), 'win1251');

	// Convert from js string to an encoded buffer.
	const buf: Buffer = iconv.encode("Sample input string", 'win1251');

	// Check if encoding is supported
	const exists: boolean = iconv.encodingExists("us-ascii");
})();
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:10,代码来源:iconv-lite-tests.ts

示例5: encodeContent

export async function encodeContent (content: Buffer, encoding: string, charset: Charset) {
    content = charsetEncoder.encode(content, charset.get(), { addBOM: charset.isFromBOM() });

    if (encoding === GZIP_CONTENT_ENCODING)
        return gzip(content);

    if (encoding === DEFLATE_CONTENT_ENCODING)
        return deflate(content);

    if (encoding === BROTLI_CONTENT_ENCODING)
        return Buffer.from(require('brotli').compress(content));

    return content;
}
开发者ID:DevExpress,项目名称:testcafe-hammerhead,代码行数:14,代码来源:index.ts

示例6: async

  router.get('/export/:format', async (req, res) => {
    const storage = botScopedStorage.get(req.params.botId)
    const config = await bp.config.getModuleConfigForBot('qna', req.params.botId)
    const data = await prepareExport(storage, { flat: true })

    if (req.params.format === 'csv') {
      res.setHeader('Content-Type', 'text/csv')
      res.setHeader('Content-disposition', `attachment; filename=qna_${moment().format('DD-MM-YYYY')}.csv`)

      const categoryWrapper = storage.hasCategories() ? ['category'] : []
      const parseOptions = {
        fields: ['question', 'action', 'answer', 'answer2', ...categoryWrapper],
        header: true
      }
      const json2csvParser = new Json2csvParser(parseOptions)

      res.end(iconv.encode(json2csvParser.parse(data), config.exportCsvEncoding))
    } else {
      res.setHeader('Content-Type', 'application/json')
      res.setHeader('Content-disposition', `attachment; filename=qna_${moment().format('DD-MM-YYYY')}.json`)
      res.end(JSON.stringify(data))
    }
  })
开发者ID:seffalabdelaziz,项目名称:botpress,代码行数:23,代码来源:api.ts

示例7:

 encode: (str, enc) => {
     encodings.add(enc);
     return iconvLite.encode(str, enc)
 },
开发者ID:mazira,项目名称:rtf-parser,代码行数:4,代码来源:de-encapsulate.test.ts

示例8: generateUserNameBuf

/***
 * Generate a userName Buffer. Currently hardcoded to CP-850, but the
 * true char encoding is LMBCS
 * @param {string} userName The username to be converted to a CP-850 buffer
 * @returns {buffer} Username encoded in CP-850 and stuffed into a Buffer
 */
function generateUserNameBuf(userName: string): Buffer {
  return encode(userName, "ibm850");
};
开发者ID:markusberg,项目名称:ltpa,代码行数:9,代码来源:index.ts


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