Skip to content

Instantly share code, notes, and snippets.

View mortezasabihi's full-sized avatar
💻
Working From Home

Morteza Sabihi mortezasabihi

💻
Working From Home
View GitHub Profile
@mortezasabihi
mortezasabihi / convert-svg-to-vue-components.js
Last active April 21, 2023 11:00
A Node.js script that converts SVG files in a directory to Vue components, using the filename as the component name and replacing spaces with hyphens.
const fs = require("fs");
const path = require("path");
const prettier = require("prettier");
const { DOMParser, XMLSerializer } = require("xmldom");
const ICONS_DIRECTORY = path.join(__dirname, "icons");
const EXPORT_DIRECTORY = path.join(__dirname, "components");
fs.readdir(ICONS_DIRECTORY, function (err, files) {
if (err) {
@mortezasabihi
mortezasabihi / useApi.ts
Created August 21, 2021 06:02
Vue 3 axios composition api
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { reactive, toRefs } from 'vue';
import axios,{ AxiosRequestConfig, AxiosError, AxiosResponse } from 'axios';
export enum Status {
IDLE = 'idle',
LOADING = 'loading',
SUCCESS = 'success',
ERROR = 'error',
@mortezasabihi
mortezasabihi / useCount.js
Last active June 15, 2021 07:54
Vue 3 count composition api
import { ref } from "vue";
export default function ({ min, max, defaultValue }) {
const count = ref(defaultValue);
const increment = () => {
if (max) {
count.value < max && count.value++;
} else {
count.value++;
}
@mortezasabihi
mortezasabihi / width.js
Last active April 25, 2024 11:40
Javascript get element width without padding
const wrapper = document.querySelector('#wrapper')
const wrapperComputedStyle = window.getComputedStyle(wrapper, null)
let wrapperWidth = wrapper.clientWidth
wrapperWidth -=
parseFloat(wrapperComputedStyle.paddingLeft) +
parseFloat(wrapperComputedStyle.paddingRight)
@mortezasabihi
mortezasabihi / useQueryParams.js
Created November 29, 2020 12:25
React query string hook using URLSearchParams
import { useLocation } from "react-router-dom";
import PropTypes from "prop-types";
export default function useQueryParams(...keys) {
const location = useLocation();
const query = new URLSearchParams(location.search);
let paramObj = {};
for (let value of keys) {
@mortezasabihi
mortezasabihi / server.js
Last active November 23, 2022 13:40
NodeJS File Upload rest Api Using multer
const express = require("express");
const multer = require("multer");
const fs = require("fs");
// constant
const app = express();
const storage = multer.diskStorage({
destination: (req, file, callback) => {
const dir = "uploads/";
!fs.existsSync(dir) && fs.mkdirSync(dir);