@gooddata/emailjs-mime-codec-new

中文文档
3.0.2发布于 2025/08/19MITCommonJS近 30 天下载 2.8万

Encode and decode quoted printable and base64 strings

原始使用文档
文档目录19 节
  1. Important
  2. Usage
  3. Charset functions
  4. foldLines
  5. mimeWordEncode
  6. mimeWordDecode
  7. continuationEncode
  8. quotedPrintableEncode
  9. quotedPrintableDecode
  10. base64Encode
  11. base64Decode
  12. mimeWordEncode
  13. mimeWordsEncode
  14. mimeWordDecode
  15. mimeWordsDecode
  16. headerLineEncode
  17. headerLinesDecode
  18. parseHeaderValue
  19. License

MIME Codec

Important

This is a fork of emailjs/emailjs-mime-codec (MIT). Upstream: https://github.com/emailjs/emailjs-mime-codec

Changes:

  • used latest ramda library version

The library allows you to encode and decode between different MIME related encodings. Quoted-Printable, Base64 etc.

All input can use any charset (in this case, the value must not be a string but an arraybuffer of Uint8Array) but output is always unicode.

Usage

npm install --save @gooddata/emailjs-mime-codec-new

import {
  encode, decode, convert,
  mimeEncode, mimeDecode,
  base64Encode, base64Decode,
  quotedPrintableEncode, quotedPrintableDecode,
  mimeWordEncode, mimeWordDecode,
  mimeWordsEncode, mimeWordsDecode,
  headerLineEncode, headerLinesDecode,
  continuationEncode,
  foldLines,
  parseHeaderValue
} from '@gooddata/emailjs-mime-codec-new'

Charset functions

encode(data: String) -> Uint8Array
decode(data: Uint8Array, charset: String) -> String
convert(data, charset: String) -> String

encode takes a String and returns a UTF-8 encoded Uint8Array.

decode takes a Uint8Array along with a charset and decodes the typed array to a String. Charset defaults to UTF-8.

convert chains encode and decode and converts an input string with a given encoding to a UTF-8 encoded Uint8Array.

foldLines

Folds a long line according to the RFC 5322 http://tools.ietf.org/html/rfc5322#section-2.1.1

foldLines(str [, lineLengthMax[, afterSpace]]) -> String
  • str - String to be folded
  • lineLengthMax - Maximum length of a line (defaults to 76)
  • afterSpace - If true, leave a space in th end of a line

For example:

foldLines('Content-Type: multipart/alternative; boundary="----zzzz----"')

results in

Content-Type: multipart/alternative;
     boundary="----zzzz----"

mimeWordEncode

Encodes a string into mime encoded word format http://en.wikipedia.org/wiki/MIME#Encoded-Word (see also mimeWordDecode)

mimeWordEncode(str [, mimeWordEncoding[, fromCharset]]) -> String
  • str - String or Uint8Array to be encoded
  • mimeWordEncoding - Encoding for the mime word, either Q or B (default is 'Q')
  • fromCharset - If the first parameter is a typed array, use this encoding to decode the value to unicode

For example:

mimeWordEncode('See on õhin test', 'Q');

Becomes with UTF-8 and Quoted-printable encoding

=?UTF-8?Q?See_on_=C3=B5hin_test?=

mimeWordDecode

Decodes a string from mime encoded word format (see also mimeWordEncode)

mimeWordDecode(str) -> String
  • str - String to be decoded

For example

mimeWordDecode('=?UTF-8?Q?See_on_=C3=B5hin_test?=');

will become

See on õhin test

continuationEncode

Encodes and splits a header param value according to RFC2231 Parameter Value Continuations.

continuationEncode(key, str [, fromCharset]) -> Array
  • key - Parameter key (eg. filename)
  • str - String or an Uint8Array value to encode
  • fromCharset - If str is a typed array, use this charset to decode the value to unicode before encoding

The method returns an array of encoded parts with the following structure: [{key:'...', value: '...'}]

Example

continuationEncode('filename', 'filename õäöü.txt', 20);
->
[ { key: 'filename*0*', value: 'utf-8\'\'filename%20' },
  { key: 'filename*1*', value: '%C3%B5%C3%A4%C3%B6' },
  { key: 'filename*2*', value: '%C3%BC.txt' } ]

This can be combined into a properly formatted header:

Content-disposition: attachment; filename*0*="utf-8''filename%20"
  filename*1*="%C3%B5%C3%A4%C3%B6"; filename*2*="%C3%BC.txt"

quotedPrintableEncode

Encodes a string into Quoted-printable format (see also quotedPrintableDecode). Maximum line length for the generated string is 76 + 2 bytes.

quotedPrintableEncode(str [, fromCharset]) -> String
  • str - String or an Uint8Array to mime encode
  • fromCharset - If the first parameter is a typed array, use this charset to decode the value to unicode before encoding

quotedPrintableDecode

Decodes a string from Quoted-printable format (see also quotedPrintableEncode).

quotedPrintableDecode(str [, fromCharset]) -> String
  • str - Mime encoded string
  • fromCharset - Use this charset to decode mime encoded string to unicode

base64Encode

Encodes a string into Base64 format (see also base64Decode). Maximum line length for the generated string is 76 + 2 bytes.

base64Encode(str [, fromCharset]) -> String
  • str - String or an Uint8Array to base64 encode
  • fromCharset - If the first parameter is a typed array, use this charset to decode the value to unicode before encoding

base64Decode

Decodes a string from Base64 format (see also base64Encode) to an unencoded unicode string.

base64Decode(str [, fromCharset]) -> String
  • str Base64 encoded string
  • fromCharset Use this charset to decode base64 encoded string to unicode

mimeWordEncode

Encodes a string to a mime word.

mimeWordEncode(str[, mimeWordEncoding[, fromCharset]]) -> String
  • str - String or Uint8Array to be encoded
  • mimeWordEncoding - Encoding for the mime word, either Q or B (default is 'Q')
  • fromCharset - If the first parameter is a typed array, use this charset to decode the value to unicode before encoding

mimeWordsEncode

Encodes non ascii sequences in a string to mime words.

mimeWordsEncode(str[, mimeWordEncoding[, fromCharset]]) -> String
  • str - String or Uint8Array to be encoded
  • mimeWordEncoding - Encoding for the mime word, either Q or B (default is 'Q')
  • fromCharset - If the first parameter is a typed array, use this charset to decode the value to unicode before encoding

mimeWordDecode

Decodes a complete mime word encoded string

mimeWordDecode(str) -> String
  • str - String to be decoded. Mime words have charset information included so need to specify it here

mimeWordsDecode

Decodes a string that might include one or several mime words. If no mime words are found from the string, the original string is returned

mimeWordsDecode(str) -> String
  • str - String to be decoded

headerLineEncode

Encodes and folds a header line for a MIME message header. Shorthand for mimeWordsEncode + foldLines.

headerLineEncode(key, value[, fromCharset])
  • key - Key name, will not be encoded
  • value - Value to be encoded
  • fromCharset - If the value parameter is a typed array, use this charset to decode the value to unicode before encoding

headerLinesDecode

Parses a block of header lines. Does not decode mime words as every header might have its own rules (eg. formatted email addresses and such).

Return value is an object of headers, where header keys are object keys. NB! Several values with the same key make up an array of values for the same key.

headerLinesDecode(headers) -> Object
  • headers - Headers string

parseHeaderValue

Parses a header value with key=value arguments into a structured object. Useful when dealing with content-type and such.

parseHeaderValue(valueString) -> Object
  • valueString - a header value without the key

Example

parseHeaderValue('content-type: text/plain; CHARSET="UTF-8"');

Outputs

{
    "value": "text/plain",
    "params": {
        "charset": "UTF-8"
    }
}

License

The MIT License

Copyright (c) 2013 Andris Reinman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.```

版本与发布记录

@gooddata/emailjs-mime-codec-new 共发布 3 个版本,首次发布于 2025/08/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.2latest2025/08/191.2 年前
3.0.12025/08/191.2 年前
3.0.02025/08/191.2 年前

关于 @gooddata/emailjs-mime-codec-new 的常见问题

@gooddata/emailjs-mime-codec-new 是什么?

Encode and decode quoted printable and base64 strings

如何安装 @gooddata/emailjs-mime-codec-new?

在项目目录运行 npm install @gooddata/emailjs-mime-codec-new,或使用 pnpm add / yarn add / bun add。

@gooddata/emailjs-mime-codec-new 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/gooddata__emailjs-mime-codec-new 是否存在。

@gooddata/emailjs-mime-codec-new 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@gooddata/emailjs-mime-codec-new 可以商用吗?

@gooddata/emailjs-mime-codec-new 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gooddata/emailjs-mime-codec-new 的下载量有多少?

根据 npm 官方下载统计,@gooddata/emailjs-mime-codec-new 在 2026/10/17 – 2026/11/15 这 30 天内被下载 27,986 次,日均约 933 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gooddata/emailjs-mime-codec-new 还在维护吗?

最新版本 3.0.2 发布于 2025/08/19(1.2 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/08/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。