@yevhen_d/everyday-helpers
Version:
A list of useful functions helpers for what ever project you build
72 lines (46 loc) • 2.05 kB
Markdown
This npm package provides a set of convenient filter functions for formatting and processing data. You can use these functions to format file names, file sizes, generate file URLs, and remove protocols from URLs.
To install this package, you can use npm or yarn:
```sh
npm i @yevhen_d/everyday-helpers
yarn add @yevhen_d/everyday-helpers
```
Use the `formatFileNameFilter` function to format a file name by removing the file extension.
```javascript
import { formatFileNameFilter } from "@yevhen_d/everyday-helpers";
const fileName = "example.txt";
const formattedName = formatFileNameFilter(fileName);
console.log(formattedName); // Output: 'example'
```
Use the `formatFileSizeFilter` function to format a file size in bytes into a human-readable format with appropriate suffixes.
```javascript
import { formatFileSizeFilter } from "@yevhen_d/everyday-helpers";
const fileSizeInBytes = 1024; // 1 KB
const formattedSize = formatFileSizeFilter(fileSizeInBytes);
console.log(formattedSize); // Output: '1 KB'
```
Use the `generateFileUrlFilter` function to generate a URL for a file object.
```javascript
import { generateFileUrlFilter } from "@yevhen_d/everyday-helpers";
const file = { name: "example.jpg" };
const fileUrl = generateFileUrlFilter(file);
console.log(fileUrl); // Output: 'blob:...'
```
Use the `removeProtocolFilter` function to remove the protocol (e.g., 'http:', 'https:') from a URL
```javascript
import { removeProtocolFilter } from "@yevhen_d/everyday-helpers";
const url = "https://example.com";
const urlWithoutProtocol = removeProtocolFilter(url);
console.log(urlWithoutProtocol); // Output: 'example.com'
```
This package is open-source and available under the MIT License. See the LICENSE file for details.
If you encounter any issues or have questions, please create an issue in the GitHub repository.