parseAssetId.js 916 B

12345678910111213141516171819
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var example = 'image-Tb9Ew8CXIwaY6R1kjMvI0uRR-2000x3000-jpg';
  4. function parseAssetId(ref) {
  5. var _a = ref.split('-'), id = _a[1], dimensionString = _a[2], format = _a[3];
  6. if (!id || !dimensionString || !format) {
  7. throw new Error("Malformed asset _ref '".concat(ref, "'. Expected an id like \"").concat(example, "\"."));
  8. }
  9. var _b = dimensionString.split('x'), imgWidthStr = _b[0], imgHeightStr = _b[1];
  10. var width = +imgWidthStr;
  11. var height = +imgHeightStr;
  12. var isValidAssetId = isFinite(width) && isFinite(height);
  13. if (!isValidAssetId) {
  14. throw new Error("Malformed asset _ref '".concat(ref, "'. Expected an id like \"").concat(example, "\"."));
  15. }
  16. return { id: id, width: width, height: height, format: format };
  17. }
  18. exports.default = parseAssetId;
  19. //# sourceMappingURL=parseAssetId.js.map