mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add types for libqp (#43437)
ts enable the libqp functions Signed-off-by: Chris. Webster <chris@webstech.net>
This commit is contained in:
parent
f42b6f9971
commit
30b7468458
31
types/libqp/index.d.ts
vendored
Normal file
31
types/libqp/index.d.ts
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
// Type definitions for libqp 1.1
|
||||
// Project: https://github.com/nodemailer/libqp
|
||||
// Definitions by: Chris. Webster <https://github.com/webstech>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
import { Transform, TransformOptions } from "stream";
|
||||
|
||||
/** Encodes a Buffer or String into a Quoted-Printable encoded string */
|
||||
export function encode(buffer: string | Buffer): string;
|
||||
|
||||
/** Decodes a Quoted-Printable encoded string to a Buffer object */
|
||||
export function decode(input: string): Buffer;
|
||||
|
||||
/** Adds soft line breaks to a Quoted-Printable string */
|
||||
export function wrap(str: string, lineLength?: number): string;
|
||||
|
||||
/** Extend options to add lineLength */
|
||||
export interface EncoderOptions extends TransformOptions {
|
||||
lineLength?: number;
|
||||
}
|
||||
|
||||
/** Create a transform stream for encoding data to Quoted-Printable encoding */
|
||||
export class Encoder extends Transform {
|
||||
constructor(opts?: EncoderOptions);
|
||||
}
|
||||
|
||||
/** Create a transform stream for decoding Quoted-Printable encoded strings */
|
||||
export class Decoder extends Transform {
|
||||
constructor(opts?: TransformOptions);
|
||||
}
|
||||
40
types/libqp/libqp-tests.ts
Normal file
40
types/libqp/libqp-tests.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import * as libqp from "libqp";
|
||||
import { Readable, Writable } from "stream";
|
||||
|
||||
const encodeText = "jõgeva";
|
||||
const encoded = libqp.encode(encodeText);
|
||||
console.log(libqp.encode(encodeText));
|
||||
|
||||
const decodeText =
|
||||
`This string contains quoted printables for the various ranges of utf-8.
|
||||
=31=32=33=34
|
||||
two byte /=[CDcd][0-9A-Fa-f]/=c2=a9
|
||||
three byte /=[Ee][0-9A-Fa-f]/=e1=99=ad
|
||||
four byte /=[Ff][0-7]/=f0=90=8d=88
|
||||
`;
|
||||
|
||||
const body = libqp.decode(decodeText);
|
||||
|
||||
const wrapped = libqp.wrap(`abc ${encoded}`, 10);
|
||||
|
||||
const encoder = new libqp.Encoder();
|
||||
const decoder = new libqp.Decoder();
|
||||
|
||||
const buffer = Buffer.from(encodeText);
|
||||
|
||||
const readable = new Readable();
|
||||
readable._read = () => {}; // _read is required but you can noop it
|
||||
readable.push(buffer);
|
||||
readable.push(null);
|
||||
|
||||
const writable = new Writable({
|
||||
// tslint:disable-next-line: variable-name
|
||||
write(chunk, _encoding, callback) {
|
||||
console.log(chunk.toString());
|
||||
callback();
|
||||
}
|
||||
});
|
||||
|
||||
readable.pipe(encoder);
|
||||
encoder.pipe(decoder);
|
||||
decoder.pipe(writable);
|
||||
23
types/libqp/tsconfig.json
Normal file
23
types/libqp/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"libqp-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/libqp/tslint.json
Normal file
1
types/libqp/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user