Nodejs generate short unique alphanumeric

前端 未结 6 643
借酒劲吻你
借酒劲吻你 2021-01-30 23:55

I would like to generate a short unique alphanumeric value to be used as confirmation codes for online purchases. I\'ve looking into https://github.com/broofa/node-uuid but the

6条回答
  •  一向
    一向 (楼主)
    2021-01-31 00:46

    based on this https://www.npmjs.com/package/randomstring

    var randomstring = require("randomstring");
    
    randomstring.generate();
    // >> "XwPp9xazJ0ku5CZnlmgAx2Dld8SHkAeT"
    
    randomstring.generate(7);
    // >> "xqm5wXX"
    
    randomstring.generate({
      length: 12,
      charset: 'alphabetic'
    });
    // >> "AqoTIzKurxJi"
    
    randomstring.generate({
      charset: 'abc'
    });
    // >> "accbaabbbbcccbccccaacacbbcbbcbbc"
    

    you can do this

    randomstring.generate({
      length: 8,
      charset: 'alphabetic'
    });
    

提交回复
热议问题