This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import _ from "lodash" | |
| import { formatBytes } from "./format" // https://gist.github.com/neysidev/71d6100023c4359a5cff256f2601c333 | |
| const openBrowseWindow = ({ | |
| accept = [], | |
| multiple = false, | |
| onChange = () => {}, | |
| }) => { | |
| // Initialize the file input | |
| const input = document.createElement("input") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require("fs") | |
| fs.readFile("input.csv", "utf8", (err, data) => { | |
| if (err) return console.log(err) | |
| const content = [] | |
| data.split("\n").forEach(line => { | |
| content.push(line.split(",")) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function discountPrice(discount: number, total: number): string { | |
| const percentage = (discount / 100) * total | |
| return (total - percentage).toLocaleString() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Calculate percentage | |
| * | |
| * @param {number} percent - The percentage to be converted to a decimal | |
| * @param {number} total - total number of items | |
| * | |
| * @example (50 / 100) * 300 => 150 | |
| * @returns {number} percentage value | |
| */ | |
| function percentage(percent: number, total: number): number { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function hasNetwork(): boolean { | |
| return navigator.onLine | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function changeMode() { | |
| if (!localStorage || !document) return | |
| if ( | |
| localStorage.theme === "dark" || | |
| (!("theme" in localStorage) && | |
| window.matchMedia("(prefers-color-scheme: dark)").matches) | |
| ) { | |
| document.documentElement.classList.add("dark") | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function arrayToCsv(data) { | |
| return data | |
| .map( | |
| row => | |
| row | |
| .map(String) // convert every value to String | |
| .map(v => v.replaceAll('"', '""')) // escape double colons | |
| .map(v => `"${v}"`) // quote it | |
| .join(",") // comma-separated | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function classNames(...classes) { | |
| return classes.filter(Boolean).join(" ") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function downloadFile(data, name) { | |
| const blob = new Blob([data], { type: "octet-stream" }) | |
| const href = URL.createObjectURL(blob) | |
| const linkTag = Object.assign(document.createElement("a"), { | |
| href, | |
| hidden: true, | |
| download: name, | |
| }) |
NewerOlder