Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to Typescript #39

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"presets": ["es2015"]
"presets": [
"@babel/preset-typescript",
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"corejs": "3.22"
}
]
]
}
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"root": true
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node_modules/
.vscode/settings.json
npm-debug.log
.DS_Store
package-lock.json
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's recommended to have the package-lock inside the source code


# VIM Swap Files
[._]*.s[a-v][a-z]
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": false,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based these on the way standard was formatting the code

"singleQuote": true,
"trailingComma": "none",
"printWidth": 120
}
15 changes: 4 additions & 11 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"program": "${workspaceRoot}/node_modules/ts-mocha/bin/ts-mocha",
"stopOnEntry": false,
"args": [
"./src/*-unit.js",
"--require", "babel-register", "testutils.js",
"--reporter", "spec",
"--no-timeouts"
],
"runtimeArgs": [
"--nolazy"
],
"args": ["./src/${fileBasename}", "--require", "@babel/register", "--reporter", "spec", "--no-timeouts"],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will run just the currently selected test file

"runtimeArgs": ["--nolazy"],
"sourceMaps": true
}
}
]
}
5 changes: 5 additions & 0 deletions @types/emailjs-base64.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'emailjs-base64' {
export function encode(input: string | Uint8Array): string
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since emailjs-base64 doesn't yet have type declaration, I've declared them temporarily here

export function decode(input: string, option: string): Uint8Array
export const OUTPUT_TYPED_ARRAY: string
}
24 changes: 24 additions & 0 deletions dist/charset.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Encodes an unicode string into an Uint8Array object as UTF-8
*
* @param {String} str String to be encoded
* @return {Uint8Array} UTF-8 encoded typed array
*/
export declare const encode: (str: string) => Uint8Array;
export declare const arr2str: (arr: Uint8Array) => string;
/**
* Decodes a string from Uint8Array to an unicode string using specified encoding
*
* @param {Uint8Array} buf Binary data to be decoded
* @param {String} Binary data is decoded into string using this charset
* @return {String} Decoded string
*/
export declare function decode(buf: Uint8Array, fromCharset?: string): string;
/**
* Convert a string from specific encoding to UTF-8 Uint8Array
*
* @param {String|Uint8Array} data Data to be encoded
* @param {String} Source encoding for the string (optional for data of type String)
* @return {Uint8Array} UTF-8 encoded typed array
*/
export declare const convert: (data: string | Uint8Array, fromCharset: string) => Uint8Array;
82 changes: 32 additions & 50 deletions dist/charset.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
'use strict';
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.convert = exports.arr2str = exports.encode = undefined;
exports.convert = exports.arr2str = void 0;
exports.decode = decode;

var _textEncoding = require('text-encoding');

exports.encode = void 0;
var _textEncoding = require("text-encoding");
/**
* Encodes an unicode string into an Uint8Array object as UTF-8
*
* @param {String} str String to be encoded
* @return {Uint8Array} UTF-8 encoded typed array
*/
var encode = exports.encode = function encode(str) {
var encode = function encode(str) {
return new _textEncoding.TextEncoder('UTF-8').encode(str);
};

var arr2str = exports.arr2str = function arr2str(arr) {
exports.encode = encode;
var arr2str = function arr2str(arr) {
var CHUNK_SZ = 0x8000;
var strs = [];

for (var i = 0; i < arr.length; i += CHUNK_SZ) {
strs.push(String.fromCharCode.apply(null, arr.subarray(i, i + CHUNK_SZ)));
strs.push(String.fromCharCode.apply(null, Array.from(arr.subarray(i, i + CHUNK_SZ))));
}

return strs.join('');
};

Expand All @@ -36,40 +33,31 @@ var arr2str = exports.arr2str = function arr2str(arr) {
* @param {String} Binary data is decoded into string using this charset
* @return {String} Decoded string
*/
exports.arr2str = arr2str;
function decode(buf) {
var fromCharset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf-8';

var charsets = [{ charset: normalizeCharset(fromCharset), fatal: false }, { charset: 'utf-8', fatal: true }, { charset: 'iso-8859-15', fatal: false }];

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
for (var _iterator = charsets[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _step.value,
charset = _step$value.charset,
fatal = _step$value.fatal;

try {
return new _textEncoding.TextDecoder(charset, { fatal: fatal }).decode(buf);
} catch (e) {}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
var charsets = [{
charset: normalizeCharset(fromCharset),
fatal: false
}, {
charset: 'utf-8',
fatal: true
}, {
charset: 'iso-8859-15',
fatal: false
}];
for (var _i = 0, _charsets = charsets; _i < _charsets.length; _i++) {
var _charsets$_i = _charsets[_i],
charset = _charsets$_i.charset,
fatal = _charsets$_i.fatal;
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
return new _textEncoding.TextDecoder(charset, {
fatal: fatal
}).decode(buf);
} catch (e) {
// ignore
}
}

return arr2str(buf); // all else fails, treat it as binary
}

Expand All @@ -80,27 +68,21 @@ function decode(buf) {
* @param {String} Source encoding for the string (optional for data of type String)
* @return {Uint8Array} UTF-8 encoded typed array
*/
var convert = exports.convert = function convert(data, fromCharset) {
var convert = function convert(data, fromCharset) {
return typeof data === 'string' ? encode(data) : encode(decode(data, fromCharset));
};

exports.convert = convert;
function normalizeCharset() {
var charset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'utf-8';

var match = void 0;

var match;
if (match = charset.match(/^utf[-_]?(\d+)$/i)) {
return 'UTF-' + match[1];
}

if (match = charset.match(/^win[-_]?(\d+)$/i)) {
return 'WINDOWS-' + match[1];
}

if (match = charset.match(/^latin[-_]?(\d+)$/i)) {
return 'ISO-8859-' + match[1];
}

return charset;
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9jaGFyc2V0LmpzIl0sIm5hbWVzIjpbImRlY29kZSIsImVuY29kZSIsIlRleHRFbmNvZGVyIiwic3RyIiwiYXJyMnN0ciIsIkNIVU5LX1NaIiwic3RycyIsImkiLCJhcnIiLCJsZW5ndGgiLCJwdXNoIiwiU3RyaW5nIiwiZnJvbUNoYXJDb2RlIiwiYXBwbHkiLCJzdWJhcnJheSIsImpvaW4iLCJidWYiLCJmcm9tQ2hhcnNldCIsImNoYXJzZXRzIiwiY2hhcnNldCIsIm5vcm1hbGl6ZUNoYXJzZXQiLCJmYXRhbCIsIlRleHREZWNvZGVyIiwiZSIsImNvbnZlcnQiLCJkYXRhIiwibWF0Y2giXSwibWFwcGluZ3MiOiI7Ozs7OztRQTRCZ0JBLE0sR0FBQ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Xhwb3J0IGNvbnN0IGNvbnZlcnQgPSAoZGF0YSwgZnJvbUNoYXJzZXQpID0+IHR5cGVvZiBkYXRhID09PSAnc3RyaW5nJyA/IGVuY29kZShkYXRhKSA6IGVuY29kZShkZWNvZGUoZGF0YSwgZnJvbUNoYXJzZXQpKVxuXG5mdW5jdGlvbiBub3JtYWxpemVDaGFyc2V0IChjaGFyc2V0ID0gJ3V0Zi04Jykge1xuICBsZXQgbWF0Y2hcblxuICBpZiAoKG1hdGNoID0gY2hhcnNldC5tYXRjaCgvXnV0ZlstX10/KFxcZCspJC9pKSkpIHtcbiAgICByZXR1cm4gJ1VURi0nICsgbWF0Y2hbMV1cbiAgfVxuXG4gIGlmICgobWF0Y2ggPSBjaGFyc2V0Lm1hdGNoKC9ed2luWy1fXT8oXFxkKykkL2kpKSkge1xuICAgIHJldHVybiAnV0lORE9XUy0nICsgbWF0Y2hbMV1cbiAgfVxuXG4gIGlmICgobWF0Y2ggPSBjaGFyc2V0Lm1hdGNoKC9ebGF0aW5bLV9dPyhcXGQrKSQvaSkpKSB7XG4gICAgcmV0dXJuICdJU08tODg1OS0nICsgbWF0Y2hbMV1cbiAgfVxuXG4gIHJldHVybiBjaGFyc2V0XG59XG4iXX0=
}
162 changes: 162 additions & 0 deletions dist/mimecodec.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import { encode, decode, convert } from './charset';
/**
* Encodes all non printable and non ascii bytes to =XX form, where XX is the
* byte value in hex. This function does not convert linebreaks etc. it
* only escapes character sequences
*
* @param {String|Uint8Array} data Either a string or an Uint8Array
* @param {String} [fromCharset='UTF-8'] Source encoding
* @return {String} Mime encoded string
*/
export declare function mimeEncode(data?: string | Uint8Array, fromCharset?: string): string;
/**
* Decodes mime encoded string to an unicode string
*
* @param {String} str Mime encoded string
* @param {String} [fromCharset='UTF-8'] Source encoding
* @return {String} Decoded unicode string
*/
export declare function mimeDecode(str?: string, fromCharset?: string): string;
/**
* Encodes a string or an typed array of given charset into unicode
* base64 string. Also adds line breaks
*
* @param {String|Uint8Array} data String or typed array to be base64 encoded
* @param {String} Initial charset, e.g. 'binary'. Defaults to 'UTF-8'
* @return {String} Base64 encoded string
*/
export declare function base64Encode(data: string | Uint8Array, fromCharset?: string): string;
/**
* Decodes a base64 string of any charset into an unicode string
*
* @param {String} str Base64 encoded string
* @param {String} [fromCharset='UTF-8'] Original charset of the base64 encoded string
* @return {String} Decoded unicode string
*/
export declare function base64Decode(str: string, fromCharset?: string): string;
/**
* Encodes a string or an Uint8Array into a quoted printable encoding
* This is almost the same as mimeEncode, except line breaks will be changed
* as well to ensure that the lines are never longer than allowed length
*
* @param {String|Uint8Array} data String or an Uint8Array to mime encode
* @param {String} [fromCharset='UTF-8'] Original charset of the string
* @return {String} Mime encoded string
*/
export declare function quotedPrintableEncode(data?: string | Uint8Array, fromCharset?: string): string;
/**
* Decodes a string from a quoted printable encoding. This is almost the
* same as mimeDecode, except line breaks will be changed as well
*
* @param {String} str Mime encoded string to decode
* @param {String} [fromCharset='UTF-8'] Original charset of the string
* @return {String} Mime decoded string
*/
export declare function quotedPrintableDecode(str?: string, fromCharset?: string): string;
/**
* Encodes a string or an Uint8Array to an UTF-8 MIME Word
* https://tools.ietf.org/html/rfc2047
*
* @param {String|Uint8Array} data String to be encoded
* @param {String} mimeWordEncoding='Q' Encoding for the mime word, either Q or B
* @param {String} [fromCharset='UTF-8'] Source sharacter set
* @return {String} Single or several mime words joined together
*/
export declare function mimeWordEncode(data: string | Uint8Array, mimeWordEncoding?: string, fromCharset?: string): string;
/**
* Finds word sequences with non ascii text and converts these to mime words
*
* @param {String|Uint8Array} data String to be encoded
* @param {String} mimeWordEncoding='Q' Encoding for the mime word, either Q or B
* @param {String} [fromCharset='UTF-8'] Source sharacter set
* @return {String} String with possible mime words
*/
export declare function mimeWordsEncode(data?: string | Uint8Array, mimeWordEncoding?: string, fromCharset?: string): string;
/**
* Decode a complete mime word encoded string
*
* @param {String} str Mime word encoded string
* @return {String} Decoded unicode string
*/
export declare function mimeWordDecode(str?: string): string;
/**
* Decode a string that might include one or several mime words
*
* @param {String} str String including some mime words that will be encoded
* @return {String} Decoded unicode string
*/
export declare function mimeWordsDecode(str?: string): string;
/**
* Folds long lines, useful for folding header lines (afterSpace=false) and
* flowed text (afterSpace=true)
*
* @param {String} str String to be folded
* @param {Boolean} afterSpace If true, leave a space in th end of a line
* @return {String} String with folded lines
*/
export declare function foldLines(str?: string, afterSpace?: boolean): string;
/**
* Encodes and folds a header line for a MIME message header.
* Shorthand for mimeWordsEncode + foldLines
*
* @param {String} key Key name, will not be encoded
* @param {String|Uint8Array} value Value to be encoded
* @param {String} [fromCharset='UTF-8'] Character set of the value
* @return {String} encoded and folded header line
*/
export declare function headerLineEncode(key: string, value: string | Uint8Array, fromCharset?: string): string;
/**
* The result is not mime word decoded, you need to do your own decoding based
* on the rules for the specific header key
*
* @param {String} headerLine Single header line, might include linebreaks as well if folded
* @return {Object} And object of {key, value}
*/
export declare function headerLineDecode(headerLine?: string): {
key: string;
value: string;
};
/**
* 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)
*
* @param {String} headers Headers string
* @return {Object} An object of headers, where header keys are object keys. NB! Several values with the same key make up an Array
*/
export declare function headerLinesDecode(headers: string): Record<string, string | string[]>;
/**
* Parses a header value with key=value arguments into a structured
* object.
*
* parseHeaderValue('content-type: text/plain; CHARSET='UTF-8'') ->
* {
* 'value': 'text/plain',
* 'params': {
* 'charset': 'UTF-8'
* }
* }
*
* @param {String} str Header value
* @return {Object} Header value as a parsed structure
*/
export declare function parseHeaderValue(str: string): {
value: string | false;
params: Record<string, string>;
};
/**
* Encodes a string or an Uint8Array to an UTF-8 Parameter Value Continuation encoding (rfc2231)
* Useful for splitting long parameter values.
*
* For example
* title="unicode string"
* becomes
* title*0*="utf-8''unicode"
* title*1*="%20string"
*
* @param {String|Uint8Array} data String to be encoded
* @param {Number} [maxLength=50] Max length for generated chunks
* @param {String} [fromCharset='UTF-8'] Source sharacter set
* @return {Array} A list of encoded keys and headers
*/
export declare function continuationEncode(key: string | Uint8Array, data: string, maxLength: number, fromCharset?: string): Array<Record<string, unknown>>;
export { decode, encode, convert };
Loading