UNPKG

@resk/core

Version:

An innovative TypeScript framework that empowers developers to build applications with a fully decorator-based architecture for efficient resource management. By combining the power of decorators with a resource-oriented design, DecorRes enhances code cla

67 lines (66 loc) 3.02 kB
/** * Checks if the provided string is a valid data URL. * * This function verifies that the input string is a non-null string, does not * contain the specific data URL for `.x-icon` images, and matches the * `isDataUrlRegex` regular expression for data URLs. * * The function returns `true` if the string is a valid data URL and `false` * otherwise. * * @param {string} s - The string to check for being a data URL. * @returns {boolean} - Returns `true` if the string is a valid data URL, * `false` otherwise. * * @example * // Valid data URLs * console.log(isDataUrl('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA...')); // true * console.log(isDataUrl('data:text/plain;charset=utf-8,Hello%20World!')); // true * * // Invalid data URLs * console.log(isDataUrl('data:image/x-icon;base64,...')); // false (contains x-icon) * console.log(isDataUrl('not-a-data-url')); // false * console.log(isDataUrl(null)); // false */ export declare const isDataUrl: (s: string) => boolean; /** * Checks if the provided source is a valid image source. * * This function verifies whether the input `src` is a valid image source by performing * several checks: * * 1. **Non-null String Check**: It first checks if `src` is a non-null string using the * `isNonNullString` function. * * 2. **Trim Whitespace**: The function trims any leading or trailing whitespace from the * source string to ensure accurate validation. * * 3. **Blob URL Handling**: If the source starts with `blob:http`, it removes the `blob:` * prefix for further validation. Note that `ltrim` should be defined elsewhere in your code. * * 4. **Validation Checks**: The function then checks if the modified source is: * - A valid data URL using the `isDataUrl` function. * - A string that matches common image file extensions (e.g., `.bmp`, `.jpg`, `.jpeg`, * `.png`, `.gif`, `.svg`) using a regular expression. * - A string that starts with `data:image/`, indicating it is a data URL for an image. * * The function returns `true` if any of these conditions are met, indicating that the source * is a valid image source; otherwise, it returns `false`. * * @param {any} src - The source to validate as an image source. * @returns {boolean} - Returns `true` if the source is a valid image source, * `false` otherwise. * * @example * // Valid image sources * console.log(isValidImageSrc('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA...')); // true * console.log(isValidImageSrc('https://example.com/image.jpg')); // true * console.log(isValidImageSrc('image.png')); // true (if file extension is valid) * * // Invalid image sources * console.log(isValidImageSrc(null)); // false * console.log(isValidImageSrc('')); // false * console.log(isValidImageSrc('not-a-valid-url')); // false * console.log(isValidImageSrc('blob:http://example.com/...')); // true (if valid blob URL) */ export declare const isValidImageSrc: (src: any) => any;