How to use protocolify - 2 common examples

To help you get started, we’ve selected a few protocolify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / pageres / lib / index.js View on Github external
create(uri: string, size: string, options: Options) {
		const sizes = size.split('x');
		const stream = screenshotStream(protocolify(uri), size, options);

		// Coercing to string here to please Flow
		// TODO: Should fix the Flow type so this isn't necessary
		const filename = template(`${String(options.filename)}.${String(options.format)}`);

		let hash = url.parse(uri).hash || '';

		if (path.isAbsolute(uri)) {
			uri = path.basename(uri);
		}

		// Strip empty hash fragments: `#` `#/` `#!/`
		if (/^#!?\/?$/.test(hash)) {
			hash = '';
		}
github sindresorhus / pageres / lib / util.js View on Github external
export function create(uri, size, options) {
	const sizes = size.split('x');
	const stream = screenshotStream(protocolify(uri), size, options);
	const filename = template(`${options.filename}.${options.format}`);

	if (path.isAbsolute(uri)) {
		uri = path.basename(uri);
	}

	stream.filename = filename({
		crop: options.crop ? '-cropped' : '',
		date: easydate('Y-M-d'),
		time: easydate('h-m-s'),
		size,
		width: sizes[0],
		height: sizes[1],
		url: filenamifyUrl(uri)
	});

protocolify

Prepend `https://` to humanized URLs like `sindresorhus.com` and `file://` to file paths

MIT
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis

Popular protocolify functions