Skip to content

Instantly share code, notes, and snippets.

View mrfzd's full-sized avatar

Zad (Farzad Soleimaninia) mrfzd

  • London, United Kingdom
  • 07:27 (UTC -12:00)
View GitHub Profile
https://kentcdodds.com/blog/use-ternaries-rather-than-and-and-in-jsx
@mrfzd
mrfzd / gist:872171d79f59242a677ff42351fedf6c
Created August 4, 2021 12:15
TypeScript Decorators #101
// @experimentalDecorators
console.clear();
function computeFullName() {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
// target is the class name
// propertyKey is the method name in the class
// This is the method func itself
@mrfzd
mrfzd / gist:6f2396f9204aae8250c9eaa184fcfa38
Created March 10, 2023 18:02
Generate Safe Slug strig for different purposes
const generateSafeSlugString = (s) => s?.toString().normalize('NFD').replace(/[\u0300-\u036f]/g, "") //remove diacritics
.toLowerCase()
.replace(/\s+/g, '-') //spaces to dashes
.replace(/&/g, '-and-') //ampersand to and
.replace(/[^\w\-]+/g, '') //remove non-words
.replace(/\-\-+/g, '-') //collapse multiple dashes
.replace(/^-+/, '') //trim starting dash
.replace(/-+$/, ''); //trim ending dash