Merge pull request #8678 from allenve/master

feat: 公式支持uuid生成
This commit is contained in:
Allen 2023-11-09 20:45:10 +08:00 committed by GitHub
commit ab0832c359
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
}