UNPKG

profile-plus

Version:

### IOS

47 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateUniqueFileName = exports.replaceLocalhostWithSiteRoot = exports.generateRandomName = void 0; const core_1 = require("@capacitor/core"); // currently use for generate function generateRandomName(format) { const timestamp = new Date().getTime(); const randomString = Math.random().toString(15).substring(7); // Generate a random string return format ? `${timestamp}_${randomString}.${format}` : `${timestamp}_${randomString}`; } exports.generateRandomName = generateRandomName; /** * Fixes the image path for Android devices during development. * Replaces 'localhost' with the appropriate site root URL. * @param croppedImage * @returns */ function replaceLocalhostWithSiteRoot(croppedImage) { let imageSrc = croppedImage; if (imageSrc && process.env.NODE_ENV !== 'production' && core_1.Capacitor.getPlatform() === 'android') { if (imageSrc.includes('localhost')) { imageSrc = imageSrc.replace(/http\:\/\/localhost\:\d+/, process.env.SITE_ROOT); } } return imageSrc; } exports.replaceLocalhostWithSiteRoot = replaceLocalhostWithSiteRoot; /** * Generates a unique file name based on the original file name. * Example: `originalName.jpg` -> `originalName_1633024800000_abcd12.jpg` * * @param originalName * @returns */ function generateUniqueFileName(originalName) { const ext = originalName.substring(originalName.lastIndexOf('.') + 1); const base = originalName.substring(0, originalName.lastIndexOf('.')); const timestamp = Date.now(); const randomStr = Math.random().toString(36).substring(2, 8); // 6-char random string return `${base}_${timestamp}_${randomStr}.${ext}`; } exports.generateUniqueFileName = generateUniqueFileName; //# sourceMappingURL=helper.js.map