mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
commit
ab0832c359
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user