Skip to content

Instantly share code, notes, and snippets.

View gangsthub's full-sized avatar
Creative developer

Paul Melero gangsthub

Creative developer
View GitHub Profile
@gangsthub
gangsthub / component.vue
Created April 25, 2023 19:51
Vue Props as enums
<script setup lang="ts">
enum VariantEnum {
PRIMARY = 'primary',
SECONDARY = 'secondary',
}
// Turn enums into string union types!
type TypeFromEnum<T> = T extends `${infer U}` ? U : never;
type VariantType = TypeFromEnum<VariantEnum>;
@gangsthub
gangsthub / vitest.config.mjs
Created January 21, 2023 17:31
Basic vitest config for a Nuxt project
// vitest.config.mjs
import { defineConfigWithNuxtEnv } from 'vitest-environment-nuxt/config'
export default defineConfigWithNuxtEnv({
test: {
globals: true,
},
})
@gangsthub
gangsthub / index.js
Last active May 11, 2022 15:26
JS Quiz
const quiz = {
...{ a: { b: 1, c: 3 }},
...{ a: { b: 2 }}
}
@gangsthub
gangsthub / main.vue
Created September 30, 2021 12:56
Specificity Challenge
<template>
<p id="one" class="hello">hello world</p>
</template>
<style scoped>
#one {
color: blue;
}
.hello.hello.hello.hello.hello.hello.hello.hello.hello.hello.hello.hello.hello {
@gangsthub
gangsthub / asyncOnce.js
Created July 22, 2020 15:49
Async once
/**
* Takes a generator function that can yeild async functions.
* When the wrapped generator is called again, the previous call will cancel ASAP.
* Note: it won't cancel in-flight requests made (see: AbortController)
* @param {GeneratorFunction} generator
* @see https://dev.to/chromiumdev/cancellable-async-functions-in-javascript-5gp7
* @author Sam Thorogood
* @returns {(...args: any[]) => Promise<any>}
*/
/// <reference types="jest" />
import { mount } from '@vue/test-utils'
import IntersectionComponent from './IntersectionComponent.vue'
const mountComponent = props =>
mount(IntersectionComponent, {
propsData: {
callback: jest.fn().mockImplementation(isVisible => isVisible),
...props
@gangsthub
gangsthub / line-clamp.scss
Created March 6, 2020 11:06
Truncate lines utility classes scss
// `.truncate-1-line` and `truncate-2-lines`
@each $lines in (1, 2) {
:root .truncate-#{$lines}-line#{if($lines > 1, 's', '')} {
display: -webkit-box;
overflow: hidden;
-webkit-line-clamp: $lines;
-webkit-box-orient: vertical;
}
}
@gangsthub
gangsthub / README.md
Last active July 16, 2020 15:34
Remove unwanted HTML tags from an HTML string (for security reasons)
@gangsthub
gangsthub / README.md
Last active November 27, 2020 09:14
`img-exists`
@gangsthub
gangsthub / README.md
Last active September 29, 2023 01:09
DeepClone-js: JS utility with circular replacer

DeepClone-js

Utility to clean up circular references while creating a new reference of an object performing a deep copy (as oposite to a shallow copy). Bear in mind it doesn't work with some data types: Date, Map, RegExp, Set, TypedArray...

📦 Install

npm i -S gist:0bce1161cfd2aa91ae7cad9abb42c342