本文整理汇总了TypeScript中file-saver.saveAs函数的典型用法代码示例。如果您正苦于以下问题:TypeScript saveAs函数的具体用法?TypeScript saveAs怎么用?TypeScript saveAs使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了saveAs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: if
return this.betterdb.getExcel(loggedin).subscribe(data => {
//console.log(`downloading data`)
const content = data.headers.get("content-disposition")
const blob = data.body
if(content && blob){
const filename = content.split(" ")[1].split("=")[1]
FileSaver.saveAs(blob, filename, true)
} else if(blob) {
this.snackBar.openFromComponent(ToastComponent, { data: { message: "wrong filename, will not verify", level: "warning"}})
FileSaver.saveAs(blob, "bets.xlsx", true)
} else {
this.snackBar.openFromComponent(ToastComponent, { data: { message: "could not download excel", level: "error"}})
}
},
示例2: download
download(name?: string) {
var isFileSaverSupported = false;
try {
isFileSaverSupported = !!new Blob();
} catch (e) {
alert("blob not supported");
}
name = (name === undefined)? "trial.svg" : name;
let gnode: any = this.g.node()
var bbox = gnode.getBBox();
var width = this.svg.attr("width"), height = this.svg.attr("height");
this.g.attr("transform", "translate(" + (-bbox.x + 5) +", " +(-bbox.y + 5) +")");
let svgNode: any = this.svg
.attr("title", "Trial")
.attr("version", 1.1)
.attr("width", bbox.width + 10)
.attr("height", bbox.height + 10)
.attr("xmlns", "http://www.w3.org/2000/svg")
.node();
var html = svgNode.parentNode.innerHTML;
html = '<svg xmlns:xlink="http://www.w3.org/1999/xlink" ' + html.slice(4);
this.svg
.attr("width", width)
.attr("height", height);
this.g.attr("transform", this.transform);
if (isFileSaverSupported) {
var blob = new Blob([html], {type: "image/svg+xml"});
fs.saveAs(blob, name);
}
}
示例3: exportASM
/**
* Compile current document and export assembly code
*/
exportASM() {
let source = this.currentDocument.editor.content;
let asm = Util.bench('compile', () => this._compiler.compile(source));
let blob = new Blob([asm], { type: 'text/plain;charset=utf-8' });
saveAs(blob, 'Untitled.asm');
}
示例4: saveAs
.then((blob) => {
saveAs(blob, `${this.project.name}-${Date.now()}.zip`);
});
示例5: gpxExport
/**
* Export LatLng coordinates as a GPX file
*
* Stolen from here:
* https://github.com/mstock/osrm-frontend/blob/7bcb1b3587fb502c016daa61eae5270bca6b90bf/src/tools.js
*
* @param {LatLng[]} coordinates
*/
export default function gpxExport(coordinates) {
var trackPoints = coordinates.map(function(coordinate) {
return {
'$lat': coordinate.lat,
'$lon': coordinate.lng
};
});
var gpx = {
'gpx': {
'$xmlns': 'http://www.topografix.com/GPX/1/1',
'$xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'$xsi:schemaLocation': 'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd',
'$version': '1.1',
'trk': {
'trkseg': {
'trkpt': trackPoints
}
}
}
};
var gpxData = JXON.stringify(gpx);
var blob = new Blob(['<?xml version="1.0" encoding="utf-8"?>', '\n', gpxData], {
type: 'application/gpx+xml;charset=utf-8'
});
saveAs(blob, 'route.gpx');
}
示例6: ensureRendered
ensureRendered(() => {
let rootNode = document.getElementById('nbdime-root')!;
let content = rootNode.outerHTML;
// Strip hover text of CM ellipses
content = content.replace(/title="Identical text collapsed. Click to expand."/g, '');
let blob = new Blob([prefix + content + postfix], {type: 'text/html;charset=utf-8'});
saveAs(blob, 'diff.html');
});
示例7: saveFile
/**
* Saves a file
* @param file
* @param filename
* @param mimeType an optional mime type
*/
public saveFile(file: BlobPart, filename: string, mimeType?: string): void {
const options: BlobPropertyBag = {};
if (mimeType) {
options.type = mimeType;
}
const blob = new Blob([file], options);
saveAs(blob, filename, { autoBOM: true });
// autoBOM = automatic byte-order-mark
}
示例8: serveDownload
/**
* Create a browser file download from the given object.
* It will be served as json file.
* @param {Object} data
* @param {string} filename
*/
private serveDownload(data: object, filename: string) {
fs.saveAs(
new Blob(
[JSON.stringify(data)],
{type: 'application/json'}
),
filename + '.json'
);
}
示例9: Blob
this.documentService.obtainReport(this.document).subscribe((res: Response) => {
const contentDisposition = res.headers.get('Content-Disposition');
let filename = this.document.documentId + '.pdf';
if (contentDisposition) {
filename = res.headers.get('Content-Disposition').match(/filename=(.*)/)[1];
}
const file = new Blob([res.blob()], { type: res.headers.get('Content-Type') });
saveAs(file, filename);
});
示例10: exportSID
/**
* Compile current document and export to .sid
*/
exportSID() {
let source = this.currentDocument.editor.content;
let asm = Util.bench('compile', () => this._compiler.compile(source));
let {objectCode} = Util.bench('assemble', () => this._assembler.assemble(asm));
let sidData = Uint8Array.from(objectCode);
let blob = new Blob([sidData], { type: 'application/octet-binary' });
saveAs(blob, 'Untitled.sid');
}
示例11: downloadString
export function downloadString(
fileContents: string,
filepath: string,
contentType: string
) {
const filename = filepath.split("/").pop();
const blob = new Blob([fileContents], { type: contentType });
// NOTE: There is no callback for this, we have to rely on the browser
// to do this well, so we assume it worked
FileSaver.saveAs(blob, filename);
}
示例12: export
export() {
const data = this.expenses.data;
// console.log(data);
const json = JSON.stringify(data, null, '\t');
const blob = new Blob([json], {
type: 'application/json;charset=utf-8'
});
const filename = 'umsaetze-' + Date.today().toString('yyyy-MM-dd') + '.json';
// console.log(filename);
saveAs(blob, filename);
}
示例13: exportPlayer
/**
* Compile current document and export player program
*/
exportPlayer() {
let source = this.currentDocument.editor.content;
let asm = Util.bench('compile', () => {
let compiler = new Compiler({ player: true });
return compiler.compile(source);
});
let {objectCode} = Util.bench('assemble', () => this._assembler.assemble(asm));
let prgData = Uint8Array.from(objectCode);
let blob = new Blob([prgData], { type: 'application/octet-binary' });
saveAs(blob, 'Untitled.prg');
}
示例14: saveEmbeddedScript
saveEmbeddedScript(templateHtml: string) {
const html = JSON.stringify(`${TPL_CSS}${templateHtml}`);
const script = `(function(w, d, b) {
var tpl = ${html};
d.addEventListener('DOMContentLoaded', function() {
var block = document.createElement('div');
block.innerHTML = tpl;
d.body.appendChild(block);
});})(window, document);`;
const blob = new Blob([script], {type: 'text/javascript;charset=utf-8'});
FileSaver.saveAs(blob, 'poptin-embedded.js');
}
示例15: exportTemplate
exportTemplate() {
let templateData = this.templateService.templateData;
let blob = new Blob([templateData], { type: 'text/json;charset=utf-8' });
saveAs(blob, 'template.json');
}