Skip to content

Instantly share code, notes, and snippets.

View jsanchezba's full-sized avatar
🏠
Full Stack Developer

Joan jsanchezba

🏠
Full Stack Developer
  • Valencia, Spain
  • 17:44 (UTC +02:00)
View GitHub Profile
@jsanchezba
jsanchezba / toRelativeTime.ts
Created November 11, 2023 11:34
i18n toRelativeTime()
import { useI18n } from 'vue-i18n'
export default function toRelativeTime(value: Date, options?: Intl.RelativeTimeFormatOptions) {
const { locale } = useI18n()
if (!options) {
options = {
localeMatcher: 'best fit',
numeric: 'auto',
style: 'long',
@jsanchezba
jsanchezba / mongoose.ts
Created March 15, 2023 09:21
Mongoose virtual properties with CASL
import fastify from './fastify'
import mongoose from 'mongoose'
import { accessibleRecordsPlugin, accessibleFieldsPlugin } from '@casl/mongoose'
mongoose.plugin(accessibleRecordsPlugin)
mongoose.plugin(accessibleFieldsPlugin, {
getFields: (schema: Record<string, unknown>) =>
Object.keys({
...(schema as { paths: object }).paths,
...(schema as { virtuals: object }).virtuals,