-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: master
Are you sure you want to change the base?
Changes from all commits
b8ebe4e
c1cd5bc
5ce7b79
2736989
caa3925
7e6631f
a1e94b0
73efb1b
cf0614b
0200ee6
fb9776c
72c7851
c6b5301
d1ce0ac
0e330d8
acaa4ee
79bb712
901a1e2
789c313
1844739
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
} | ||
] | ||
] | ||
} |
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"semi": false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I based these on the way |
||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"printWidth": 120 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will run just the currently selected test file |
||
"runtimeArgs": ["--nolazy"], | ||
"sourceMaps": true | ||
} | ||
} | ||
] | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since |
||
export function decode(input: string, option: string): Uint8Array | ||
export const OUTPUT_TYPED_ARRAY: string | ||
} |
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; |
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 }; |
There was a problem hiding this comment.
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