В одну строку
Генерация случайной строки (например, пароля) в nodejs в одну строку:
(function(length,charset){return [...Array(length)].reduce(x=>x+charset[Math.floor(Math.random()*charset.length)],'')})(16,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'); |
Base64 -> hex (nodejs)
(function(b64){return Buffer.from(b64, 'base64').toString('hex');})('AQAB'); |
Base64url -> hex (nodejs)
(function(b64url){return Buffer.from(b64url.replaceAll(/[_-]/g, function(m){return '+/'['_-'.indexOf(m)];}), 'base64').toString('hex'); })('AQAB'); |
String -> Base64 (nodejs)
(function(s){return Buffer.from(s).toString('base64');})('test'); |
SHA-256 Digest (nodejs)
crypto.createHash('sha256').update('12345').digest().toString('hex'); |
===
Перепечатка материалов блога разрешается с обязательной ссылкой на blog.coolsoftware.ru