Skip to content

Commit

Permalink
uniqid
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo committed Jun 19, 2024
1 parent 7321cd9 commit fdfd00e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pbottleRPA.js
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,27 @@ exports.searchFile = searchFile;
exports.utils.searchFile = searchFile;



/**
* 常用工具
* 生成唯一符串 注意:默认只是毫秒级的
* @param {string} prefix 前缀
* @param {boolean} moreEntropy 是否开启更精细的随机,如果还不能满足请使用uuid
* @returns {string}
*/
function uniqid(prefix = '', moreEntropy = false) {
let timestamp = Date.now().toString(36); // 将时间戳转换为36进制
let randomStr = '';
if (moreEntropy) {
// 如果需要更多的熵,则添加一些随机字符
randomStr = Math.random().toString(36).substring(2);
}
return prefix + timestamp + randomStr;
}
exports.uniqid = uniqid;
exports.utils.uniqid = uniqid;


/**
* 入口检测提示
*/
Expand Down
7 changes: 7 additions & 0 deletions 常用工具 Utils 演示.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ console.log('标准格式时间:',timeStr);
pbottleRPA.sleep(1000)


//随机数
console.log(pbottleRPA.utils.uniqid()); // 默认前缀和时间戳,可能没有额外的随机性
console.log(pbottleRPA.utils.uniqid('myPrefix_')); // 使用自定义前缀
console.log(pbottleRPA.utils.uniqid('', true)); // 带有额外随机性的唯一ID,默认只是毫秒级的
pbottleRPA.sleep(1000)


//数字字符串检测
console.log('检测变量是否为数字或数字字符串:',pbottleRPA.utils.isNumeric("3.14"));
pbottleRPA.sleep(1000)
Expand Down

0 comments on commit fdfd00e

Please sign in to comment.