Skip to content

Instantly share code, notes, and snippets.

View miladd3's full-sized avatar
🥒

Milad Dehghan miladd3

🥒
View GitHub Profile
@miladd3
miladd3 / mockHttp.js
Created April 17, 2023 14:39
mock http calls with payload
/**
* for mocking api with a timeout to test loadings
*
* @example
*
* const someEvent = async () => {
* try {
* await mock({mockedKey: '' } ,true, 1000);
* await mock({mockedKey: '' });
@function strip-unit($num) {
@return $num / ($num * 0 + 1);
}
@function convert-to-rem($value, $base-value: $rem-base) {
$value: strip-unit($value) / strip-unit($base-value) * 1rem;
@if ($value == 0rem) { $value: 0; } // Turn 0rem into 0
@return $value;
}
@miladd3
miladd3 / remCalc.ts
Last active June 27, 2024 11:36
Javascript px to Rem function
/**
* Converts pixel size to rem and accepts the base as second argument. default base is 16px
*
* @param {number|string} px
* @param {number} base
* @return {string}
*/
const remCalc = (px: number | string, base: number = 16) => {
const tempPx = `${px}`.replace('px', '')
@miladd3
miladd3 / scrollTo.js
Last active January 6, 2020 12:32
Vanilla Javascript smooth scrolling with some options (uses Es6 and behavior)
/**
* Smooth scroll to element (just modern browsers)
* @param {HTMLElement|String} elm
* @param options
*
* @example scrollTo('.element img');
* @example scrollTo(document.getElementById('element'))
*/
const scrollTo = (elm, options = {
offset: 0,
@miladd3
miladd3 / PerianMonthArray.js
Last active October 5, 2019 00:47
A list of persian month names in persian لیست ماه‌های سال در یک آرایه
let mounthList = ['فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند']
let mounthListCollection = [
{value: 1,label: 'فروردین'},
{value: 2,label: 'اردیبهشت'},
{value: 3,label: 'خرداد'},
{value: 4,label: 'تیر'},
{value: 5,label: 'مرداد'},
{value: 6,label: 'شهریور'},
{value: 7,label: 'مهر'},
@miladd3
miladd3 / localstorage.js
Last active October 18, 2018 10:07
Get and set storage easily
/**
* get local storage item and return parsed object or array
*
* @param name
* @returns {any}
*/
function getStorage(name) {
try {
if (localStorage.getItem(name)) {
@miladd3
miladd3 / get-most-repeated.js
Last active September 2, 2018 06:29
Get most repeated item in a array using pure js
/**
* get most repeated item in an array with help of this article
* https://stackoverflow.com/questions/1053843/
*
* @param {Array} array
* @returns {*}
*/
var getMostRepeatedItem: function (array) {
if(array.length === 0)
@miladd3
miladd3 / toPersianNumber.js
Last active December 1, 2019 08:16
latin to Persian number pure JS function
/**
* persian number Function that get latin number and returns Persian numbers in small vanilla js function
*
* @param {string|number} v
* @returns {string}
*/
var toPersianNumber: function(v) {
var PersianNumber = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
var vString = v.toString();
@miladd3
miladd3 / font-size.scss
Last active June 19, 2018 16:16
font size in em scss loop from 1em to 4 em
/**
this snippet is handy when u need to use font sizes in em
this will compile to css like this
.fz-0-1em {
font-size: 0.1em;
}
and it will loop through to