Skip to content

Instantly share code, notes, and snippets.

View abigmiu's full-sized avatar
👋
I may be slow to respond.

Abigmiu abigmiu

👋
I may be slow to respond.
View GitHub Profile
@abigmiu
abigmiu / uniapp deleteableIntercept.ts
Last active June 11, 2025 05:22
uniapp 创建可删除的intercept
// 用于拦截指定API,返回一个移除"添加时"拦截器的函数
type IStopInterceptor = () => void;
interface IInterceptorItem {
id: string;
interceptor: UniApp.InterceptorOptions,
}
class Interceptors {
private interceptors: Record<string, IInterceptorItem[]> = {};
// 在 swagger 中定义 response 需要新建一个 class。 但是从数据库里面查询出来的数据有些不需要返回。所以可以通过`class-transform` 进行清除
// response class
import { ConsoleLogger } from '@nestjs/common';
import { ApiProperty } from '@nestjs/swagger';
import { Exclude, Expose, Transform } from 'class-transformer';
@Exclude()
export class IBookDetailResponse {
function isString(test: any): test is string{
return typeof test === "string";
}
function example(foo: any){
if(isString(foo)){
console.log("it is a string" + foo);
console.log(foo.length); // string function
// 如下代码编译时会出错,运行时也会出错,因为 foo 是 string 不存在toExponential方法
console.log(foo.toExponential(2));
export interface ClientModel {
idCardFront: string;
}
export interface NewInter extends Omit<ClientModel, 'idCardFront'> {
idCardFront?: string;
}
export function timeStampTo13(value: number) {
if (`${value}`.length === 10) {
return value * 1000;
}
return value;
}
export function timeStampTo10(value: number) {
if (`${value}`.length === 13) {
@abigmiu
abigmiu / typescript is 类型保护.md
Last active November 27, 2022 08:02
typescript is 类型保护
function isString(test: any): test is string{
    return typeof test === "string";
}

function example(foo: any){
    if(isString(foo)){
        console.log("it is a string" + foo);
        console.log(foo.length); // string function
 // 如下代码编译时会出错,运行时也会出错,因为 foo 是 string 不存在toExponential方法