A collection of utility functions for image manipulation, DOM operations, and data validation.
npm install @xiping/utils
or
yarn add @xiping/utils
or
pnpm install @xiping/utils
- Image manipulation (resize, flip, rotate)
- Base64 conversion utilities
- DOM utilities
- File handling utilities
Converts an image URL to a base64 encoded string.
const result = await imageUrlToBase64('https://example.com/image.jpg');
if (result.success) {
console.log(result.data); // base64 string
}
resizeImage({ file: File, width: number, height: number }): Promise<{ success: boolean; file?: File }>
Resizes an image file to specified dimensions.
const result = await resizeImage({
file: imageFile,
width: 800,
height: 600
});
if (result.success) {
console.log(result.file); // compressed file
}
Flips an image horizontally or vertically.
const flippedImage = await flipImage(imageSource, FlipDirection.HORIZONTAL);
Rotates an image by a specified angle.
const rotatedImage = await rotateImage(imageSource, 90);
Smoothly scrolls an HTML element to its bottom.
const element = document.querySelector('.chat-container');
scrollToBottom(element);
Creates a continuous smooth scrolling effect that automatically scrolls an element up and down. Returns a function to stop the scrolling.
const element = document.querySelector('.scroll-container');
// Start auto-scrolling with 2px step
const stopScroll = autoScroll(element, 2);
// Stop scrolling when needed
stopScroll();
Converts a base64 encoded string to a Blob object.
const blob = base64ToBlob(base64String, 'image/png');
Validates if a value is a valid base64 encoded string.
const isValid = isBase64(someString, {
allowEmpty: false,
allowMime: true,
mimeRequired: false,
paddingRequired: true
});
MIT