Skip to content

Instantly share code, notes, and snippets.

View uriannrima's full-sized avatar

Luciano Lima uriannrima

  • Lisbon, Portugal
View GitHub Profile
@uriannrima
uriannrima / mock.msw.spec.js
Created May 20, 2021 10:36
Jest - Expectation using MSW
it('should post a body correctly', async () => {
expect.extend({
toHaveBeenCalledWithBody(mockFn, expectedBody) {
const {
mock: {
calls: [call],
},
} = mockFn;
let [{ body }] = call;
@uriannrima
uriannrima / useForm.hook.ts
Created November 3, 2019 23:40
useForm Vue Composition API (Hook) using useFormik as reference.
/* eslint-disable @typescript-eslint/no-non-null-assertion*/
import _set from 'lodash.set';
import _get from 'lodash.get';
import { reactive, computed, watch } from '@vue/composition-api';
import { ObjectSchema } from 'yup';
export const isObject = (obj: object) => obj !== null && typeof obj === 'object';
export const toSpreadable = <FieldValueType>({
@uriannrima
uriannrima / main.js
Last active March 28, 2019 14:06
Small example of using Ajv and JSONSchema to validate JSON model.
// Common schema.
const defSchema = {
$id: "http://my-domain.com/schemas/defs.json",
definitions: {
URL: {
type: "string",
format: "uri",
pattern: "^(https?|wss?|ftp)://"
}
}
@uriannrima
uriannrima / shims-router.d.ts
Created March 16, 2019 01:09
Vue router shims to allow Next router location
import Vue from 'vue'
import { RawLocation } from 'vue-router'
declare module 'vue-router' {
interface Next<T extends Vue = Vue> {
(to?: RawLocation | false | ((vm: T) => any) | void): void
}
}
@uriannrima
uriannrima / route.ts
Last active March 16, 2019 01:08
Automatic router registration per page
import { RouteConfig } from 'vue-router'
import { Home } from './index';
export const routes: RouteConfig[] = [
{
name: 'home',
path: '/home',
component: Home
},
{
@uriannrima
uriannrima / global-components.ts
Created March 16, 2019 01:06
Vue global components registration
import Vue from 'vue'
import { upperFirstLetter } from './utils/string.extensions'
/** List all files from folder name. */
let requireComponent = require.context(
'./components',
// Consider subfolders?
true,
// The regular expression used to match base component filenames
@uriannrima
uriannrima / vue.json
Last active March 16, 2019 01:12
Vue typescript component scaffolding (snippet)
{
"Scaffold Typescript Vue Component": {
"prefix": "tscaffold",
"body": [
"<template>",
"",
"</template>",
"",
"<script lang=\"ts\">",
"import Vue from 'vue'",
<template>
<div class="Sandbox">
<div>
<span>Default:</span>
<themed-button>Main</themed-button>
<themed-button primary>Primary</themed-button>
<span>Themed:</span>
<theme-provider :theme="coloredTheme">
<themed-button @click="$emit('main-button')">Main</themed-button>
<themed-button primary
@uriannrima
uriannrima / Description.vue.js
Last active October 9, 2019 18:23
Mixin factory to create components with it's own vuex store module.
<template>
<div>
<div class="black-box rounded h-md-up">
<div>
<label>Description</label>
<minimize-button :minimize.sync="minimize"></minimize-button>
</div>
</div>
<div class="description-component" v-show="!minimize">
<div class="horizontal-container">