feat: 公式支持uuid生成

This commit is contained in:
allenve 2023-11-09 19:36:59 +08:00
parent 5fe0edd141
commit 78c34a31cd
2 changed files with 10 additions and 3 deletions

View File

@ -564,7 +564,14 @@ test('evalute:Math', () => {
});
test('evalute:UUID', () => {
expect(evaluate('${UUID()}', {}).length).toBe(32);
function isUUIDv4(value: string) {
return /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i.test(
value
);
}
expect(isUUIDv4(evaluate('${UUID()}', {}))).toBe(true);
expect(evaluate('${UUID()}', {}).length).toBe(36);
expect(evaluate('${UUID(8)}', {}).length).toBe(8);
});

View File

@ -1524,8 +1524,8 @@ export class Evaluator {
*
* @returns {string} UUID字符串
*/
fnUUID(length: number = 32) {
const len = Math.min(Math.max(length, 0), 32);
fnUUID(length: number = 36) {
const len = Math.min(Math.max(length, 0), 36);
return uuidv4().slice(0, len);
}