Comparing version 5.0.0 to 5.0.1
@@ -48,3 +48,2 @@ /// <reference types="node" /> | ||
private _destination; | ||
private _filename; | ||
constructor(options?: Options); | ||
@@ -51,0 +50,0 @@ src(): Source[]; |
@@ -94,5 +94,3 @@ "use strict"; | ||
// TODO: Make this concurrent | ||
const screenshot = yield this.create(src.url, size, options); | ||
screenshot.filename = this._filename; | ||
this.items.push(screenshot); | ||
this.items.push(yield this.create(src.url, size, options)); | ||
} | ||
@@ -124,5 +122,3 @@ return undefined; | ||
this.sizes.push(item.item); | ||
const screenshot = yield this.create(url, item.item, options); | ||
screenshot.filename = this._filename; | ||
this.items.push(screenshot); | ||
this.items.push(yield this.create(url, item.item, options)); | ||
} | ||
@@ -138,14 +134,12 @@ }); | ||
for (const size of array_uniq_1.default(obj.sizes)) { | ||
const screenshot = yield this.create(obj.url, size, options); | ||
screenshot.filename = this._filename; | ||
this.items.push(screenshot); | ||
this.items.push(yield this.create(obj.url, size, options)); | ||
} | ||
}); | ||
} | ||
save(streams) { | ||
save(screenshots) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield Promise.all(streams.map((stream) => __awaiter(this, void 0, void 0, function* () { | ||
yield Promise.all(screenshots.map((screenshot) => __awaiter(this, void 0, void 0, function* () { | ||
yield make_dir_1.default(this.dest()); | ||
const dest = path_1.default.join(this.dest(), this._filename); | ||
yield writeFile(dest, stream); | ||
const dest = path_1.default.join(this.dest(), screenshot.filename); | ||
yield writeFile(dest, screenshot); | ||
}))); | ||
@@ -155,46 +149,49 @@ }); | ||
create(uri, size, options) { | ||
const basename = path_1.default.isAbsolute(uri) ? path_1.default.basename(uri) : uri; | ||
let hash = url_1.parse(uri).hash || ''; | ||
// Strip empty hash fragments: `#` `#/` `#!/` | ||
if (/^#!?\/?$/.test(hash)) { | ||
hash = ''; | ||
} | ||
const [width, height] = size.split('x'); | ||
const filenameTemplate = lodash_template_1.default(`${options.filename}.${options.format}`); | ||
let filename = filenameTemplate({ | ||
crop: options.crop ? '-cropped' : '', | ||
date: easydate_1.default('Y-M-d'), | ||
time: easydate_1.default('h-m-s'), | ||
size, | ||
width, | ||
height, | ||
url: `${filenamify_url_1.default(basename)}${filenamify_1.default(hash)}` | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const basename = path_1.default.isAbsolute(uri) ? path_1.default.basename(uri) : uri; | ||
let hash = url_1.parse(uri).hash || ''; | ||
// Strip empty hash fragments: `#` `#/` `#!/` | ||
if (/^#!?\/?$/.test(hash)) { | ||
hash = ''; | ||
} | ||
const [width, height] = size.split('x'); | ||
const filenameTemplate = lodash_template_1.default(`${options.filename}.${options.format}`); | ||
let filename = filenameTemplate({ | ||
crop: options.crop ? '-cropped' : '', | ||
date: easydate_1.default('Y-M-d'), | ||
time: easydate_1.default('h-m-s'), | ||
size, | ||
width, | ||
height, | ||
url: `${filenamify_url_1.default(basename)}${filenamify_1.default(hash)}` | ||
}); | ||
if (options.incrementalName) { | ||
filename = unused_filename_1.default.sync(filename); | ||
} | ||
const finalOptions = { | ||
width: Number(width), | ||
height: Number(height), | ||
delay: options.delay, | ||
timeout: options.timeout, | ||
fullPage: !options.crop, | ||
styles: options.css && [options.css], | ||
scripts: options.script && [options.script], | ||
cookies: options.cookies, | ||
element: options.selector, | ||
hideElements: options.hide, | ||
scaleFactor: options.scale === undefined ? 1 : options.scale, | ||
format: options.format === 'jpg' ? 'jpeg' : 'png', | ||
userAgent: options.userAgent, | ||
headers: options.headers | ||
}; | ||
if (options.username && options.password) { | ||
finalOptions.authentication = { | ||
username: options.username, | ||
password: options.password | ||
}; | ||
} | ||
const screenshot = yield capture_website_1.default.buffer(uri, finalOptions); | ||
screenshot.filename = filename; | ||
return screenshot; | ||
}); | ||
if (options.incrementalName) { | ||
filename = unused_filename_1.default.sync(filename); | ||
} | ||
const finalOptions = { | ||
width: Number(width), | ||
height: Number(height), | ||
delay: options.delay, | ||
timeout: options.timeout, | ||
fullPage: !options.crop, | ||
styles: options.css && [options.css], | ||
scripts: options.script && [options.script], | ||
cookies: options.cookies, | ||
element: options.selector, | ||
hideElements: options.hide, | ||
scaleFactor: options.scale === undefined ? 1 : options.scale, | ||
format: options.format === 'jpg' ? 'jpeg' : 'png', | ||
userAgent: options.userAgent, | ||
headers: options.headers | ||
}; | ||
if (options.username && options.password) { | ||
finalOptions.authentication = { | ||
username: options.username, | ||
password: options.password | ||
}; | ||
} | ||
this._filename = filename; | ||
return capture_website_1.default.buffer(uri, finalOptions); | ||
} | ||
@@ -201,0 +198,0 @@ } |
{ | ||
"name": "pageres", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "Capture website screenshots", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
26116
257