[qrcode-svg] Add documentation, change test's import

This commit adds documentation for most of the remaining things in the definition. It also changes the way the class is imported in the test, as requested by @plantain-00. This also removes the rule override in the local `tslint.json` file, to only include the extends prop. This also removes the `typeNumber` prop from options, as it doesn't actually seem to do anything in the module (it's not referenced from the options object and is just calculated during QR code creation). This also fixes a mixture of whitespace types.
This commit is contained in:
Ferreira, Eric (ef183v)
2019-04-04 16:14:15 -04:00
parent f4d1db5ee8
commit 0fcf5ec019
3 changed files with 62 additions and 27 deletions
+57 -18
View File
@@ -3,27 +3,45 @@
// Definitions by: Eric Ferreira <https://github.com/ericbf>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Generate an svg QR code easily with this class. Just instatiate an instance
* with one of the constructors, then either generate the QR code svg as a
* string with `.svg(...)` or save it to a file with `.save(...)`.
*/
declare class QRCode {
constructor(content: string);
constructor(options: QRCode.Options);
/**
* Create a QRCode with the default options and the passed content.
* @param content The content to encode in the QRCode.
*/
constructor(content: string);
/**
* Create a QRCode by specifying its options. Any values not passed in the
* options object will be inferred as the defaults.
* @param options The options with which to create the QRCode.
*/
// tslint:disable-next-line:unified-signatures
constructor(options: QRCode.Options);
/** The raw model of this QRCode. */
qrcode: QRCode.Model;
/** The options that were used to create this QRCode. */
options: QRCode.Options;
/**
* Generates QR Code as SVG image
* @param opt Set the container. Defaults to `{ container: "svg" }`.
* @return The svg string.
*/
svg(opt?: {
container: "svg" | "g" | "none"
}): string;
/**
* Writes QR Code image to a file. Requires `fs`.
* @param file The filename to write to
* @param callback The callback that will be called, possibly with an error, when done.
*/
save(file: string, callback: (error?: Error) => void): void;
/**
* Generates an SVG image of this QRCode
* @param opt Set the container. Defaults to `{ container: "svg" }`.
* @return The svg string.
*/
svg(opt?: {
container: "svg" | "g" | "none"
}): string;
/**
* Writes this QRCode to a file. Requires `fs`.
* @param file The filename to write to
* @param callback The callback that will be called, possibly with an error, when done.
*/
save(file: string, callback: (error?: Error) => void): void;
}
declare namespace QRCode {
@@ -42,25 +60,46 @@ declare namespace QRCode {
padding?: number;
/** Default is `256`. */
width?: number;
/** Default is `4`. */
typeNumber?: number;
}
interface Model {
/**
* This QRCode's data matrix. A square, two-dimensional boolean array
* of `moduleCount` x `moduleCount` size. True in a given slot means
* that spot is filled in in the QRCode visualization.
*/
modules: boolean[][];
/** The calculated type number for this QRCode. */
typeNumber: number;
/** The numerical error correction level for this QRCode. */
errorCorrectLevel: number;
/** The width/length of this QRCode's modules matrix. */
moduleCount: number;
/** The cache used to store data during the creation of this QRCode. */
dataCache: number[] | null;
/** A list of the data added to this QRCode. */
dataList: Array<{
data: string;
mode: number;
parsedData: number[];
}>;
/**
* Queue data up to be added to this QRCode. `make` needs to be called
* to actually generate the QRCode from the data.
* @param data The data to queue up in this QRCode.
*/
addData(data: string): void;
/**
* Whether a given coordinate is filled in in this QRCode's matrix.
* @param row The row to check.
* @param col The column to check.
* @return True if the coordinate is filled in, false otherwise.
*/
isDark(row: number, col: number): boolean;
/** Returns the length/width of this QRCode's matrix. */
getModuleCount(): number;
/** Generate this QRCode's matrix from the queued data. */
make(): void;
}
}
+4 -5
View File
@@ -1,19 +1,18 @@
import * as QRCode from "qrcode-svg";
import QRCode = require("qrcode-svg");
const qrCode = new QRCode(`sample-data`);
const assert = (result: boolean, messagePrefix: string, successMessage: string, errorMessage: string) => {
if (result) {
console.log(`${messagePrefix} ${successMessage}`);
console.log(`[qrcode-svg] ${messagePrefix} ${successMessage}`);
} else {
console.error(`${messagePrefix} ${errorMessage}`);
console.error(`[qrcode-svg] ${messagePrefix} ${errorMessage}`);
}
};
assert(qrCode.options.padding === 4, "Default value for padding", "matches expected.", "does not match expected.");
assert(qrCode.options.width === 256, "Default value for width", "matches expected.", "does not match expected.");
assert(qrCode.options.height === 256, "Default value for height", "matches expected.", "does not match expected.");
assert(qrCode.options.typeNumber === 4, "Default value for typeNumber", "matches expected.", "does not match expected.");
assert(qrCode.options.background === "#ffffff", "Default value for background", "matches expected.", "does not match expected.");
assert(qrCode.options.color === "#000000", "Default value for color", "matches expected.", "does not match expected.");
@@ -21,4 +20,4 @@ assert(Array.isArray(qrCode.qrcode.modules) &&
qrCode.qrcode.modules.length === 0 ||
Array.isArray(qrCode.qrcode.modules[0]), "Modules in qrcode is", "a two-dimensional array", "not a two-dimensional array");
assert(typeof qrCode.svg() === "string", "QRCode", "generated an svg string", "did not generate an svg string");
assert(typeof qrCode.svg() === "string", "QRCode object", "generated an svg string", "did not generate an svg string");
+1 -4
View File
@@ -1,6 +1,3 @@
{
"extends": "dtslint/dt.json",
"rules": {
"unified-signatures": false
}
"extends": "dtslint/dt.json"
}