crypto.createHash('sha1').update(str).digest('latin1'); // raw_output
crypto.createHash('sha1').update(str).digest('base64'); // сразу base64
async function sha1(str) {
const buf = Uint8Array.from(unescape(encodeURIComponent(str)), c=>c.charCodeAt(0)).buffer;
const digest = await crypto.subtle.digest('SHA-1', buf);
const raw = String.fromCharCode.apply(null, new Uint8Array(digest));
return raw; // 20-символьная строка
// или
return btoa(raw); // base64
}
last_call
(уже не глобальную), результат присваивает переменной имя которой ей передали в параметрах и exit code работает как обычно.#!/bin/bash
last_call=never
function f {
local -n res=$1
printf -v last_call '%(%x %X)T'
res=$(($res * 2))
}
result=1
echo "Before: $last_call $result"
f result
echo "Return code: $?"
echo "After: $last_call $result"
sleep 1
f result
echo "Return code: $?"
echo "After: $last_call $result"
Before: never 1
Return code: 0
After: 06/16/2020 02:48:23 PM 2
Return code: 0
After: 06/16/2020 02:48:24 PM 4
return str.replace(/^(\d{4})(\d+)(\d{4})$/, (m, p1, p2, p3) => p1 + '*'.repeat(p2.length) + p3);
The third argument can be used to create virtual mocks – mocks of modules that don't exist anywhere in the system:
jest.mock( '../moduleName', () => { /* * Custom implementation of a module that doesn't exist in JS, * like a generated module or a native module in react-native. */ }, {virtual: true}, );