Skip to content

Instantly share code, notes, and snippets.

@tiagofrancafernandes
Last active April 26, 2023 14:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagofrancafernandes/55cbe6c42c56326b181ac9c3abf1fdea to your computer and use it in GitHub Desktop.
Save tiagofrancafernandes/55cbe6c42c56326b181ac9c3abf1fdea to your computer and use it in GitHub Desktop.
dev-typescript snippets
// index.ts
export * from "./Customer";
export * from "./StringArray";
export * from "./CancellablePromise";
export interface GenericFunctionInterfaceFn {
    (params: SomeTypeOfParams, options: SomeTypeOfOptions): SomeTypeOfReturn;
}

export interface Provider<T> {
    (): Promise<T>;
}
type SitemapPriority = 0.3 | 0.5 // ...

type SitemapResource = {
    changefreq: 'daily' | 'weekly';
    defaultPriority: SitemapPriority;
}

type SitemapResources = {
    [resource: string]: SitemapResource;
}

interface SitemapConfig {
    hostname: string;
    sitemapPath: string;
    defaultLowPriority: SitemapPriority,
    resources: SitemapResources,
}

const sitemapConfig: SitemapConfig = {
    hostname: 'https://www.site.com.br/',
    sitemapPath: 'seo/',
    defaultLowPriority: 0.3,
    resources: {
        revendas: {
            changefreq: 'daily',
            defaultPriority: 1.0,
        },
        tipo: {
            changefreq: 'weekly',
            defaultPriority: 0.3,
        },
    }
}
interface MetricStorage {
    readonly startedAt: Date;
    finshedAt?: Date;
    totalOfLinks: number;
    [item: string]: any;
}

let metrics: MetricStorage = {
    startedAt: new Date(),
    totalOfLinks: 0,
};
interface Dict<T> {
    [key: string]: T | undefined;
}

interface ReadOnlyDict<T> {
    readonly [key: string]: T | undefined;
}
// src/functions/integrator/post/IntegratorPostSchema.ts
export default {
  key: "value",
  required: ['name', 'businessName']
} as const;

import IntegratorPostSchema from './post/IntegratorPostSchema';

Libs pessoais

  • libs-pessoais/_index.md

handlerResolver

// src/libs/handlerResolver.ts
export const handlerPath = (context: string): string => {
  return `${context.split(process.cwd())[1].substring(1).replace(/\\/g, '/')}`
};

// Usage
import { handlerPath } from '@libs/handlerResolver';

const handler: string = `${handlerPath(__dirname)}/post/handler.main`,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment