update svg2png tpye (#18393)

* update svg2png tpye

* fix

* fix reference

* fix export default

* change version

* fix definitions by

* fix type

* fix lint
This commit is contained in:
scc
2017-08-24 22:07:17 +08:00
committed by Andy
parent 25ba611105
commit 76a13f1ad8
4 changed files with 49 additions and 37 deletions

View File

@@ -1,10 +1,20 @@
// Type definitions for svg2png node package
// Type definitions for svg2png 4.1
// Project: https://github.com/domenic/svg2png
// Definitions by: hans windhoff <https://github.com/hansrwindhoff>
// Definitions by: hans windhoff <https://github.com/hansrwindhoff>, songChengcheng <https://github.com/sccgithub>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function svg2png(srcFile: string, destFile: string, scale: number, cb: (err:Error) => void):void;
declare function svg2png(srcFile: string, destFile: string, cb: (err:Error) => void):void;
/// <reference types="node" />
interface opts {
fileName?: string;
width?: number;
height?: number;
url?: string;
}
declare function svg2png(sourceBuffer: Buffer, opts?: opts): Promise<Buffer>;
declare namespace svg2png {
function sync(sourceBuffer: Buffer, opts?: opts): Buffer;
}
export = svg2png;

View File

@@ -1,43 +1,43 @@
"use strict";
import svg2png = require("svg2png");
svg2png("./1.svg", "./tiger.png", err => {
import { sync as svg2pngSync } from 'svg2png';
import * as fs from 'fs';
fs.readFile("./source.svg", (err: Error, buffer: Buffer): void => {
if (err) {
console.log("didnt work");
} else {
console.log("ok");
console.log(err);
}
svg2png(buffer)
.then((buffer: Buffer) => {
fs.writeFileSync("test.png", buffer);
})
.catch((e: any) => console.error(e));
});
svg2png("./index.svg", "./dest.png", err => {
fs.readFile("./source.svg", (err: Error, buffer: Buffer): void => {
if (err) {
console.log("didnt work");
} else {
console.log("ok");
console.log(err);
}
svg2png(buffer, {
width: 200,
height: 200
})
.then((buffer: Buffer) => {
fs.writeFileSync("dest.png", buffer);
})
.catch((e: any) => console.error(e));
});
for (var i = 0.1; i < 4; i += 0.2) {
svg2png("./tiger.svg", "./tigerzoom" + i.toString() + ".png", i, err => {
if (err) {
console.log("didnt work");
} else {
console.log("ok");
}
});
svg2png("./index.svg", "./index" + i.toString() + ".png", i, err => {
if (err) {
console.log("didnt work");
} else {
console.log("ok");
}
});
}
fs.readFile("./source.svg", (err: Error, buffer: Buffer): void => {
if (err) {
console.log(err);
}
try {
const pngBuffer = svg2pngSync(buffer);
} catch (error) {
console.log(error);
}
});
console.log("done");

View File

@@ -2,8 +2,7 @@
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
@@ -20,4 +19,4 @@
"index.d.ts",
"svg2png-tests.ts"
]
}
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}