@react-native-ohos/react-native-mmkv-storage
Version:
This library aims to provide a fast & reliable solution for you data storage needs in react-native apps. It uses [MMKV](https://github.com/Tencent/MMKV) by Tencent under the hood on Android and iOS both that is used by their WeChat app(more than 1 Billion
49 lines (48 loc) • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const lowercase = 'abcdefghijklmnopqrstuvwxyz';
const uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const numbers = '0123456789';
const all = lowercase + uppercase + numbers;
/**
* A utility function that generates a strong password
* @returns
*/
function generatePassword() {
let password = '';
password += pick(password, lowercase, 1, 5);
password += pick(password, uppercase, 1, 5);
password += pick(password, all, 10);
return shuffle(password);
}
exports.default = generatePassword;
function pick(exclusions, string, min, max) {
var n, chars = '';
if (max === undefined) {
n = min;
}
else {
n = min + Math.floor(Math.random() * (max - min + 1));
}
var i = 0;
while (i < n) {
const character = string.charAt(Math.floor(Math.random() * string.length));
if (exclusions.indexOf(character) < 0 && chars.indexOf(character) < 0) {
chars += character;
i++;
}
}
return chars;
}
function shuffle(string) {
var array = string.split('');
var tmp, current, top = array.length;
if (top)
while (--top) {
current = Math.floor(Math.random() * (top + 1));
tmp = array[current];
array[current] = array[top];
array[top] = tmp;
}
return array.join('');
}