Skip to content

Instantly share code, notes, and snippets.

@gooqiao
gooqiao / validate.ts
Last active September 23, 2020 09:00
/* eslint-disable @typescript-eslint/no-explicit-any */
const validate = {
int: "整数格式",
number: "数字格式",
double: "浮点数格式",
require: "必填",
};
const itValidate = (key: keyof typeof validate) => {
return validate[key];
};
a,
a:focus,
a:hover {
color: inherit;
outline: none;
text-decoration: none;
}
body {
height: 100%;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type N = Record<string, any>;
/**
* 严格的Exclude, 方便自动提示
*/
type ExcludeStrict<T, U extends T> = Exclude<T, U>;
/**
* 严格的Extract, 方便自动提示
*/
type ExtractStrict<T, U extends T> = Extract<T, U>;
@gooqiao
gooqiao / vue-instance.ts
Last active August 24, 2020 09:44
开发时拿到所有vue组件实例, 代替vue devtools
import Vue, { VNode, RenderContext, CreateElement } from "vue";
declare global {
interface VueComponents {
[key: string]:
| Vue
| ((createElement: CreateElement, hack: RenderContext) => VNode)
| undefined;
}
interface Window {
// 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
/*
* 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
* 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)