mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
feat: 公式支持uuid生成
This commit is contained in:
parent
5fe0edd141
commit
78c34a31cd
@ -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