UNPKG

@bradgarropy/rehype-cloudinary-image-size

Version:
34 lines • 1.55 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; const getImageDimensions = (imageUrl) => __awaiter(void 0, void 0, void 0, function* () { const url = new URL(imageUrl); const pathSegments = url.pathname.split("/"); const index = pathSegments.findIndex(value => value === "bradgarropy.com"); pathSegments.splice(index, 0, "fl_getinfo"); url.pathname = pathSegments.join("/"); const response = yield fetch(url); const json = yield response.json(); const dimensions = { width: json.output.width, height: json.output.height, }; return dimensions; }); const isCloudinaryImage = (url) => { if (url.startsWith("http://res.cloudinary.com")) { return true; } if (url.startsWith("https://res.cloudinary.com")) { return true; } return false; }; export { getImageDimensions, isCloudinaryImage }; //# sourceMappingURL=cloudinary.js.map