mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 15:00:26 +00:00
Added types for identicon.js (#34286)
* added identicon.js types * instead of exporting the PNGlib and Svg class they are now declared * instead of classes interfaces are now used for PNGlib and Svg
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import Identicon, { Svg } from "identicon.js";
|
||||
|
||||
// create an identicon with only a hash and a size
|
||||
new Identicon("d3b07384d113edec49eaa6238ad5ff00", 420).toString();
|
||||
|
||||
// create an identicon with a hash and other options and get the svg
|
||||
const svg = new Identicon("d3b07384d113edec49eaa6238ad5ff00", {
|
||||
background: [255, 255, 255, 255],
|
||||
foreground: [0, 0, 0, 0],
|
||||
margin: 0.05,
|
||||
size: 64,
|
||||
format: "svg",
|
||||
}).image() as Svg;
|
||||
svg.getDump();
|
||||
// or get the base64 encoded svg
|
||||
svg.getBase64();
|
||||
Vendored
+129
@@ -0,0 +1,129 @@
|
||||
// Type definitions for identicon.js 2.3
|
||||
// Project: https://github.com/stewartlord/identicon.js
|
||||
// Definitions by: D0miH <https://github.com/D0miH>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export type Color = [number, number, number, number];
|
||||
|
||||
export interface IdenticonOptions {
|
||||
background?: Color;
|
||||
foreground?: Color;
|
||||
margin?: number;
|
||||
size?: number;
|
||||
format?: "svg" | "png";
|
||||
}
|
||||
|
||||
export interface PNGlib {
|
||||
width: number;
|
||||
height: number;
|
||||
depth: number;
|
||||
|
||||
/**
|
||||
* Returns the index of a given pixel in the image data array.
|
||||
* @param x The given x coordinate of the pixel.
|
||||
* @param y The given y coordinate of the pixel.
|
||||
*/
|
||||
index(x: number, y: number): number;
|
||||
|
||||
/**
|
||||
* Returns the image as a base64 encoded string.
|
||||
*/
|
||||
getBase64(): string;
|
||||
|
||||
/**
|
||||
* Returns the png as a string.
|
||||
*/
|
||||
getDump(): string;
|
||||
}
|
||||
|
||||
export interface Svg {
|
||||
size: number;
|
||||
foreground: Color;
|
||||
background: Color;
|
||||
rectangles: [
|
||||
{
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
color: Color;
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* Returns a string with the structure 'rgb(r, g, b, a)'.
|
||||
* @param red
|
||||
* @param green
|
||||
* @param blue
|
||||
* @param alpha
|
||||
*/
|
||||
color(red: number, green: number, blue: number, alpha: number): string;
|
||||
|
||||
/**
|
||||
* Returns the Svg as string.
|
||||
*/
|
||||
getDump(): string;
|
||||
|
||||
/**
|
||||
* Returns the Svg as a base64 encoded string.
|
||||
*/
|
||||
getBase64(): string;
|
||||
}
|
||||
|
||||
export default class Identicon {
|
||||
hash: string;
|
||||
foreground: Color;
|
||||
background: Color;
|
||||
size: number;
|
||||
format: "svg" | "png";
|
||||
margin: number;
|
||||
|
||||
constructor(hash: string, size?: number);
|
||||
constructor(hash: string, options: IdenticonOptions);
|
||||
|
||||
/**
|
||||
* Returns a new blank image as Svg or PNGlib.
|
||||
*/
|
||||
image(): Svg | PNGlib;
|
||||
|
||||
/**
|
||||
* Returns a new image as Svg or PNGlib with the identicon applied.
|
||||
*/
|
||||
render(): Svg | PNGlib;
|
||||
|
||||
/**
|
||||
* Places a rectangle at the given position with the given width, height and color in the image.
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate
|
||||
* @param w The width.
|
||||
* @param h The height.
|
||||
* @param color The color.
|
||||
* @param image The image.
|
||||
*/
|
||||
rectangle(
|
||||
x: number,
|
||||
y: number,
|
||||
w: number,
|
||||
h: number,
|
||||
color: Color,
|
||||
image: Svg | PNGlib
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Converts from hsl to rgb.
|
||||
* @param h hue
|
||||
* @param s saturation
|
||||
* @param b brightness
|
||||
*/
|
||||
hsl2rgb(h: number, s: number, b: number): [number, number, number];
|
||||
|
||||
/**
|
||||
* Returns the image data as a string.
|
||||
*/
|
||||
toString(): string;
|
||||
|
||||
/**
|
||||
* Returns true if the identicon is a Svg.
|
||||
*/
|
||||
isSvg(): boolean;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"identicon.js-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user