标签:ror efault ref lob ber 就会 1.0 .json add
// /bin/main.js
#!/usr/bin/env node
console.log(
123
);
{
"name": "sh",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"bin": {
"r32": "./bin/main.js"
}
}
在脚本根目录执行 cnpm i -g ./
r32 执行命令就会出现 123
#!/usr/bin/env node
const {
argv
} = require('yargs')
.config({
s: 'c0'
})
.option('all', {
describe: '查看返回字符串类型'
})
.alias('v', 'version')
.help('help')
if (argv.version) {
console.log('1.0.0');
return;
}
if (argv.all) {
console.log(`
--s=c0 默认返回大小写字母和数字 [c1 全大写] [c2 全小写] [c3 全小写]
`);
return;
}
let len = argv._[0] && typeof + argv._[0] === "number" ?
+argv._[0] :
32
const c0 = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; // 大小写字母和数字
const c1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // 大写
const c2 = 'abcdefghijklmnopqrstuvwxyz'; // 小写
const c3 = '123456789'; // 小写
let c = argv.s; // 默认大小写数字
switch (c) {
case 'c1':
c = c1;
break;
case 'c2':
c = c2;
break;
case 'c3':
c = c3;
break;
default:
c = c0;
break;
}
const random = (a, b) => Math.floor(Math.random() * (b - a + 1) + a);
function randomString32(len, c) {
// 返回随机字符串
const c_len = c.length;
return new Array(len)
.fill()
.reduce((acc) => acc += c[random(0, c_len - 1)], '')
}
const str = randomString32(len, c);
const exec = require('child_process').exec ;
exec(`echo ${str} | clip`, (error, stdout, stderr)=>{
if(error) console.log('复制到粘贴板失败!');
})
console.log(str);
>node .\bin\main.js 6 --s=c3
842773
标签:ror efault ref lob ber 就会 1.0 .json add
原文地址:https://www.cnblogs.com/ajanuw/p/8818873.html