import { Injectable } from '@nestjs/common' ; import nanoid from 'nanoid/async/generate' ; /**
 * 随机数工具
 */ @ Injectable ( ) export class RandomUtil { param pool param length async genRandomStr ( pool ? , length ? ) { if ( pool && ! length ) { return await nanoid ( pool , 32 ) ; } if ( ! pool && length ) { return await nanoid ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' , length ) ; } if ( pool && length ) { return await nanoid ( pool , length ) ; } return await nanoid ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' , 32 ) ; } }