當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。